Sign in to follow this  
johnnyBravo

Possible to make MsgProc from WNDPROC?

Recommended Posts

Hi , with c++ win32apps, I was wondering if its possible to make a MsgProc from WNDPROC. eg. WNDPROC MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); I was then wondering what would I do if DefWindowProc( hWnd, msg, wParam, lParam );' failed? I am not sure what DefWindowProc does exactly, but i read up on msdn somewhere that it helped let all the messages through, but I don't know if its important to post a failed LRESULT to the MsgProc. With the normal LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); it has the LRESULT, and I don't know if that does anything with the WNDPROC WNDCLASS::lpfnWndProc internally. So would this work using WNDPROC MsgProc...etc to make a MsgProc? Thanks

Share this post


Link to post
Share on other sites
You need to write a little less breathlessly and a little more legibly. Your sentences are poorly formed, which makes it difficult for anyone to understand you.

WNDPROC is a pointer type. It is defined as LRESULT (CALLBACK * WNDPROC) (HWND, UINT, WPARAM, LPARAM). In other words, it is a function pointer. Its use is in providing a mechanisms for delegation of message handling, which is why the lpfnWndProc member of WNDCLASS[EX] has this type.

DefWindowProc is the API-supplied default window procedure. If it fails, it's a system-wide problem beyond the scope of your application. In short, assume that it will always succeed.

In summary, if you declare a window procedure:

LRESULT WINAPI MsgProc(HWND, UINT, WPARAM, LPARAM)

and declare and fill out a WNDCLASS[EX] structure, you are supposed to indicate that MsgProc is the window procedure for that class as follows:

WNDCLASSEX wcex;
...
wcex.lpfnWndProc = MsgProc;
...


Within MsgProc, you handle the messages that are applicable to your application, paying attention to the appropriate return values for each of them (they're not all the same; some messages require zero for success while others require non-zero). Your default case, for messages that you don't wish to handle yourself, is to return the result of calling DefWindowProc, as follows:

LRESULT WINAPI MsgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case <SOME_MESSAGE>:
...
return <message-appropriate return value>;

...

default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}

// this line is necessary to eliminate a "not all control paths return a value" compiler warning
return 0;
}


Further Reading
About Window Procedures

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this