WindowProc
Is it possible to include the windows message handler function in a class? I''m trying to do that, but get the error:
error C2440: ''type cast'' : cannot convert from ''long (__stdcall CWindow::*)(struct HWND__ *,unsigned int,unsigned int,long)'' to ''long''
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
What does that mean?
I''m using this code:
wc.lpfnWndProc = (LRESULT)WndProc;
and
LRESULT CALLBACK CWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Do stuff here
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
The compiler is complaining that it can''t convert
the function pointer to a long because you are
casting it to LRESULT.
Also, the parameters for the function will need to
match up when it actually gets called and in this
case they don''t because all class methods have an
implicit first parameter that is a pointer to the
class (the "this" pointer). Declaring the function
as static will remove this first parameter, but then
you won''t have access to individual CWindows in the
callback function.
Remove the LRESULT cast and make sure that your
callback function is static and then this assignment
should work.
this implicit parameter. However, then you won''t
Do I declare the function static in the .h file only, cause it wont work otherwise.
When I do that I get a warning:
warning C4715: ''CWindow::NewWindow'' : not all control paths return a value
will it work?
When I do that I get a warning:
warning C4715: ''CWindow::NewWindow'' : not all control paths return a value
will it work?
Yes, you should only use the static keyword
in the class declaration in this situation.
It has a different meaning when it''s used
in the actual function declaration.
Ok, it works, but the window is only visible for half a second, then it dissapeares. Please help me find this little error!
download source here:
http://193.150.218.78/dist/cwindow.zip
(it''ll only de up for ½ hour)
download source here:
http://193.150.218.78/dist/cwindow.zip
(it''ll only de up for ½ hour)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement