Advertisement

WindowProc

Started by February 09, 2000 12:42 PM
5 comments, last by ZomeonE 24 years, 10 months ago
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
Advertisement
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?

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)

After you create the window, you call
ShowWindow(CWindow::hwnd, NULL);
which hides it.

Instead, call
ShowWindow(CWindow::hwnd, SW_SHOW);

(And you don''t need to prefix every member
variable with CWindow:: when you are inside
a method for that class).
Advertisement
Yes ofcourse thanks!

This topic is closed to new replies.

Advertisement