Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CALLBACK in a class

Status
Not open for further replies.

RichardF

Programmer
Oct 9, 2000
239
GB
Hi,

Can a CALLBACK function, eg a window procedure, be a class method ?

eg
class CMyWinApp {
public:
CMyWinApp();
~CMyWinApp();

....

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};

Thanks.
 
No it can't. If you want it to be part of a class, it must be a static method. The windows API is not OO and does not understand the "this" prefix of the member method.....
Greetings,
Rick
 
but this is ok ?

class CMyWinApp {
public:
CMyWinApp();
~CMyWinApp();

....

static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
 
Yes, that's ok.
Although you will have to make some sort of object map so you can distinguish between objects when receiving messages....
Greetings,
Rick
 
class CMyWinApp {
public:
CMyWinApp()
{...SetWindowLong(hWnd, GWL_USERDATA, (LONG)this);....}
~CMyWinApp();

....

static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};

LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(hWnd)
CMyWinApp* theObj = (CMyWinApp*)(void*)GetWindowLong(hWnd, GWL_USERDATA);
if(theObj)use theObj here
}
Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top