Every control is a window, all windows generate messages, if you want to know if a button is clicked on you check if a message is generated for the button not the mouse (its possible but pointless)
so you search msdn for button control: http://msdn2.microsoft.com/en-us/library/ms673340.aspx
you check button messages: http://msdn2.microsoft.com/en-us/library/ms673328.aspx
you see for button messages it says "the low-order word of the wParam parameter contains the control identifier, the high-order word of wParam contains the notification code, and the lParam parameter contains the control window handle."
and then you find the msg your interested in: "BN_CLICKED The user clicked a button." (http://msdn2.microsoft.com/en-us/library/ms673572.aspx)
"The parent window of the button receives the BN_CLICKED notification code through the WM_COMMAND message.
wParam
The low-order word contains the button's control identifier. The high-order word specifies the notification message.
lParam
A handle to the button."
ok so:
Code:
if(msg == WM_COMMAND)
{
} next you need to check if its the button your intereseted in, if its from a resource ID:
"The low-order word contains the button's control identifier"
so:
Code:
if(LOWORD(wParam) == MY_BUTTON)
or if you created the button then you will have a handle to it:
"lParam - A handle to the button."
Code:
if((HWND)lParam == hWndMyButton)
So now you wanna check if the button is clicked -
"The high-order word specifies the notification message"
Code:
if(HIWORD(wParam) == BN_CLICKED)
so to sum up:
Code:
if(msg == WM_COMMAND)
{
if(LOWORD(wParam) == MY_BUTTON)
{
if(HIWORD(wParam) == BN_CLICKED)
{
// Wah the button was clicked!
}
}
}
Bookmarks