{"id":2057,"date":"2015-07-27T14:23:21","date_gmt":"2015-07-27T12:23:21","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=2057"},"modified":"2015-07-28T10:25:18","modified_gmt":"2015-07-28T08:25:18","slug":"dynamic-dialog-layout-for-mfc-in-visual-c-2015","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/","title":{"rendered":"Dynamic Dialog Layout for MFC in Visual C++ 2015"},"content":{"rendered":"<p>In Visual Studio 2015 MFC comes with a new features (something that has rarely happen in recent years): support for dynamic dialog layout. That means library support for moving and resizing controls on a dialog. In this article I will show how this feature works.<\/p>\n<p>Suppose we have the following dialog:<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout1.png\" alt=\"Dialog in original size\" width=\"336\" height=\"293\" class=\"size-full wp-image-2058\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout1.png 336w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout1-300x262.png 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/a><\/p>\n<p>What we want is that the controls on the dialog move (the buttons) or resize (the group box, edit and the list) when the dialog is resized:<br \/>\n<figure id=\"attachment_2059\" aria-describedby=\"caption-attachment-2059\" style=\"width: 629px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout2.png\" alt=\"Resized dialog\" width=\"639\" height=\"434\" class=\"size-full wp-image-2059\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout2.png 639w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout2-300x204.png 300w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/a><figcaption id=\"caption-attachment-2059\" class=\"wp-caption-text\">Resized dialog<\/figcaption><\/figure><\/p>\n<p>The resource editor provides support for this, but it can also be done programmatically. If you open the properties of a control there is a new category called <em>Dynamic Layout<\/em> that allows you to select a moving and a sizing type.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout5.png\" alt=\"Dynamic Layout Settings\" width=\"341\" height=\"185\" class=\"alignnone size-full wp-image-2067\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout5.png 341w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout5-300x163.png 300w\" sizes=\"auto, (max-width: 341px) 100vw, 341px\" \/><\/a><br \/>\nThe options you have for both moving and resizing are: <em>None<\/em>, <em>Horizontal<\/em> <em>Vertical<\/em>, and <em>Both<\/em>. These options should be self explanatory. However, the important thing to notice is the value for the X and Y axes moving and resizing: these are ratios, not dialog units or pixels, having a value between 1 and 100 and defining how much a control is moved or resized when the host dialog changes size.<\/p>\n<p>Now, to enable the layout shown in the the example above we need to do the following:<\/p>\n<ul>\n<li>fully resize (100%) the group box and list box both horizontally and vertically<\/li>\n<li>fully resize the edit control horizontally<\/li>\n<li>completely (100%) move the OK button vertically<\/li>\n<li>completely move the Add button horizontally<\/li>\n<li>completely move the Clear and Cancel buttons both horizontally and vertically<\/li>\n<\/ul>\n<p><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout3.png\" alt=\"Dynamic layout settings for the example dialog\" width=\"878\" height=\"432\" class=\"alignnone size-full wp-image-2060\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout3.png 878w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout3-300x148.png 300w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/a><br \/>\nIt is pretty simple to put values into the dynamic layout settings for each control. When you build and run and resize the dialog box the controls move or resize accordingly. <\/p>\n<p>These dynamic layout settings are put in the resource script (.rc file) of the application. For the example above it looks like this:<\/p>\n<pre class=\"lang:default decode:true \" >\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/\r\n\/\/ AFX_DIALOG_LAYOUT\r\n\/\/\r\n\r\nIDD_MFCDYNLAYOUTDEMO_DIALOG AFX_DIALOG_LAYOUT\r\nBEGIN\r\n    0,\r\n    0, 100, 0, 0,\r\n    100, 100, 0, 0,\r\n    0, 0, 100, 100,\r\n    0, 0, 0, 0,\r\n    0, 0, 100, 0,\r\n    0, 0, 100, 100,\r\n    100, 100, 0, 0,\r\n    100, 0, 0, 0\r\nEND<\/pre>\n<p>In this definition <tt>IDD_MFCDYNLAYOUTDEMO_DIALOG<\/tt> is the identifier of the dialog for which the settings are defined and the numbers in the <tt>BEGIN-END<\/tt> block represent:<\/p>\n<ul>\n<li>the first line is a header containing the version number on the structure (0 in this version)<\/li>\n<li>the consecutive lines are the dynamic layout settings (move and size ratios) for each control on the dialog, corresponding to the order the controls were defined for the dialog in the resource script file.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout4-1024x280.png\" alt=\"Dynamic layout settings in .rc file\" width=\"1024\" height=\"280\" class=\"alignnone size-large wp-image-2072\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout4-1024x280.png 1024w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout4-300x82.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout4.png 1222w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>These settings are loaded into a  <a href=\"http:\/\/CMFCDynamicLayout\" target=\"_blank\"><tt>CMFCDynamicLayout<\/tt><\/a> object (see afxlayout.h\/cpp). This is done in the <tt>OnInitDialog<\/tt> method of the <tt>CDialog<\/tt> class as shown below:<\/p>\n<pre class=\"lang:c++ decode:true \" >BOOL CDialog::OnInitDialog()\r\n{\r\n\t\/\/ execute dialog RT_DLGINIT resource\r\n\tBOOL bDlgInit;\r\n\tif (m_lpDialogInit != NULL)\r\n\t\tbDlgInit = ExecuteDlgInit(m_lpDialogInit);\r\n\telse\r\n\t\tbDlgInit = ExecuteDlgInit(m_lpszTemplateName);\r\n\r\n\tif (!bDlgInit)\r\n\t{\r\n\t\tTRACE(traceAppMsg, 0, \"Warning: ExecuteDlgInit failed during dialog init.\\n\");\r\n\t\tEndDialog(-1);\r\n\t\treturn FALSE;\r\n\t}\r\n\r\n\tLoadDynamicLayoutResource(m_lpszTemplateName);\r\n<\/pre>\n<p>Note: for <tt>CPaneDialog<\/tt>, <tt>CDialogBar<\/tt> and <tt>CFormView<\/tt> on the other hand this is done in <tt>HandleInitDialog<\/tt>.<\/p>\n<p>This <tt>LoadDynamicLayoutResource<\/tt> is actually a member of <tt>CWnd<\/tt> which contains other methods for working with dynamic layouts:<\/p>\n<ul>\n<li><tt>EnableDynamicLayout<\/tt>: enables or disables layout manager for a window<\/li>\n<li><tt>IsDynamicLayoutEnabled<\/tt>: indicates if layout management is enabled for a window<\/li>\n<li><tt>GetDynamicLayout<\/tt>: retrieves a pointer to layout manager<\/li>\n<li><tt>ResizeDynamicLayout<\/tt>: readjust the position of the controls handled by the dynamic layout manager as a response to <tt>WM_SIZE<\/tt><\/li>\n<li><tt>InitDynamicLayout<\/tt>: initializes dynamic layout manager as a response to the <tt>WM_CREATE<\/tt> message<\/li>\n<\/ul>\n<pre class=\"lang:c++ decode:true \" >\r\n\t\/\/ controls dynamic layout:\r\n\r\n\t\/\/\/ &lt;summary&gt;\r\n\t\/\/\/ Enables or disables layout manager for a window.&lt;\/summary&gt;\r\n\t\/\/\/ &lt;param name=\"bEnable\"&gt; TRUE - enable layout management, FALSE - disable layout management.&lt;\/param&gt;\r\n\tvoid EnableDynamicLayout(BOOL bEnable = TRUE);\r\n\r\n\t\/\/\/ &lt;summary&gt;\r\n\t\/\/\/ This function returns TRUE, if layout management is enabled for a window; otherwise FALSE.&lt;\/summary&gt;\r\n\t\/\/\/ &lt;remarks&gt;\r\n\t\/\/\/ Call EnableDynamicLayout in order to enable or disable layout management for a window.&lt;\/remarks&gt;\r\n\t\/\/\/ &lt;returns&gt; \r\n\t\/\/\/ TRUE, if layout management is enabled for a window; otherwise FALSE.&lt;\/returns&gt;\r\n\tBOOL IsDynamicLayoutEnabled() const { return m_pDynamicLayout != NULL; }\r\n\r\n\t\/\/\/ &lt;summary&gt;\r\n\t\/\/\/ Call this function to retrieve a pointer to layout manager.&lt;\/summary&gt;\r\n\t\/\/\/ &lt;remarks&gt;\r\n\t\/\/\/ Call EnableDynamicLayout in order to enable or disable layout management for a window.&lt;\/remarks&gt;\r\n\t\/\/\/ &lt;returns&gt; \r\n\t\/\/\/ Returns a pointer to the window layout manager or NULL if layout wasn't enabled.&lt;\/returns&gt;\r\n\tCMFCDynamicLayout* GetDynamicLayout() { return m_pDynamicLayout; }\r\n\r\n\t\/\/\/ <summary>\r\n\t\/\/\/ The method is called to adjust positions of child controls. \r\n\t\/\/\/ It recalculates positions of child controls if layout management is enabled for a window.<\/summary>\r\n\tvirtual void ResizeDynamicLayout();\r\n\tvoid InitDynamicLayout();\r\n\tBOOL LoadDynamicLayoutResource(LPCTSTR lpszResourceName);\r\n<\/pre>\n<p>These methods allow you to enable or disable the dynamic layout management on the fly. <\/p>\n<ol>\n<li>Initially the dynamic layout management is set so the controls move and resize when the dialog is resized.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout6.png\" alt=\"dynlayout6\" width=\"336\" height=\"315\" class=\"alignnone size-full wp-image-2092\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout6.png 336w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout6-300x281.png 300w\" sizes=\"auto, (max-width: 336px) 100vw, 336px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout7.png\" alt=\"dynlayout7\" width=\"479\" height=\"339\" class=\"alignnone size-full wp-image-2093\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout7.png 479w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout7-300x212.png 300w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/a><\/li>\n<li>Disable the dynamic layout management and the child controls are no longer adjusted.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout8.png\" alt=\"dynlayout8\" width=\"596\" height=\"405\" class=\"alignnone size-full wp-image-2094\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout8.png 596w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout8-300x204.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/a><\/li>\n<li>Re-enable the dynamic layout management and it works again.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout9.png\" alt=\"dynlayout9\" width=\"790\" height=\"485\" class=\"alignnone size-full wp-image-2095\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout9.png 790w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout9-300x184.png 300w\" sizes=\"auto, (max-width: 790px) 100vw, 790px\" \/><\/a><\/li>\n<\/ol>\n<p>The catch here is that just calling <tt>CWnd::EnableDynamicLayout<\/tt> won&#8217;t work because this method only deletes and recreates the <tt>CMFCDynamicLayout<\/tt> instance.<\/p>\n<pre class=\"lang:c++ decode:true \" >void CWnd::EnableDynamicLayout(BOOL bEnable)\r\n{\r\n\tif (m_pDynamicLayout != NULL)\r\n\t{\r\n\t\tdelete m_pDynamicLayout;\r\n\t\tm_pDynamicLayout = NULL;\r\n\t}\r\n\r\n\tif (!bEnable)\r\n\t{\r\n\t\treturn;\r\n\t}\r\n\r\n\tm_pDynamicLayout = new CMFCDynamicLayout;\r\n}<\/pre>\n<p>Just like <tt>CDialog::OnInitDialog<\/tt> you&#8217;d have to call <tt>CWnd::LoadDynamicLayoutResource<\/tt>. Therefore, the correct code for enabling and disabling dynamic layout management should look like this:<\/p>\n<pre class=\"lang:c++ decode:true \" >void CMFCDynLayoutDemoDlg::EnableDynamicLayoutHelper(bool const enable)\r\n{\r\n   if (enable &amp;&amp; this-&gt;IsDynamicLayoutEnabled())\r\n      return;\r\n\r\n   this-&gt;EnableDynamicLayout(enable ? TRUE : FALSE);\r\n\r\n   if (enable) \r\n   {\r\n      this-&gt;LoadDynamicLayoutResource(m_lpszTemplateName);\r\n   }\r\n}<\/pre>\n<p>As mentioned earlier, setting the move and size values for dynamic layout management can be done programmatically using the <a href=\"http:\/\/CMFCDynamicLayout\" target=\"_blank\"><tt>CMFCDynamicLayout<\/tt><\/a> class. This is important when the controls are created dynamically and not in the resource template. What you have to do is:<\/p>\n<ul>\n<li>create the <tt>CMFCDynamicLayout<\/tt> object<\/li>\n<li>store the host window (the dialog) in that object<\/li>\n<li>add the child controls with their move and size settings<\/li>\n<\/ul>\n<p>The following code provides the same dynamic layout functionality as shown earlier except that all is set from code. Note that you must call <tt>EnableDynamicLayoutHelper<\/tt> from <tt>OnInitDialog<\/tt>.<\/p>\n<pre class=\"lang:c++ decode:true \" >void CMFCDynLayoutDemoDlg::EnableDynamicLayoutHelper(bool const enable)\r\n{\r\n   if (enable &amp;&amp; this-&gt;IsDynamicLayoutEnabled())\r\n      return;\r\n\r\n   this-&gt;EnableDynamicLayout(enable ? TRUE : FALSE);\r\n\r\n   if (enable)\r\n   {\r\n      SetupDynamicLayout();\r\n   }\r\n}\r\n\r\nvoid CMFCDynLayoutDemoDlg::SetupDynamicLayout()\r\n{\r\n   auto manager = this-&gt;GetDynamicLayout();\r\n   if (manager != nullptr)\r\n   {\r\n      auto movenone = CMFCDynamicLayout::MoveSettings{};\r\n      auto moveboth100 = CMFCDynamicLayout::MoveSettings {};\r\n      moveboth100.m_nXRatio = 100;\r\n      moveboth100.m_nYRatio = 100;\r\n      auto movex100 = CMFCDynamicLayout::MoveSettings {};\r\n      movex100.m_nXRatio = 100;\r\n      auto movey100 = CMFCDynamicLayout::MoveSettings {};\r\n      movey100.m_nYRatio = 100;\r\n\r\n      auto sizenone = CMFCDynamicLayout::SizeSettings{};\r\n      auto sizeboth100 = CMFCDynamicLayout::SizeSettings{};\r\n      sizeboth100.m_nXRatio = 100;\r\n      sizeboth100.m_nYRatio = 100;\r\n      auto sizex100 = CMFCDynamicLayout::SizeSettings{};\r\n      sizex100.m_nXRatio = 100;\r\n\r\n      manager-&gt;Create(this);\r\n\r\n      manager-&gt;AddItem(IDC_STATIC_GROUPBOX, movenone, sizeboth100);\r\n      manager-&gt;AddItem(IDC_LIST1, movenone, sizeboth100);\r\n      manager-&gt;AddItem(IDC_EDIT1, movenone, sizex100);\r\n      manager-&gt;AddItem(IDC_BUTTON_ADD, movex100, sizenone);\r\n      manager-&gt;AddItem(IDC_BUTTON_CLEAR, moveboth100, sizenone);\r\n      manager-&gt;AddItem(IDOK, movey100, sizenone);\r\n      manager-&gt;AddItem(IDCANCEL, moveboth100, sizenone);\r\n   }\r\n}<\/pre>\n<p>Actually the same code as above can be expressed differently with the help of several static methods from <tt>CMFCDynamicLayout<\/tt> that create instances of <tt>MoveSettings<\/tt> and <tt>SizeSettings<\/tt>.<\/p>\n<pre class=\"lang:c++ decode:true \" >void CMFCDynLayoutDemoDlg::SetupDynamicLayout()\r\n{\r\n   auto manager = this-&gt;GetDynamicLayout();\r\n   if (manager != nullptr)\r\n   {\r\n      manager-&gt;Create(this);\r\n\r\n      manager-&gt;AddItem(IDC_STATIC_GROUPBOX, CMFCDynamicLayout::MoveNone(), CMFCDynamicLayout::SizeHorizontal(100));\r\n      manager-&gt;AddItem(IDC_LIST1, CMFCDynamicLayout::MoveNone(), CMFCDynamicLayout::SizeHorizontalAndVertical(100, 100));\r\n      manager-&gt;AddItem(IDC_EDIT1, CMFCDynamicLayout::MoveNone(), CMFCDynamicLayout::SizeHorizontal(100));\r\n      manager-&gt;AddItem(IDC_BUTTON_ADD, CMFCDynamicLayout::MoveHorizontal(100), CMFCDynamicLayout::SizeNone());\r\n      manager-&gt;AddItem(IDC_BUTTON_CLEAR, CMFCDynamicLayout::MoveHorizontalAndVertical(100, 100), CMFCDynamicLayout::SizeNone());\r\n      manager-&gt;AddItem(IDOK, CMFCDynamicLayout::MoveVertical(100), CMFCDynamicLayout::SizeNone());\r\n      manager-&gt;AddItem(IDCANCEL, CMFCDynamicLayout::MoveHorizontalAndVertical(100, 100), CMFCDynamicLayout::SizeNone());\r\n   }\r\n}<\/pre>\n<p>One important thing to notice here is that this code does not call <tt>CWnd::LoadDynamicLayoutResource<\/tt> because there are no settings in the resource script file. All these settings are only provided programmatically in this case.<\/p>\n<p>When controls have to move or resize completely (100%) across one or both axes, setting the right values for the layout is straight forward. It gets complicated though when controls are not positioned sideways or need to move or resize with more complicated rules. Let&#8217;s take an example where the OK and Cancel buttons are positioned at the bottom vertically and centered horizontally. When the dialog resizes they should retain the original size, but they should always remain at the center bottom.<\/p>\n<table>\n<tbody>\n<tr valign=\"top\">\n<td><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout10.png\" alt=\"dynlayout10\" width=\"393\" height=\"315\" class=\"alignnone size-full wp-image-2104\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout10.png 393w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout10-300x240.png 300w\" sizes=\"auto, (max-width: 393px) 100vw, 393px\" \/><\/a><\/td>\n<td><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout11.png\" alt=\"dynlayout11\" width=\"531\" height=\"417\" class=\"alignnone size-large wp-image-2105\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout11.png 531w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout11-300x236.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In this case the Y ratio for move is again 100. But what is the move ratio on the X axis? To determine you need a paper and pen. Basically we need to find how much do the buttons move on X when the width increases by 100 units. That is the ratio we have to set.<\/p>\n<p>Initially the dialog has 251 units, that means two halves of 125 and 126 units. We want to keep the buttons apart by 10 units. What means the OK button is left aligned at 70 units and the Cancel button is left alight at 130 units.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout12.png\" alt=\"dynlayout12\" width=\"603\" height=\"256\" class=\"alignnone size-full wp-image-2106\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout12.png 603w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout12-300x127.png 300w\" sizes=\"auto, (max-width: 603px) 100vw, 603px\" \/><\/a><br \/>\nThen we increase the size of the dialog by 100 units. It&#8217;s now 351 and the haves have 175 and 176. The buttons are still 10 units apart and their with is still 50 units each. That means the OK button is now left aligned at 120 units, and the Cancel button is left aligned at 180 units.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout13.png\" alt=\"dynlayout13\" width=\"816\" height=\"257\" class=\"alignnone size-full wp-image-2107\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout13.png 816w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout13-300x94.png 300w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><\/a><br \/>\nThe conclusion is their both left margin has moved 50 units, and that is the value we need to set for the X ratio of their move setting. (Remember, the value is a ratio, but 50 units out of 100 units is also 50%.)<\/p>\n<p>What if the OK and Cancel buttons should both be aligned at the center of their each half on the X axis and always preserve the margins? In other words they should change like this:<\/p>\n<table>\n<tbody>\n<tr valign=\"top\">\n<td><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout14.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout14.png\" alt=\"dynlayout14\" width=\"363\" height=\"315\" class=\"alignnone size-full wp-image-2108\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout14.png 363w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout14-300x260.png 300w\" sizes=\"auto, (max-width: 363px) 100vw, 363px\" \/><\/a><\/td>\n<td><a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout15.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout15.png\" alt=\"dynlayout15\" width=\"547\" height=\"402\" class=\"alignnone size-full wp-image-2109\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout15.png 547w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout15-300x220.png 300w\" sizes=\"auto, (max-width: 547px) 100vw, 547px\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In this example, initially, the dialog has 231 units and that means two halves of 115 and 116 units. The buttons have both 60 units width, so they are aligned at 27 or 28 units to the margins.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout16.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout16.png\" alt=\"dynlayout16\" width=\"597\" height=\"256\" class=\"alignnone size-full wp-image-2110\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout16.png 597w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout16-300x129.png 300w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/a><br \/>\nWhen the width of the dialog increases by 100 units to 331 units, the two halves have 165 and 166 units. The buttons preserve their margins, so their new width is 110 units.<br \/>\n<a href=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout17.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout17.png\" alt=\"dynlayout17\" width=\"812\" height=\"257\" class=\"alignnone size-full wp-image-2112\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout17.png 812w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout17-300x95.png 300w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/a><br \/>\n(Notice that the image above is stretched and the margins may be misleading.)<\/p>\n<p>The conclusion is that:<\/p>\n<ul>\n<li>The OK button did not move horizontally, but it increased its width from 60 units to 110 units, that means 50%.<\/li>\n<li>The Cancel button moved horizontally and is now left aligned at 193 units instead of the original 143 units. That means it moved by 50% horizontally. Its sized increased from 60 units to 110 units, that also means 50%.<\/li>\n<\/ul>\n<p>With those values set the buttons are resized and positioned as intended.<\/p>\n<p>For more information see <a href=\"http:\/\/blogs.msdn.com\/b\/vcblog\/archive\/2015\/04\/29\/mfc-dynamic-dialog-layout.aspx\" target=\"_blank\">MFC Dynamic Dialog Layout<\/a>.<\/p>\n<p>Demo source code:<br \/>\n<div class=\"wp-block-button\">\n<a  data-e-Disable-Page-Transition=\"true\" class=\"dlm-download-link dlm-download-default wp-block-button__link wp-element-button\" title=\"Version 1.0\" href=\"https:\/\/mariusbancila.ro\/blog\/download\/3507\/?tmstv=1791132060\" rel=\"nofollow\" id=\"download-link-3507\" data-redirect=\"false\" >\n\tMFC Dynamic Layout Management - demo 1\t(<span class=\"dlm-download-count-value\">13968 downloads<\/span>\n\t)\n<\/a>\n<\/div>\n<br \/>\n<div class=\"wp-block-button\">\n<a  data-e-Disable-Page-Transition=\"true\" class=\"dlm-download-link dlm-download-default wp-block-button__link wp-element-button\" title=\"Version 1.0\" href=\"https:\/\/mariusbancila.ro\/blog\/download\/3509\/?tmstv=1791132060\" rel=\"nofollow\" id=\"download-link-3509\" data-redirect=\"false\" >\n\tMFC Dynamic Layout Management - demo 2\t(<span class=\"dlm-download-count-value\">13219 downloads<\/span>\n\t)\n<\/a>\n<\/div>\n<br \/>\n<div class=\"wp-block-button\">\n<a  data-e-Disable-Page-Transition=\"true\" class=\"dlm-download-link dlm-download-default wp-block-button__link wp-element-button\" title=\"Version 1.0\" href=\"https:\/\/mariusbancila.ro\/blog\/download\/3511\/?tmstv=1791132060\" rel=\"nofollow\" id=\"download-link-3511\" data-redirect=\"false\" >\n\tMFC Dynamic Layout Management - demo 3\t(<span class=\"dlm-download-count-value\">13991 downloads<\/span>\n\t)\n<\/a>\n<\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Visual Studio 2015 MFC comes with a new features (something that has rarely happen in recent years): support for dynamic dialog layout. That means library support for moving and resizing controls on a dialog. In this article I will show how this feature works. Suppose we have the following dialog: What we want is &#8230; <a title=\"Dynamic Dialog Layout for MFC in Visual C++ 2015\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/\" aria-label=\"Read more about Dynamic Dialog Layout for MFC in Visual C++ 2015\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,12,1],"tags":[451,318,453,34],"class_list":["post-2057","post","type-post","status-publish","format-standard","hentry","category-c","category-mfc","category-uncategorized","tag-c","tag-dialog","tag-mfc","tag-vc"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"vc++,c++,mfc,dialog\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Dynamic Dialog Layout for MFC in Visual C++ 2015\" \/>\n\t\t<meta property=\"og:description\" content=\"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2015-07-27T12:23:21+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2015-07-28T08:25:18+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Dynamic Dialog Layout for MFC in Visual C++ 2015\" \/>\n\t\t<meta name=\"twitter:description\" content=\"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#article\",\"name\":\"Dynamic Dialog Layout for MFC in Visual C++ 2015\",\"headline\":\"Dynamic Dialog Layout for MFC in Visual C++ 2015\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/wp-content\\\/uploads\\\/2015\\\/07\\\/dynlayout1.png\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#articleImage\",\"width\":336,\"height\":293,\"caption\":\"Dialog in original size\"},\"datePublished\":\"2015-07-27T14:23:21+02:00\",\"dateModified\":\"2015-07-28T10:25:18+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#webpage\"},\"articleSection\":\"C++, MFC, Uncategorized, C++, dialog, MFC, VC++\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"position\":4,\"name\":\"C++\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"name\":\"MFC\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"position\":5,\"name\":\"MFC\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#listItem\",\"name\":\"Dynamic Dialog Layout for MFC in Visual C++ 2015\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/#listItem\",\"name\":\"C++\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#listItem\",\"position\":6,\"name\":\"Dynamic Dialog Layout for MFC in Visual C++ 2015\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/c\\\/mfc\\\/#listItem\",\"name\":\"MFC\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/\",\"name\":\"Dynamic Dialog Layout for MFC in Visual C++ 2015\",\"description\":\"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2015\\\/07\\\/27\\\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2015-07-27T14:23:21+02:00\",\"dateModified\":\"2015-07-28T10:25:18+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Dynamic Dialog Layout for MFC in Visual C++ 2015","description":"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/","robots":"max-image-preview:large","keywords":"vc++,c++,mfc,dialog","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#article","name":"Dynamic Dialog Layout for MFC in Visual C++ 2015","headline":"Dynamic Dialog Layout for MFC in Visual C++ 2015","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2015\/07\/dynlayout1.png","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#articleImage","width":336,"height":293,"caption":"Dialog in original size"},"datePublished":"2015-07-27T14:23:21+02:00","dateModified":"2015-07-28T10:25:18+02:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#webpage"},"articleSection":"C++, MFC, Uncategorized, C++, dialog, MFC, VC++"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","position":4,"name":"C++","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","name":"MFC"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","position":5,"name":"MFC","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#listItem","name":"Dynamic Dialog Layout for MFC in Visual C++ 2015"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/#listItem","name":"C++"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#listItem","position":6,"name":"Dynamic Dialog Layout for MFC in Visual C++ 2015","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/#listItem","name":"MFC"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/","name":"Dynamic Dialog Layout for MFC in Visual C++ 2015","description":"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2015-07-27T14:23:21+02:00","dateModified":"2015-07-28T10:25:18+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Dynamic Dialog Layout for MFC in Visual C++ 2015","og:description":"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.","og:url":"https:\/\/mariusbancila.ro\/blog\/2015\/07\/27\/dynamic-dialog-layout-for-mfc-in-visual-c-2015\/","article:published_time":"2015-07-27T12:23:21+00:00","article:modified_time":"2015-07-28T08:25:18+00:00","twitter:card":"summary","twitter:title":"Dynamic Dialog Layout for MFC in Visual C++ 2015","twitter:description":"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes."},"aioseo_meta_data":{"post_id":"2057","title":null,"description":"This article shows how to enable and use dynamic layout management in MFC and also shows how things work behind the scenes.","keywords":[{"label":"VC++","value":"VC++"},{"label":"C++","value":"C++"},{"label":"MFC","value":"MFC"},{"label":"dialog","value":"dialog"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:10:26","updated":"2025-12-12 07:42:26","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":1,"uagb_excerpt":"In Visual Studio 2015 MFC comes with a new features (something that has rarely happen in recent years): support for dynamic dialog layout. That means library support for moving and resizing controls on a dialog. In this article I will show how this feature works. Suppose we have the following dialog: What we want is&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/mfc\/\" class=\"advgb-post-tax-term\">MFC<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">Uncategorized<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">MFC<\/span>","<span class=\"advgb-post-tax-term\">Uncategorized<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">dialog<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">MFC<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/uncategorized\/\" class=\"advgb-post-tax-term\">VC++<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">dialog<\/span>","<span class=\"advgb-post-tax-term\">MFC<\/span>","<span class=\"advgb-post-tax-term\">VC++<\/span>"]}},"comment_count":"1","relative_dates":{"created":"Posted 11 years ago","modified":"Updated 11 years ago"},"absolute_dates":{"created":"Posted on July 27, 2015","modified":"Updated on July 28, 2015"},"absolute_dates_time":{"created":"Posted on July 27, 2015 2:23 pm","modified":"Updated on July 28, 2015 10:25 am"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-xb","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=2057"}],"version-history":[{"count":23,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2057\/revisions"}],"predecessor-version":[{"id":2113,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2057\/revisions\/2113"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=2057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=2057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=2057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}