The Problem
I always found unpleasant to change dynamically the layout of a form or a dialog. In these cases, we had to call SetWindowPos or MoveWindow on each control of the form. We had to calculate manually the position of each controls on the form too.
The Resolution
So, why don’t use dialog templates as layout placement templates for controls?
So this is what I’ve done in the
CCtrlPositionTemplate
class.
{
CCtrlPositionTemplate aPositionTemplate(IDD_DIALOG_TEMPLATE1, CPoint(10, 10), this);
aPositionTemplate.ApplyTemplate();
}
You just have to create the class whit relevant parameter and the layout changes like magic!
The Trick
Create your dialog:
Create layout template with controls using the same ID as the initial dialog:
Insatiate the class and call ApplyTemplate() method and that’s it:
The layout changes like by magic.
So you can have many layouts for the same controls on a form and changing it at runtime.
Note 1 : Sorry for my bad English.
Note 2 : I also integrate in the
CSetDPI
class of George Yohng to support users that actually use it in their projects. So you can specify the exact DPI in the class parameter and the layout will respect the specified DPI.