How to declare WindowProc function in class
-
I declared WindowProc function in public section: static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } But I receive following errors: c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'CALLBACK' c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'WindowProc' c:\ABE\DTS\Form1.h(51) : error C2501: 'DTS::Form1::CALLBACK' : missing storage-class or type specifiers c:\ABE\DTS\Form1.h(51) : error C2061: syntax error : identifier 'HWND' c:\ABE\DTS\Form1.h(84) : warning C4183: 'WindowProc': missing return type; assumed to be a member function returning 'int' How shall I solve it????
-
I declared WindowProc function in public section: static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { } But I receive following errors: c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'CALLBACK' c:\ABE\DTS\Form1.h(51) : error C2146: syntax error : missing ';' before identifier 'WindowProc' c:\ABE\DTS\Form1.h(51) : error C2501: 'DTS::Form1::CALLBACK' : missing storage-class or type specifiers c:\ABE\DTS\Form1.h(51) : error C2061: syntax error : identifier 'HWND' c:\ABE\DTS\Form1.h(84) : warning C4183: 'WindowProc': missing return type; assumed to be a member function returning 'int' How shall I solve it????
-
Hmm. You don't have HWND defined. This would imply that you haven't included the windows.h header...
Steve S Developer for hire
-
I declared WndProc() as static public function in a form class. It needs to access non-static member function when wparam is DBT_DEVICEARRIVAL. This non-static function will modify the form panel displaying content. But static member function can only access other static member functions. How shall I solve this problem???
-
I declared WndProc() as static public function in a form class. It needs to access non-static member function when wparam is DBT_DEVICEARRIVAL. This non-static function will modify the form panel displaying content. But static member function can only access other static member functions. How shall I solve this problem???
(Disclaimer: This is for VC++6.0 and for MFC, and I'm pretty sure that this is not exactly what you use. Anyway, it may give you some ideas.) (Disclaimer: Untested code) You have the window handle as a parameter to WndProc, so it's easy to get the MFC C++ class corresponding to the window:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (wparam == DBT_DEVICEARRIVAL) {
CYourWnd* wnd = (CYourWnd*)CWnd::FromHandlePermanent(hWnd);
if ((wnd != NULL) && (wnd->IsKindOf(RUNTIME_CLASS(CYourWnd))) {
// access CYourWnd members by wnd->
}
}
}More on-beat C++ programmers will probably object to using the old-style typecasts, but it's safe when checking wnd for NULL and checking the runtime class.
Cheers Steen. "Are you gonna check your makeup when you're done whining?" John Simmons, 05/31/2006