Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Win32 Button Commands

4: Adsense

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   

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


#2 ApochPiQ   Moderators   

22556
Like
2Likes
Like

Posted 10 August 2012 - 08:52 PM

You seem to have left out a break; just above case WM_CLOSE.
Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#3 Endurion   Members   

5321
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   

1360
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   Members   

5321
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   

11764
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.