IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: Haim on October 03, 2007, 08:41:36 AM

Title: WndProc as a class method does not work for me (probably a stupid question)
Post by: Haim on October 03, 2007, 08:41:36 AM
Hello,
I am trying to register a custom control, using RegisterClassex API which needs to be passed a WNDCLASSEX structure.
One member of WNDCLASSEX is the adress of the WndProc of the control.

I implemented the WndProc as a method of my custom control. How do I assign the address of this class method to the member of the WNDCLASSEX structure?

I recall having seen somewhere that one must implement WNDPROC as  a static method. How can this be implemented in AURORA? Is there a work around?

I am at aloss. Any help would be appreciated.

Thanks,
Haim
Title: Re: WndProc as a class method does not work for me (probably a stupid question)
Post by: Ionic Wind Support Team on October 03, 2007, 08:56:43 AM
If you just want to access class instance members when WndProc is called then use a window property to save off a pointer to your class instance.

Class methods have a 1st parameter called 'this' which is a pointer to the current instance of a class.  Windows doesn't know about classes so would not call your method correctly as the parameter count would be wrong.

If you have the sources look at 'instance.src'

When a window is created in Aurora a WNDCLASSEX structure is filled in with the address of a regular function as the WndProc.  I use SetWindowLong to save of the pointer to the current instance and when windows calls my WndProc I retrieve that pointer as such:


SUB DefaultHandler(hwnd as UINT, uMsg as UINT, wParam as UINT, lParam as UINT),INT
{
unsigned int result;
unsigned word atom;
atom = GetClassWord(hwnd,-32);
CWindow *pWnd;pWnd = NULL;
result = 0;
IF hwnd
pWnd = GetWindowLongA(hwnd,0)
ELSE
pWnd = 0;
......


Further down in the function I call a method in that instance to further process messages in an OOP way:


}
result = *pWnd.WndProc(uMsg,wParam,lParam);
}



Paul.
Title: Re: WndProc as a class method does not work for me (probably a stupid question)
Post by: Haim on October 03, 2007, 09:09:44 AM
Paul, thanks for the speedy response.
I guess I'll do this part as a non OOP SUB.
Wish there was a more elegant way though  :-[

Haim
Title: Re: WndProc as a class method does not work for me (probably a stupid question)
Post by: Ionic Wind Support Team on October 03, 2007, 09:14:08 AM
What I gave you was a way to redirect it to the OOP sub.

You have to remember that Windows itself is API based and doesn't know anything about OOP.  So even in Microsofts own products, like MFC for VC++, they have to redirect messages like this to process them in the oop world.

Paul.