Skip to main content
GameDev.net gamedev.net
🔒 Locked

small "BUTTON" problem

Started by Progames25 Feb 28, 2009 at 7:27 PM 2 replies 1.1k views
Original Post
Progames25
Progames25
(using C++ Win32 API) Hello, I have one button in my window. I can't figure out how to make a MessageBox() show if you press this button. I named the HWND for my button hWndButtonSave. The closest I have gotten to figuring out if the button was pressed was creating a: case WM_COMMAND: break; inside of winproc. How can I tell if a certain button was pressed, and then do something (MessageBox()) when it is pressed? I ahve looked all over google, Win32 Tips, and other places and just can't find how to do this. Thanks, Progames25
-----------------------------I use C++ and DirectX.I'm new to game programming.
MJP
MJP
When you create a control (or any other child window) with CreateWindow or CreateWindowEx, you give it an ID via the hMenu parameter. When the control sends a WM_COMMAND, the ID is sent as the low-word of the wParam. You can check this ID to determine which control sent the notification. The lParam is the handle to the control window, so you can also check this against the HWND you received from CreateWindow when you created the Button.

Make sure you also check the notification code, which in the high-word of wParam. In your case you'll want to make sure the code is BN_CLICKED, which indicates that the button was clicked.
Endurion
Endurion
As MJP said.

MSDN should have a nice sample when you look for BN_CLICKED. It boils down to:

case WM_COMMAND:  if ( HIWORD( wParam ) == BN_CLICKED )  {    // either check the ID    if ( LOWORD( wParam ) == myID )    {      // do action    }    // ... or the HWND    if ( (HWND)lParam == hwndMyButton )    {      // do action    }  }  break;
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Progames25
Progames25
Awsome,
thanks it worked.
now I get it.



Thanks,
Progames25
-----------------------------I use C++ and DirectX.I'm new to game programming.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.