August 18, 2019, 04:29:45 pm

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


WndProc as a class method does not work for me (probably a stupid question)

Started by Haim, October 03, 2007, 08:41:36 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

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

Ionic Wind Support Team

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:

Code Select

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:

Code Select

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



Paul.
Ionic Wind Support Team

Haim

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

Ionic Wind Support Team

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.
Ionic Wind Support Team