Sign in to follow this  
captacha

Win32 Button Commands

Recommended Posts

captacha    141
In my code the WM_COMMAND segment causes my program to exit when I click on a button. Why is this? Shouldn't it do nothing?
[CODE]
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_CREATE:
CreateWindow("button", "Button 1", WS_VISIBLE | WS_CHILD, (width/2)-40, (height/2)-12, 80, 25, hwnd, (HMENU)1, NULL, NULL);
CreateWindow("button", "Button 2", WS_VISIBLE | WS_CHILD, (width/2)-40, ((height/2)-12)-45, 80, 25, hwnd, (HMENU)2, NULL, NULL);
break;
case WM_COMMAND:
if(LOWORD(wparam) == 1)
{
}
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
break;
}
}
[/CODE]

Share this post


Link to post
Share on other sites
Endurion    5407
[quote name='dilyan_rusev' timestamp='1344703207' post='4968435']
And also you should return 0 for handled messages. I don't know if this is the full code, but I can't see a "return 0" statement. Returning 0 is important.
[/quote]
You cannot generally return 0. Look up the handled message and see what you should return (if you should do so).

Share this post


Link to post
Share on other sites
SiCrane    11839
In particular, a common mistake is to return 0 from WM_NCCREATE, which indicates that window creation shouldn't proceed and causes CreateWindow()/CreateWindowEx() to return a NULL handle. Confusingly, WM_CREATE does the opposite: 0 indicates success.

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