Im the last person to write better MFC code than these gurus, but I think this is probably an underutilized class so it fell through the cracks.
The problem:
Create a CXTResizeFormView from a dialog and start your application. Grab the right edge of the window and shrink it to the left until you get the horizontal scroll bar (but not a vertical one). Thats correct behavior so far. Now, enlarge the window in the vertical direction (drag the resize handle downward). You see that the form did not resize in the vertical direction, even though there was plenty of room to do so. All resizing stops as soon as either the vertical or horizontal scrollbar makes an appearance. That is correct behavior for when both scrollbars are needed (H & V), but when you have just one, the other direction should freely expand.
Now, slowly enlarge the window to the right until the horizontal scroll bar is no longer needed. VOOM! The form suddenly enlarged to fill the window.
A cheap solution:
1) Add two protected fields to your formview class: int lastCx, lastCy. Initialize them to 0 in your creation method.
2) Create an OnSize message handler that has two lines of code:
CFormView::OnSize(nType, cx, cy); FormSize(cx, cy);
3) Go to the CXTResize source code and add the following static method into your cpp file: static bool _IsGroupBox(HWND hWnd)
4) now we create the FormSize() method. Base it on the Size() method from the CXTResize source (cut and paste it).
5) The following changes need to be made to the FormSize method:
Just AFTER the line "int dx = rcWindow.Width() - m_rcWindow.Width();" add
if (cx < m_totalLog.cx) dx = 0;
Just AFTER the line "int dy = rcWindow.Height() - m_rcWindow.Height();" add
if (cy < m_totalLog.cy) dy = 0;
Just PRIOR to the line "m_rcWindow = rcWindow;" add the following:
if (cx >= m_totalLog.cx && cy >= m_totalLog.cy) { if (lastCx < m_totalLog.cx || lastCy < m_totalLog.cy) { CXTResize::Reset(); } }
lastCx = cx; lastCy = cy;
Now resize the window as mentioned earlier. There are still problems if the formview is a tabbed view and it is not the active window, the window gets resized, then the view is made active. But its much better than before.
|