Click to See Complete Forum and Search --> : Message loop, CreateWindowEx, Buttons
BlackenedSky
August 29th, 2004, 05:02 PM
I've been trying for the past few hours to try and find out how to handle a button click event when I create a button using CreateWindowEx.
I've managed to make it so that it detects clicks on buttons, but how can I find out what button it is? That's the bit I've been stuck on and it's becomming very annoying, and the MSDN help is useless on the subject!
sbubis
August 30th, 2004, 12:45 AM
Is it a standard windows button, i.e. when creating it using CreateWindowEx do you specify BUTTON as a window class?
2. Where is message loop and who is owner of your button?
Assume that it is a standard button and you want to catch the click event. Here is a copy of MSDN regarding to this:
The BN_CLICKED notification code is sent when the user clicks a button.
The parent window of the button receives the BN_CLICKED notification code through the WM_COMMAND message.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_COMMAND
WPARAM wParam, // identifier of button, BN_CLICKED
LPARAM lParam // handle to button (HWND)
);
Parameters
wParam
The low-order word contains the button's control identifier.
The high-order word specifies the notification message.
lParam
Handle to the button.
It means that you should catch WM_COMMAND in the window procedure of the parent window and then either check wParam:
if (LOWORD (wParam) == IDC_BUTTON_XXX)
// This message sent by button IDC_BUTTON_XXX
else
..... Continue to check other controls.
or, if you know window handle of your button, you can check lParam:
if ((HWND) lParam == hMyButtonWnd)
The IDC_BUTTON_XXX is an integer value you use as hMenu parameter of CreateWindowEx. As written in MSDN, it should be an integer value that identifies a control (button, checkbox, etc.) being created or a handle of menu.
Hope it will help
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.