Locking splitter windows

Earlier today, someone asked on the vc.mfc NG how he can lock his splitter windows. I replied to him asking him to handle WM_SETCURSOR, WM_LBUTTONDOWN and WM_LBUTTONUP in a CSplitterWnd derived class and to call the base class implementation only if locking is disabled. Later, I decided to try it out and found that there was no need to handle WM_LBUTTONUP but that WM_MOUSEMOVE should be handled. I replied to him again, correcting my earlier post. For future reference, I thought it best to blog about it here and the relevant code snippets are posted below :-

class CLockSplitterWnd : public CSplitterWnd;

//. . .

BEGIN_MESSAGE_MAP(CLockSplitterWnd, CSplitterWnd)
    ON_WM_LBUTTONDOWN()
    ON_WM_SETCURSOR()
    ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

//. . .

void CLockSplitterWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
    if(m_bLocked)
        CWnd::OnLButtonDown(nFlags, point);
    else
        CSplitterWnd::OnLButtonDown(nFlags, point);
}

BOOL CLockSplitterWnd::OnSetCursor(CWnd* pWnd,
    UINT nHitTest, UINT message)
{
    if(m_bLocked)
        return CWnd::OnSetCursor(pWnd, nHitTest, message);
    else
        return CSplitterWnd::OnSetCursor(pWnd, nHitTest, message);
}

void CLockSplitterWnd::OnMouseMove(UINT nFlags, CPoint point)
{
    if(m_bLocked)
        CWnd::OnMouseMove(nFlags, point);
    else
        CSplitterWnd::OnMouseMove(nFlags, point);
}
Advertisements

2 thoughts on “Locking splitter windows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s