Using Dialog Templates as Controls Positioning Templates
Download sourceThe ProblemI 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...
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 theCCtrlPositionTemplate
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: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.