Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Error Handling
 Win32 Skeleton
 Message Handler
 Conclusion

 Source code
 Printable version

 


  The Series

 Part I
 Part II

 

The Message Handler

LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc (hWnd, msg, wParam, lParam); break; } return 0; }

We don't need to worry too much about the parameters of the function because the Windows system calls this function automaticlly. You just need to have those four parameters declared.

We determine the type of message and how to handle it by using a switch statement. This simple program just uses WM_DESTROY, which is a message that is sent to the program when it's beilg closed. We handle the message by telling the program to quit and return 0 to let Windows know we processed the message.

All messages that aren't processed by us are returned to Windows to use the default processing by calling DefWindowProc.




Next : Conclusion