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
{
public:
  CMySplitter();
  virtual ~CMySplitter();
  // Overrides
  // ClassWizard generated virtual function overrides
  // {{AFX_VIRTUAL(CMySplitter)
  // }}AFX_VIRTUAL
protected:
  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);
  DECLARE_MESSAGE_MAP()
};

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?
          {

          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) // 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
      }
    }
  }
  else
    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
    return;
  }
  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.

Downloads

Download demo project - 35 Kb
Download source - 42 Kb


Comments

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

    Reply
  • http://www.codeguru.com/dialog/splitterdemo.exe is absent

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

    Originally posted by: Alexi Jordanov

    http://www.codeguru.com/dialog/splitterdemo.exe is absent

    Regards, Alex

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Mobile devices, social business apps, and business analytics are converging with the Cloud to create the most substantial changes in technology since the Internet revolution. Businesses have to change the way they think and operate, and with rising budgets for technology, they need someone to provide the services that will keep them competitive in this environment. Learn more about the important technology trends you need to stay on top of to ensure your business doesn't get left behind.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds