BN_CLICKED, change button style

This is a discussion on BN_CLICKED, change button style within the Windows Programming forums, part of the Platform Specific Boards category; using win32 API, in my WndProc, i have the following code: Code: case BN_CLICKED: SendMessage((HWND) lParam, BM_SETSTYLE, (WPARAM) LOWORD(BS_TOP), MAKELPARAM(TRUE, ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    BN_CLICKED, change button style

    using win32 API, in my WndProc, i have the following code:

    Code:
    case BN_CLICKED:
        SendMessage((HWND) lParam, BM_SETSTYLE, 
        (WPARAM) LOWORD(BS_TOP), 
        MAKELPARAM(TRUE, 0));
    break;
    i know the BN_CLICKED message is being received right, but when i send this message to change the button style, nothing happens. what is the problem?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I have not used that message before, but here is the documentation I have on it:
    The BN_CLICKED notification message is sent when the user clicks a button. The parent window of the button receives this notification message through the WM_COMMAND message. Unlike the other button notification messages, this message is intended for applications written for any version of Windows.

    BN_CLICKED
    idButton = (int) LOWORD(wParam); // identifier of button
    hwndButton = (HWND) lParam; // handle of button


    Remarks

    A disabled button does not send a BN_CLICKED notification message to its parent window.

    See Also

    WM_COMMAND
    Here is some documentation on BM_SETSTYLE
    An application sends a BM_SETSTYLE message to change the style of a button.

    BM_SETSTYLE
    wParam = (WPARAM) LOWORD(dwStyle); // style
    lParam = MAKELPARAM(fRedraw, 0); // redraw flag


    Parameters

    dwStyle

    Value of wParam. Specifies the button style. For an explanation of button styles, see the following Remarks section.

    fRedraw

    Value of the low-order word of lParam. Specifies whether the button is to be redrawn. A value of TRUE redraws the button; a value of FALSE does not redraw the button.

    Return Values

    This message always returns zero.

    Remarks

    Following are the available button styles:

    Style Meaning
    BS_3STATE Creates a button that is the same as a check box, except that the box can be grayed as well as checked or unchecked. Use the grayed state to show that the state of the check box is not determined.
    BS_AUTO3STATE Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it. The state cycles through checked, grayed, and unchecked.
    BS_AUTOCHECKBOX Creates a button that is the same as a check box, except that the check state automatically toggles between checked and unchecked each time the user selects the check box.
    BS_AUTORADIOBUTTON Creates a button that is the same as a radio button, except that when the user selects it, Windows automatically sets the button’s check state to checked and automatically sets the check state for all other buttons in the same group to unchecked.
    BS_CHECKBOX Creates a small, empty check box with text. By default, the text is displayed to the right of the check box. To display the text to the left of the check box, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style).
    BS_DEFPUSHBUTTON Creates a push button that behaves like a BS_PUSHBUTTON style button, but also has a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely (default) option.
    BS_GROUPBOX Creates a rectangle in which other controls can be grouped. Any text associated with this style is displayed in the rectangle’s upper left corner.
    BS_LEFTTEXT Places text on the left side of the radio button or check box when combined with a radio button or check box style. Same as the BS_RIGHTBUTTON style.
    BS_OWNERDRAW Creates an owner-drawn button. The owner window receives a WM_MEASUREITEM message when the button is created and a WM_DRAWITEM message when a visual aspect of the button has changed. Do not combine the BS_OWNERDRAW style with any other button styles.
    BS_PUSHBUTTON Creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button.
    BS_RADIOBUTTON Creates a small circle with text. By default, the text is displayed to the right of the circle. To display the text to the left of the circle, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style). Use radio buttons for groups of related, but mutually exclusive choices.
    BS_USERBUTTON Obsolete, but provided for compatibility with 16-bit versions of Windows. Win32-based applications should use BS_OWNERDRAW instead.
    BS_BITMAP Specifies that the button displays a bitmap.
    BS_BOTTOM Places text at the bottom of the button rectangle.
    BS_CENTER Centers text horizontally in the button rectangle.
    BS_ICON Specifies that the button displays an icon.
    BS_LEFT Left-justifies the text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is left justified on the right side of the check box or radio button.
    BS_MULTILINE Wraps the button text to multiple lines if the text string is too long to fit on a single line in the button rectangle.
    BS_NOTIFY Enables a button to send BN_DBLCLK, BN_KILLFOCUS, and BN_SETFOCUS notification messages to its parent window. Note that buttons send the BN_CLICKED notification message regardless of whether it has this style.
    BS_PUSHLIKE Makes a button (such as a check box, three-state check box, or radio button) look and act like a push button. The button looks raised when it isn’t pushed or checked, and sunken when it is pushed or checked.
    BS_RIGHT Right-justifies text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is right justified on the right side of the check box or radio button.
    BS_RIGHTBUTTON Positions a radio button’s circle or a check box’s square on the right side of the button rectangle. Same as the BS_LEFTTEXT style.
    BS_TEXT Specifies that the button displays text.
    BS_TOP Places text at the top of the button rectangle.
    BS_VCENTER Places text in the middle (vertically) of the button rectangle.
    Hope that helps.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i think i have that some documentation, so that doesn't really help at all. according to the doco, everything im doing is right. so whats wrong?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    another useless post...

    >>so whats wrong?

    You!

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    what r u trying to say face master?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Check the HWND you are using. Also the LPARAM is just TRUE (or non zero).

    Try
    Code:
     
    SendMessage(GetDlgItem(hWnd,ID_BUTTON)
               ,BM_SETSTYLE
               ,(WPARAM)BS_TOP
               ,(LPARAM)1);//true redraws button
    I also use the BN_CLICKED differently

    Code:
    case WM_COMMAND:
    {   
       idControl	= GET_WM_COMMAND_ID(wParam, lParam) ;
       switch(idControl)
       case ID_BUTTON:
       if (BN_CLICKED == HIWORD(wParam))
       {//button clicked code
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    it still doesn't work. i know the code is being reached, so the problem must lie with the SendMessage() function.
    Code:
    SendMessage(GetDlgItem(hwnd,ID_OK)
    	,BM_SETSTYLE
    	,(WPARAM)BS_TOP
    	,(LPARAM)1);//true redraws button
    that code is just not doing anything. help!
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    Maybe there is little to no visual change between the two styles.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Try getting the buttons style and adding the BS_TOP. (which only draws the text near the top of the button)

    try BS_FLAT to see if it changes.

    Call UpdateWindow() with the hWnd of the Buttons Dialog.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    how do i get the style of the button? my documentation only has BM_SETSTYLE, no BM_GETSTYLE. however, i dont think that would work, because when my buttons are created, they are created with the WS_CHILD and WS_VISIBLE styles. therefore, if i sent a change style message not including those 2 styles, things would be majorly messed up. so obviously it is not just a matter of adding BS_TOP or whatever to the existing styles.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    Registered User
    Join Date
    Jul 2010
    Posts
    1

    no change

    Hi,
    I have the same problem. The setting from resource file ("Bitmap" property in VS window, or "BS_BITMAP" in rc file) are looking like stamped there. I cannot set or unset the BS_BITMAP flag, there is no efect. I needed this because i wanted to show a text message in case the bmp i want to load could not be found (an we know that in WinXP it does not function text&bmp at the same time).

    SendMessage(ahBtn[i], BM_SETSTYLE, BS_PUSHBUTTON, (LPARAM) TRUE);
    (code does not unset)

    I think problem could be because the button doesn't know ow to handle this BM_SETSTYLE command. I use only plain C.
    Copy/Paste from documentations already discussed are not welcome, but ideas or solutions are welcome.

  12. #12
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    It could be that you need to invalidate the button after changing it's style. The redraw is supposed to do that but maybe the API failed to mention there are exceptions to when it redraws and when it does not. My guess is that the redraw param is being ignored due to some internal state or a style the control does not support.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Holy Thread Necrophillia Batman!

    Quote Originally Posted by artcoding View Post
    I needed this because i wanted to show a text message in case the bmp i want to load could not be found (an we know that in WinXP it does not function text&bmp at the same time).
    It has been a few years but I think I created an image that warned the used that the image could not be found (and added it as a resource).

    The image loading routine defaulted to this image (so always would show an image).

    Or was it that I created a compatible bitmap at run time and wrote the error on it (before setting it to the control)?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Eh sorry about that. I didn't realize this thing was that old.

    Thread closed. Please don't bump old threads.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC: Change the color of static text with button press?
    By BrianK in forum Windows Programming
    Replies: 2
    Last Post: 06-16-2004, 11:03 PM
  2. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  3. disabling button in another prog
    By timmygax in forum Windows Programming
    Replies: 11
    Last Post: 10-29-2001, 02:40 PM
  4. How To Change Caption's On A Button When It Is Click ?
    By SonicWave in forum Windows Programming
    Replies: 1
    Last Post: 09-19-2001, 02:14 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21