-1

I was frustrated because I know StackPanel wasn't in the MFC.

I'm making a UI, and I have to stack the controls vertically.

If i'm using WPF, I can use StackPanel, but I'd like to ask you some advice on how to do it in MFC.

thnk you very much

dhlee
  • 11
  • 2

2 Answers2

1

There is nothing in MFC that implements the functionality of a StackPanel. If you want to stack controls, you're going to have to do it yourself, either in code or the resource editor.

Starting with Visual Studio 2015, MFC was updated to include support for Dynamic Layout. That helps automatically re-arrange controls when a dialog is resized, but still doesn't get you the entire functionality of a StackPanel.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
1

With MFC you have to do this manually or find third-party code that does it for you. E. g. have a look on CodeProject.

To do layouting on your own, you have to know how much space each control requires to show its content unclipped.

Some controls have methods to calculate their "ideal" size, e. g.:

Some controls like CStatic don't provide such methods. In such cases you may succeed to calculate their size using CDC::DrawText() with flag DT_CALCSIZE (don't forget to select the font of the control into the device context first to get accurate measurements).

In other cases, where such calculations are not possible, you may assume a fixed size for a control.

zett42
  • 25,437
  • 3
  • 35
  • 72