Minimum size splitter

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:

  1. Add MinSplitterWnd.cpp and MinSplitterWnd.h to your current project (e.g. Menu Project->Add to project->Add files).
  2. Where you currently use CSplitterWnd, replace with CMinSplitterWnd (Note: remember to include MinSplitterWnd.h):
  3. #include "MinSplitterWnd.h" // Minimum size splitter.
    ....
    class CMyWnd : public CMDIChildWnd
    {
        ....
        CMinSplitterWnd m_wndSplitter;
        ....
    };
    
  4. Call SetRowInfo and SetColumnInfo as necessary, specifying the required minimum row and column sizes: (this is normally done in the parent window's OnCreateClient function)
  5. ....
    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.
    ....
    
  6. In the splitter's parent window, add a message handler for OnWindowPosChanging (this prevents the user from sizing the window too small) and add the following code to it:
  7. 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
    }
    
  8. That's it!

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



Comments

  • Beats past Dr Dre, your elect

    Posted by motherdhmm on 06/04/2013 11:04pm

    [url=http://www.headphonescheaponlineaustralia.com/dre-beats-solo-hd-c-66_68_77.html]Dre beats solo HD[/url] An chance to devise stunning variety, you do not uncover which utilizing keystone earphones, a much more being, the pelt facilities headphones fundamentally received an gifted look, however happened a portion more in comparison with accommodating know-how to forge a substantially much more real as articulately as considerate sensational it may be. superb loudspeaker style, difficult to market as well as agile commemorate last make inaccessible capture of to eliminate, especially within well being proficient Beats nearby dre may bear dr dre beast beats provided considerably much wagerer power when compared with headset, guarantees in putting together to a sterling largemouth bass reaches today probably the most paraphernalia pulchritudinous much every on-going songs artist as well as advertising personnel may propose to furnish you unquestionably pay attention. On the and point of view, they are beats sooner than dre cheap. I am liking the instant if I am on the ball music with the headphones. Unquestionably, it is a splendid account for personage with no money. From the artefact packaging, to the adulthood of the sketch out, to the trend, I anticipate that these beats headphones are some of the best clothes out there. Even your headphones or earphones are truly the best. [url=http://blog.cheapbeatsbydre.co.nz/]beats by dre[/url] You can imagine that position on beats by dr.dre headphone and listen to the beautiful music proper like the singer is upright first you and singing for you. We offer beats sooner than dre in a despicable price,Hold it or not, Beats dre australiaIs your epitome choice. What is more, Beats nearby dre headphones is the following of every music fan, I be aware you discretion not miss it! We poor beats by dre headphones think it practical mark is unexceptionally great, especially over-valued, highly recommended. [url=http://www.headphonescheaponlineaustralia.com/dre-beats-solo-hd-c-66_68_77.html]Dre beats solo HD[/url] Certainty the color on your screen.The counterfeits got no sport when it comes down to printing up height tip boxes like the Dr Dre Studios. Don¡¯t be a certain of those wannabe detectives and look all during the course of the buffet with a view little mistakes, look at the puss first.The polished one is the real identical while the darker one is the simulate one.The neck is showing in the authentic only, this is because counterfeits don¡¯t entertain access to strong wind up printers, although its arguable the darker concept is nicer looking but it¡¯s the brighter possibly man that is authentic.

    Reply
  • Ved Ã¥ bruke monster beats hodetelefoner er bedre enn andre

    Posted by mantouhmmm on 06/04/2013 04:31pm

    [url=http://www.beatsdrenorge.webgarden.com/]beats by dre norge[/url] Gjennomføringen av blåkopi er mindre vellykket i transaksjonen, skjønt. Hvor stramt pannebåndet, mangler i sikkerheten kamp, ??og de fleste lav leie versjon av programmet materialer. Mest metall i stedet for plast, gummi, har squidgy solo HD skaut bli en skum-polstret lær filler fot mindre myk. Selv om ikke high-end i forhold til ferdig produkt, er veldig behagelig tempo solo HD, Powerbeats justbeats Zorro, ikke alvorlig. Hengsel metall i et tynt lag av plast, fake-lær-lined ganske komfortabel pad, når de ikke er altfor tydelig en kopi av en annen populær, vil de ikke virke så ille. Funksjoner er to hovedmåter hardware unøyaktig, der takten solo modell, støy separasjon og stabilitet. Reiser god støyisolering er definitivt en på-ører et sett med hodetelefoner, men her er dårlig. Overflate på Beats by Dre justbeats [url=http://www.drebeatsnorge.qsite.dk/]beats by dre norge[/url] Internett er et sted der flere og flere produsenter og slo beslutningstakere samles for å tillate nye artister til å komme og kjøpe sine beats. Det er hundrevis og hundrevis av beat-selger nettsteder på nettet som imøtekomme til kunstnere som har talent, men kan ikke ha et veldig stort budsjett til å kjøpe instrumentaler. Med det blir sagt, er det også mange beat-nettsteder som ikke er satt opp riktig, og kan lage musikk artist nest gjette når det kommer til å kjøpe en instrumental fra noen av disse sites.First du må være i stand til å finne en "FAQ" side på en beat nettsted for å besvare noen av dine spørsmål du måtte ha om du er usikker på noe som er markedsført på nettsiden. Du bør være i stand til å lese alt klart og presist. Hvis du har noen spørsmål bør det være en måte å komme i kontakt med produsenten av Beats By Dre Mixr [url=http://www.beatsdrenorge.webgarden.com/]beats by dre norge[/url] By Dr Dre De makrokosmos kosttilskudd navn hugeness slår nær Dre Solo HD Special.Beats av Dre studio whitened sølv hodetelefoner edition rød-farget hodetelefoner for administrere diskusjon. kosttilskudd opplysninger hugeness slår nær til røde beats solo hd spesiell utgave slår nær dre solo hd gir deg lilje innenfor av dalen fineste kunnskap grunn musikk, Beats Engros hugeness nær Dr. Dre Solo HD-hodetelefoner rød-farget begrenset Edition, rundt jorden med en gang frakt og levering USD 52,30 Kina hotsale Jovial hugeness Beats By Dr Dre Solo HD for store mengder allot ingen verdi frakt og levering, kom fro her fro kjøpe Beats By Dr Dre Solo HD-hodetelefoner rød-farget, august deg 100 spesifikke monster beats bli butikk, Beats hugeness Beats By Dr.Dre Solo HD akseptable Beats By Dre Solo HD rød-farget ControlTalk begrenset Edition nær Dr. Dre Solo HD store Definition OnEar Hodetelefoner Red. elektrisk post fro bare en kompis Vær lilje innenfor av dalen nøkkelen fro evaluering dette produktet. Tilgjengelighet På lager. RegulMonster Beats-hodetelefonene Beats By Dre Solo Red.

    Reply
  • Vedligeholdelse af headset

    Posted by wanzixiao on 06/04/2013 01:03pm

    [url=http://www.kbhretelefonerbillig.webstarts.com/]beats høretelefoner[/url] Derudover dag Beats Electronics udvider sit in-ear produktudbud med lanceringen af de nye urBeats. Disse nye høretelefoner er specielt designet til at være en væsentlig opgradering fra hovedtelefonerne, der kommer med din musikafspiller: mere holdbarhed, bedre lyd, og en chance for at gøre reel retfærdighed til din musik. urBeats giver førsteklasses lydkvalitet, der er blevet synonym med Beats by Dr. Dre mærke. [url=http://www.beatsbydrdredanmark.350.com/]beats by dre danmark[/url] At Pressekonference afholdt med bestyrelsesmedlemmer i selskabet og pressen medlemmer, erklærede direktøren for selskabet, at statistikken over salget efter indførelsen af den nye beats har krydset benchmarks. Den digitale tidsalder med indførelsen af de nye teknologier også nødt til at opretholde de komplementære produkter som pr de nyeste standarder. Dette er, hvad kræver en opgradering i teknologien. Denne opgradering i teknologi er tilgængelig på helt minimerede satser på i form af de nyeste hovedtelefoner og headsets. Monster beats og andre mærker har hjulpet skabe sig en kunstnerisk niche. [url=http://www.beatsbydrdredanmark.moonfruit.com/]beats by dre danmark[/url] Projektet kan opnås på en måde at bruge god til handling og magt lav overflod, og værdiskabende tilbehør. Den faktiske headset komfort element er virkelig stor. Du vil finde disse slag Dre taktslag buy berømtheder certificering af DRE pro at slå Dre studio hovedtelefoner i øret. BIII komme med en rengøringsklud til at sikre, at de er på udkig efter. For nylig fandt jeg en fælles ven kørte vej sat på afDr. Dre Studio hovedtelefoner, derfor vil jeg opfordre til at spørge hende, hvordan de ser ud.

    Reply
  • vPqkc dFn vELg

    Posted by zzZMKBwvMM on 04/06/2013 02:16pm

    tramadol online buy tramadol online overnight mastercard - tramadol for dogs vs tramadol for humans

    Reply
  • a simple way ...

    Posted by FDogY on 06/08/2004 09:25am

    First of all: Putting the variable nIdealSize by SetColumnInfo() or SetRowInfo() serves only as an initial setting!
    nIdealSize is always updated with the current value of the partial window after the first drawing. Use only this value.
    In this context the additional variable nCurSize leads to confusion. Forget about this.
    Here is the really short solution for the "minimum size splitter"-problem: 
    
    1. you create a class which is derived from CSplitterWnd 
    2. overwrite the function RecalcLayout() as follows: 
    
      void  CMySplitterWnd::RecalcLayout(){
        for (int i = 0; i < m_nCols; i++)  { // Check all columns
          if ( m_pColInfo[i].nIdealSize < m_pColInfo[i].nMinSize ) { 
            m_pColInfo[i].nIdealSize=m_pColInfo[i].nMinSize; 
          }
        }
        for (int i = 0; i < m_nRows; i++)  { // Check all rows
          if ( m_pRowInfo[i].nIdealSize < m_pRowInfo[i].nMinSize ) {
            m_pRowInfo[i].nIdealSize=m_pRowInfo[i].nMinSize; 
          }
        }
        CSplitterWnd::RecalcLayout();
      }
    
    3. create an object of your class (CMySpliterWnd m_SplitterWnd)
    4. after creating the SplitterWindow set the (initial) IdealSize value (e.g. 150) and the MinimalSize (e.g. 20) 
      
      m_SplitterWnd.SetColumnInfo(0, 150, 20);
      m_SplitterWnd.SetRowInfo(0, 150, 20);
    
    ready

    Reply
  • Greate work... How can I do the same in VB

    Posted by Legacy on 06/03/2002 12:00am

    Originally posted by: Navneet Gupta

    Hey Dude !
    Great wrok ..

    I want to implement the same thing in Visual Basic can you guide me how can I do this.


    Reply
  • U do a pretty work.There is a Bug in Dynamic Split

    Posted by Legacy on 12/14/2001 12:00am

    Originally posted by: zsj

    U do a good job,But When I create a dynamic split with CScrollView ,the Splitbar stop in wrong position ,I Think You may make a wrong that U have not considered the size of ScrollBox .

    Reply
  • simpler solution continued...

    Posted by Legacy on 08/20/2001 12:00am

    Originally posted by: Alan Kang

    This solution is similar to Vinayak Tadas's suggestion of 
    
    overriding CSplitterWnd::RecalcLayout. This one works
    with all sub-panes. You would still need to call
    SetRowInfo and SetColumnInfo as necessary but there is
    no need to do anything else

    void CSplitterWndEx::RecalcLayout()
    {
    CSplitterWnd::CRowColInfo* pInfo = m_pColInfo;
    CSplitterWnd::CRowColInfo* pInfoNext = pInfo;
    for (int i = 0; i < m_nCols - 1 && pInfo->nCurSize > -1; i++)
    {
    // Check next column
    int nXDiff = (++pInfoNext)->nMinSize -
    (pInfoNext->nCurSize - (pInfo->nIdealSize - pInfo->nCurSize));

    // Adjust the resizing step so that the size of the next col
    // will be at least its min size
    if (nXDiff > 0) pInfo->nIdealSize -= nXDiff;

    // Adjust the resizing step so that the size of this col
    // will be at least its min size
    pInfo->nIdealSize = max(pInfo->nIdealSize, pInfo->nMinSize);
    }

    pInfoNext = pInfo = m_pRowInfo;
    for (i = 0; i < m_nRows - 1 && pInfo->nCurSize > -1; i++)
    {
    // Check next row
    int nYDiff = (++pInfoNext)->nMinSize -
    (pInfoNext->nCurSize - (pInfo->nIdealSize - pInfo->nCurSize));

    // Adjust the resizing step so that the size of the next row
    // will be at least its min size
    if (nYDiff > 0) pInfo->nIdealSize -= nYDiff;

    // Adjust the resizing step so that the size of this row
    // will be at least its min size
    pInfo->nIdealSize = max(pInfo->nIdealSize, pInfo->nMinSize);
    }
    CSplitterWnd::RecalcLayout();
    }


    Reply
  • An even simple solution .....

    Posted by Legacy on 10/08/1999 12:00am

    Originally posted by: Vinayak Tadas

    Retain only the OnMouseMove function in the above class and modify the 
    
    RecalcLayout() function as below. You can remove all the
    other functions and structures ....


    void CMinSplitterWnd::RecalcLayout()
    {
    CSplitterWnd::CRowColInfo* pInfoArray = m_pColInfo;
    CSplitterWnd::CRowColInfo* pInfo;
    int i =0;
    for (i = 0, pInfo = pInfoArray; i < m_nCols-1; i++,
    pInfo++)
    {
    if (pInfo->nIdealSize < pInfo->nMinSize)
    pInfo->nIdealSize = pInfo->nMinSize;
    pInfo->nCurSize = pInfo->nIdealSize;
    }

    CSplitterWnd::RecalcLayout();
    }

    Reply
  • Thank U mail

    Posted by Legacy on 09/20/1999 12:00am

    Originally posted by: wowow

    This is the article what I was looking for.
    The 'minimum size splitter' may not be very useful for most people, but there's always somebody really, really needs it.( eg., me! )

    I thank U again and I expect many other useful articles from U and the CodeGuru.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds