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

Thread: MFC: Buttonstyles and Windows 7

  1. #1
    Join Date
    Mar 2007
    Posts
    82

    Question MFC: Buttonstyles and Windows 7

    Hi,

    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:

    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   );
    	ptr->SetWindowText(_T(button_text.c_str()));
    
    }
    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).

    Thanks.

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

    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."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Mar 2007
    Posts
    82

    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 CodeGuru survey question.


Featured


HTML5 Development Center