Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

Possible to make MsgProc from WNDPROC?

This topic is 5139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!