Using the Layout Manager
The following topics describe how to use the Layout Manager via procedures and examples.
Adding Layout Management to Your Applications
The process of merging the layout framework into your application is easy. The following procedure outlines the recommended steps.
1. Add an instance of the layout factory to the header of the window class to which you want to apply the Layout Manager. For example:
 
Class CMyResizableDIalog : public CDialog {
. . .
protected:
SECLayoutFactory m_LayoutFactory;
. . .
2. During the window’s initialization stage (for example, in a CDialog’s OnInitDialog(), a CWnd’s OnCreate(), or a CView’s OnInitialUpdate()), initialize the layout. You can use the layout factory to produce both the layout algorithms and the window nodes required for the constraint setup.
 
CMyDialog::OnInitDialog() {
 
// Create top-level scale node. The layout factory will
// automatically
// deallocate the storage when it goes out of scope.
SECLNScale* pScaleNode=(SECLNScale*)m_LayoutFactory.CreateNode(
NODE_CLASS(SECLNScale));
 
// Create a “window node” and link it as a child of the scale
// layout
SECLayoutNodeWnd* pNode = m_LayoutFactory.CreateNodeWnd(IDC_BUTTON1,
this,pScaleNode);
3. Now, add the relevant layout constraints. See the next section for more information.
4. Finally, create the window listener and bridge between the parent window and the layout framework. This guarantees the appropriate windows events trigger the layout recalculations.
 
// Use the factory to create the listener, this way we don’t
// have to consider memory management
SECLayoutWndListener* pListener=m_LayoutFactory.CreateLayoutWndListener();
 
// Use the AutoInit function to bridge the gap between window
// and layout
pListener->AutoInit(pGrid,this);
NOTE >> Both SECLNScale and SECLNGrid are derived from a common class—SECLayoutNode.