MFC: Buttonstyles and Windows 7
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: MFC: Buttonstyles and Windows 7

  1. #1
    Join Date
    Mar 2007

    Question MFC: Buttonstyles and Windows 7


    My MFC dialog app which was working ok in XP has started exhibiting some strange behaviour concerning MFC buttons.

    I have a function to set the button text and style, but bizarrely, when the text is too long to fit the button and is wrapped, the button seems to 'forget' the BS_CENTER attribute and left aligns.

    I should say that I'm using the "classic" style with the Themes services deactived. Even if this is avtivated, the behaviour is the same. If I go back to Windows 7 themes, then the button text centers correctly, but this isn't the look I want.

    Any idea how to get the buttons to behave properly in Classic theme in Win7?

    This is my code:

    void CMain::SetButtonText(CWnd* ptr, std::string button_text )
    	int test = 0;
    	test = ptr->ModifyStyle(0, BS_MULTILINE   , 0);
    	test = ptr->ModifyStyle(0, BS_CENTER, 0   );
    When I debug step by step, ModifyStyle returns TRUE, and the std::string is correct (no white spaces).

    Also, when I comment out the style setting and use the VS button properties, the result is the same.

    Any ideas? Or is this a limitation of Windows 7? (I'm beginning to think it is).


  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Iasi - Romania

    Re: MFC: Buttonstyles and Windows 7

    AFAIK, in classic theme, BS_CENTER is ignored if BS_MULTILINE is set, regardless the Windows version.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My latest articles:

  3. #3
    Join Date
    Mar 2007

    Re: MFC: Buttonstyles and Windows 7

    In XP with classic theme, it works as expected. ie. button text centered when BS_CENTER and BS_MULTILINE is set.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center