Highlight view with focus | CodeGuru

Highlight view with focus

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 7, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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);
}
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.