Search code examples
mfcgroupbox

How do I change the width of a group box in MFC programmatically?


Sorry, I'm more of a C# person but I'm having to update some legacy MFC code. I'm starting to realize why C# was a good upgrade.


Solution

  • You can use CWnd::MoveWindow:

    http://msdn.microsoft.com/en-us/library/5bc5w1zz%28VS.80%29.aspx

    If your GroupBox is for instance in an dialogue and has the control-Id IDC_MYGROUP then you can call in any method/event handler of the dialogue

    GetDlgItem(IDC_MYGROUP)->MoveWindow(NewX,NewY,NewWidth,NewHeight,TRUE);
    

    The last parameter TRUE (default) is for immediate repaint.