Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - A better CXTResizeFormView (code inside)
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

A better CXTResizeFormView (code inside)

 Post Reply Post Reply
Author
Message
ddyer View Drop Down
Groupie
Groupie
Avatar

Joined: 01 December 2003
Location: United States
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote ddyer Quote  Post ReplyReply Direct Link To This Post Topic: A better CXTResizeFormView (code inside)
    Posted: 09 December 2003 at 8:35am

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.

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.