Newbie Win Message Handler Problem
I have this silly newbie question about Windows programming:
I''ve downloaded some sample codes and learned how to open a
window, use resources etc. The problem is I don''t know if my
code is exactly as it should be.
My Window message handler looks like this:
case WM_CREATE:
{ } break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
} break;
Ok, it works fine, but then I bought a book, in that book every
example is written like this:
case WM_CREATE:
{
return(0);
} break;
case WM_PAINT:
{
hdc = BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
So, as you can see there''s "return 0;" before every break. Both of these
work, but Borland compiler complains there''s "unreachable code" in the
second example.
Which style is preferred ? Or does it matter as long as it works ?
using the break system works .. IF you''ve already preped your return value to 0. using the return works also .. but using both is silly ... as borland says .. it is imposible for the compiler to reach a break which follows a return ... so leave one of the two off .. depending on the code surrounding it ... i''ll post some sample code in a minute if i can.
good luck
good luck
Here''s code .. i hope it displays right.
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { LRESULT retVal = 0; switch(message) { case WM_KEYDOWN: if(wParam == ''X'') PostMessage(hWnd, UM_COMMAND_CLOSE_PROGRAM,0,0); break; case WM_DESTROY: PostQuitMessage(0); break; default: retVal = DefWindowProc(hWnd,message,wParam,lParam); } return retVal; }
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement