Click here to Skip to main content
Click here to Skip to main content

Highlight view with focus

By , 10 Jan 2000
 

Many times it would be nice to have some visual feedback as to which pane in a split view currently has the focus. This is very useful if you have multiple view types and different keyboard strokes cause different actions in each.

NOTE: This uses an undocumented feature in MFC so be careful in the future.

Step 1) Derive your own SplitterWnd class.
Step 2) Override the undocumented OnDrawSplitter function.
Step 3) Replace the CSplitterWnd instance in the child frame with your splitter.

This example draws in red but you can adjust the color and width of the frame by altering the define values.

/////////////////////////////////////////////////////////////////////////////
// MySplitterWnd.h

class MySplitterWnd : public CSplitterWnd
{
public: 
    int cRow;
    int cCol; 
    MySplitterWnd();
    void OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rectArg);
    void RefreshSplitBars(void);
};

/////////////////////////////////////////////////////////////////////////////
// MySplitterWnd.cpp

#include "StdAfx.h"
#include "MySplitterWnd.h"

#define FOCUS_HILIGHT_COLOR_ULO RGB(180, 75, 25)
#define FOCUS_HILIGHT_COLOR_LRO RGB(245, 5, 25)
#define FOCUS_HILIGHT_COLOR_ULI RGB(145, 95, 75)
#define FOCUS_HILIGHT_COLOR_LRI RGB(220, 65, 40)

#define FOCUS_HILIGHT_SHOW TRUE

#define SPLITTER_CX 4
#define SPLITTER_CY 4
#define SPLITTER_GAPX 4
#define SPLITTER_GAPY 4

void MySplitterWnd::RefreshSplitBars(void)
{
    CRect rectInside;

    GetInsideRect(rectInside);
    DrawAllSplitBars(NULL, rectInside.right, rectInside.bottom);
}

MySplitterWnd::MySplitterWnd()
{
    cRow = 0;
    cCol = 0;

    m_cxSplitter = SPLITTER_CX;
    m_cySplitter = SPLITTER_CY;
    m_cxSplitterGap = SPLITTER_GAPX;
    m_cySplitterGap = SPLITTER_GAPY;
}

void MySplitterWnd::OnDrawSplitter(CDC* pDC, ESplitType nType,
                                   const CRect& rectArg)
{
    if ((FOCUS_HILIGHT_SHOW) && ((GetRowCount() > 1) || 
        (GetColumnCount() > 1)) && (nType == splitBorder))
    {
        int pRow = 0;
        int pCol = 0;
        if (rectArg.top)
        {
            pRow = 1;
        }
        if (rectArg.left)
        {
            pCol = 1;
        }
        if ((cRow == pRow) && (cCol == pCol))
        {
            if (pDC == NULL)
            {
                RedrawWindow(rectArg, NULL, RDW_INVALIDATE|RDW_NOCHILDREN);
                return;
            }
            ASSERT_VALID(pDC);
            CRect rect = rectArg;
            pDC->Draw3dRect(rect, 
                FOCUS_HILIGHT_COLOR_ULO, FOCUS_HILIGHT_COLOR_LRO);
            rect.InflateRect(-GetSystemMetrics(SM_CXBORDER), 
                             -GetSystemMetrics(SM_CYBORDER));
            pDC->Draw3dRect(rect,
                FOCUS_HILIGHT_COLOR_ULI, FOCUS_HILIGHT_COLOR_LRI);
            return; 
        }
    }

    CSplitterWnd::OnDrawSplitter(pDC,nType,rectArg); 
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Randy More
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
General3 static splitter windowsussweilun31 Aug '04 - 20:01 
hi,your article is very good Smile | :)
but I have a question.. When I make a 2 static splitter it works well
but when I make a 3 static splitter window,just like the way "powerpoint". It does'nt work! >"< Could you help me!? thanks!
 
some codes like that..
 
BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) {
m_wndSplitter.CreateStatic(this,1,2);
if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CAutomaticSplitterView),CSize(210,100),pContext)
||
!m_wndSplitter2.CreateStatic(&m_wndSplitter, 2, 1,WS_CHILD | WS_VISIBLE, m_wndSplitter.IdFromRowCol(0, 1))
||
!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CView2),CSize(0,500),pContext)
||
!m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(CView3),CSize(0, 0), pContext)
)
{
AfxMessageBox("Create View Failed!");
return FALSE;
}
return TRUE;
}
 
1.the left window
((CChildFrame*)GetParentFrame())->m_wndSplitter.RefreshSplitBars();
 
2.the top-right window
((CChildFrame*)GetParentFrame())->m_wndSplitter2.RefreshSplitBars();
 
3.the bottom-right window
((CChildFrame*)GetParentFrame())->m_wndSplitter2.RefreshSplitBars();
 

 


GeneralMFC7 unhandled exceptionmemberNate Strandberg9 Jul '03 - 17:16 
Hey I keep getting an unhandled exception when I try to use this code in an MFC7 SDI application.. I know it works and I'm doing it right because I can use it with MFC6 fine.
 
Anyway, down to business. The problem is in the function "RefreshSplitBars" and the line that causes it is "GetInsideRect".. I don't know what Microsoft changed in MFC7 that would make this fail, but does anyone have an idea on how to fix it?
 

Thanks!
Nate S.
GeneralStatic SplitsmemberDavid Jones17 Jan '02 - 4:06 
Can anybody tell me how to do this using static splits. I tried to simply add the code but all that happens is that one pane is highlighted all the time.
 
Thanks in advance
 
David
Questionhow to access these protected functionssussDarren Schroeder9 May '00 - 5:46 
this is cut-n-paste from afxext.h
 
these are called overridables however i cannot override them because they're protected. what do i not understand about implementing this code?
 
// Overridables
protected:
// to customize the drawing
enum ESplitType { splitBox, splitBar, splitIntersection, splitBorder };
virtual void OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rect);
virtual void OnInvertTracker(const CRect& rect);

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 11 Jan 2000
Article Copyright 2000 by Randy More
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid