CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Message loop, CreateWindowEx, Buttons

    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!

  2. #2
    Join Date
    Jun 2004
    Posts
    102

    Re: Message loop, CreateWindowEx, Buttons

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured