Search code examples
winapicomctl32

WIN32: Is there a way to have the button icon (BM_SETIMAGE) on the right side of the text


Is there a way to have a button with text and graphic, with the graphic on the right side of the text, without having to owner-draw the button?

I want to just sent BM_SETIMAGE and whatever else would be needed so the graphic is to the right of the text.

Also, I noticed the image is so tight against the text that it doesn't look good. Is there a way to adjust the margin without having to use a blank space in the text?


Solution

  • Is there a way to have a button with text and graphic, with the graphic on the right side of the text, without having to owner-draw the button?

    There are BS_LEFTTEXT and BS_RIGHTBUTTON styles available, but the documentation says they only apply to CheckBoxes and RadioButtons:

    Constant Description
    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_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.

    For a standard push button, there does not appear to be a way to control the position of the image other than through owner-drawing.

    Is there a way to adjust the margin without having to use a blank space in the text?

    Use BCM_SETTEXTMARGIN/Button_SetTextMargin():

    Sets the margins for drawing text in a button control.