Showing Window Contents While Resizing the Splitter

Environment: Visual C++

The CSplitterWnd class of MFC does not draw panes while resizing. My class allows you to show a window's contents while you are resizing the splitter pane. It supports only one row and two columns per splitter window now, but you can contribute additional code and develop it.

The CSplitterWnd class does not handle WM_SIZING because the window itself does not resize -- neither do child windows -- because the splitter does not notify them until the sizing finishes. I have used the WM_MOUSEMOVE handler with the MK_LBUTTON flag; this means that the user is dragging the splitter bar while moving the mouse. I have overriden the base class' handler and put in my code to resize and paint panes while the user is dragging. I have also used two values to handle drag's start coordinates; you may use it as POINT or CPoint, instead of two variables.

class CMySplitter : public CSplitterWnd
  virtual ~CMySplitter();
  // Overrides
  // ClassWizard generated virtual function overrides
  // {{AFX_VIRTUAL(CMySplitter)
  int moveX;  // move start X
  int moveY;  // move start Y
  afx_msg void OnMouseMove(UINT nFlags, CPoint pt);
  afx_msg void OnLButtonDown(UINT nFlags, CPoint pt);

In implementation:

void CMySplitter::OnLButtonDown(UINT nFlags, CPoint pt)
  moveX=pt.x; // move start X position
  moveY=pt.y; // move start Y position
  CSplitterWnd::OnLButtonDown(nFlags, pt);

void CMySplitter::OnMouseMove(UINT nFlags, CPoint pt)
  if (nFlags==MK_LBUTTON) // Left button pressed
    static int resized=0; // we will check if pane is resizing
    if (!resized)
      int cxCur=0, cxMin=0;
      GetColumnInfo(0,cxCur, cxMin); // Get col's size before resizing
      if (moveY!=pt.y)               // If mouse moved vertically
      moveY=pt.y;                    // discard it
      if (pt.y==moveY)               // Are we ready to resize?
        if (pt.x<moveX) // if pane 0 is resizing to the left side
                          // i.e. getting smaller
          if (cxCur+(pt.x<moveX?pt.x-moveX:1)>=0)
          // will new size be greater than, or equal to, 0?

          // set it
          moveX=pt.x; // set move start point to current position
      if (pt.x>moveX) // if pane 0 is resizing to the right side
                         // i.e. getting larger
      if (cxCur+(pt.x>moveX?pt.x-moveX:-1)>=0)
      // check for new size, again
      SetColumnInfo(0,cxCur+(pt.x>moveX?pt.x-moveX:-1), cxMin);
      // set it
      moveX=pt.x; // set move start point to current position
    if (pt.x!=moveX)   // hmm. mouse moved in vertical
      moveY=pt.y;      // anyway, set it to current Y coordinate
    RecalcLayout();    // recalculate pane sizes, and redraw
    GetColumnInfo(0,cxCur, cxMin); // get pane info
    moveX=cxCur;       // set current start position to pane's width
    resized=1;         // yes, we are resized
  if (resized)         // we have resized pane
    resized=0;         // reset to resize in next time
  CSplitterWnd::OnMouseMove(nFlags, pt);
  // if not leftbutton down, do the default thing.

Add this class into your project and create the splitter as you were creating it before.

There might be programming errors on the preceding code. I wrote it hurriedly because I need it. I run the code without any exceptions.

I am open for suggestions and corrections. Please feel free to write.


Download demo project - 35 Kb
Download source - 42 Kb


  • Something that other people does when dealing with nike and furthermore those things youshould do completely different.

    Posted by icoppyapedcap on 04/23/2013 07:59pm

    UbvGmiDjaMss[url=]グッチ バッグ[/url]KyaCpzPloMjq [url=【グッチ】レディース財布-c-5.html]グッチ キーケース[/url]QfxAqzRcrYus [url=【グッチ】レディース長財布-c-6.html]グッチ 財布 新作[/url]TawFpxHnpHgk [url=【グッチ】ショルダーバッグ-c-2.html]gucci アウトレット[/url]TcsXbmWqsRvt IkrPwvJxrFwf [url=]adidas originals[/url]HfxSnpDtqNor [url=]ナイキ[/url]SinQmnTrcLao AnlAirAdySui [url=]chanel[/url] WbvZppGqvExv [url=シャネル財布-c-9.html]chanel 財布[/url]NfsJgzIupHme [url=シャネル-ショルダーバッグ-c-1.html]シャネル マトラッセ[/url]HejMcgVzmQyg EusWutFzeXyx [url=]クロエ 財布[/url] UhkNiqWyyOcl [url=クロエ-長財布-c-3.html]クロエ 長財布[/url] TndPzlUmrXmm [url=クロエ-ハンドバッグ-c-2.html]chloe バッグ[/url] VloBloPmcAsp

  • is absent

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

    Originally posted by: Alexi Jordanov is absent

    Regards, Alex

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

Top White Papers and Webcasts

  • Thanks to the Internet of Things (IoT), physical assets are turning into participants in real-time global digital markets. The countless types of assets around us will become as easily indexed, searched and traded as any online commodity. While some industries will be tougher to transform than others – those with physical limitations, such as manufacturing, will be harder to digitize – untold economic opportunities exist for growth and advancement. Our research shows this will create a new "Economy …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date