For my latest project we needed splitter panes that had proper minimum sizes, in that the user couldn't physically resize the splitter pane smaller than a specified amount. The standard MFC splitter class allows you to set minimum sizes, but these only affect what is displayed, not how small the panes can be. CMinSplitterWnd is a drop-in replacement for (and is derived from) CSplitterWnd.
Instructions:
#include "MinSplitterWnd.h" // Minimum size splitter. .... class CMyWnd : public CMDIChildWnd { .... CMinSplitterWnd m_wndSplitter; .... };
.... m_wndSplitter.CreateStatic( this, 2, 2 ); // Create with 2 rows and 2 columns. m_wndSplitter.SetRowInfo( 0, 100, 100 ); // Set ideal and minimum size to 100. m_wndSplitter.SetRowInfo( 1, 100, 100 ); // Set ideal and minimum size to 100. m_wndSplitter.SetColumnInfo( 0, 100, 100 ); // Set ideal and minimum size to 100. m_wndSplitter.SetColumnInfo( 1, 100, 100 ); // Set ideal and minimum size to 100. ....
void CMyWnd::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { // Don't do anything if minimized. if ( IsIconic() ) { CMDIChildWnd::OnWindowPosChanging( lpwndpos ); return; } // if // Calculate the window rect if we have no client area. CRect rc( 0, 0, 0, 0 ); CalcWindowRect( rc ); // Add on the minimum client width and height from the splitter. int nMinWidth = rc.Width() + m_wndSplitter.GetMinClientWidth(); int nMinHeight = rc.Height() + m_wndSplitter.GetMinClientHeight(); // Get the current window size. CRect rcWindow; GetWindowRect( rcWindow ); GetParent()->ScreenToClient( rcWindow ); // If trying to size too small... if ( lpwndpos->cx < nMinWidth ) { // If dragging left border right... if ( rcWindow.left < lpwndpos->x ) { // How much over are we? int nOver = nMinWidth - lpwndpos->cx; // Adjust left coord. lpwndpos->x -= nOver; } // if // Fix width. lpwndpos->cx = nMinWidth; } // if // If trying to size too small... if ( lpwndpos->cy < nMinHeight ) { // If dragging top border down... if ( rcWindow.top < lpwndpos->y ) { // How much over are we? int nOver = nMinHeight - lpwndpos->cy; // Adjust left coord. lpwndpos->y -= nOver; } // if // Fix height. lpwndpos->cy = nMinHeight; } // if }
Limitation:
If the minimum sizes exceed the initial frame window size, the window will snap when the window is first resized.
Download demo project and executable - 36 KB
Date Posted: August 20, 1998 - updated August 25, 1998
Add Comment
INSTANT EXPERTS!Savvy IT Pros report on SupportSource. Take a look inside the largest vault of multi-vendor computing specs ever assembled. Click here for an In-depth Report,. For tons of Windows technology resources, check out the Windows Programming directory. Go to Fatbrain for the NEWEST and BEST technical books for IT professionals. Searching the Web for tech topics just got better withTechCrawler where all results come only from popular technical sites. WINNER!!! Congratulations to James Hole, of New Mexico! The grand prize winner of EarthWeb's Flatten the Obstacles Sweepstakes and now a proud Hummer(R) owner.
WINNER!!! Congratulations to James Hole, of New Mexico! The grand prize winner of EarthWeb's Flatten the Obstacles Sweepstakes and now a proud Hummer(R) owner.