Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Win32 Button Commands


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Captacha   Members   -  Reputation: 141

Like
0Likes
Like

Posted 10 August 2012 - 07:54 PM

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?
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;
}
}


Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 17475

Like
2Likes
Like

Posted 10 August 2012 - 08:52 PM

You seem to have left out a break; just above case WM_CLOSE.

#3 Endurion   Crossbones+   -  Reputation: 4016

Like
0Likes
Like

Posted 10 August 2012 - 10:29 PM

Not the problem here, but you don't return anything for any handled message. In most cases you also want to call DefWindowProc for handled messages.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#4 dilyan_rusev   Members   -  Reputation: 1182

Like
0Likes
Like

Posted 11 August 2012 - 10:40 AM

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.

#5 Endurion   Crossbones+   -  Reputation: 4016

Like
2Likes
Like

Posted 11 August 2012 - 10:35 PM

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.

You cannot generally return 0. Look up the handled message and see what you should return (if you should do so).
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

#6 SiCrane   Moderators   -  Reputation: 10372

Like
2Likes
Like

Posted 12 August 2012 - 12:23 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS