VC单文档分割窗口3--重绘分割条

1.初始化分割条的大小,在CMySplitter的构造函数中添加如下程序。

CMySplitter::CMySplitter(void)
{
	this->m_cxSplitter = 40;//must >=4,分割条的宽度
	this->m_cySplitter = 10;
	this->m_cxBorderShare = 0;//按下鼠标的拖动量
	this->m_cyBorderShare = 0;
	this->m_cxSplitterGap = 40;//拖动条的宽度
	this->m_cySplitterGap = 10;
}

 

2.接前面的项目,增加CMySplitter的消息响应函数OnDrawSplitter。

void CMySplitter::OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rect)

 

3.函数中的nType是当前要重绘的风格类型

splitBox   The splitter drag box.
splitBar   The bar that appears between the two split windows.
splitIntersection The intersection of the split windows. This element will not be called when running on Windows 95.
splitBorder   The split window borders. 
#define CX_BORDER 10
#define CY_BORDER 10
void CMySplitter::OnDrawSplitter(CDC* pDC, ESplitType nType, const CRect& rect)
{
	// TODO: 在此添加专用代码和/或调用基类
	
	if(pDC==NULL)     
	{     
		RedrawWindow(rect,NULL,RDW_INVALIDATE|RDW_NOCHILDREN);   
		return;   
	}     

	CRect rc = rect;
	
	switch(nType)
	{
	case   splitBorder:   
		//重画分割窗口边界,使之为红色     
		pDC->Draw3dRect(rc,RGB(255,0,0),RGB(255,0,0));   
		//rc.InflateRect(-CX_BORDER,-CY_BORDER);
		pDC->Draw3dRect(rc,RGB(255,0,0),RGB(255,0,0));
		//break;
		return;    
		
	case   splitBox:   
		/*pDC->Draw3dRect(rc,RGB(0,0,0),RGB(0,0,0));   
		rc.InflateRect(-CX_BORDER,-CY_BORDER);     
		pDC->Draw3dRect(rc,RGB(255,255,0),RGB(255,255,0));   
		rc.InflateRect(-CX_BORDER,-CY_BORDER);   
		pDC->FillSolidRect(rc,RGB(255,255,0));     
		pDC->Draw3dRect(rc,RGB(0,0,0),RGB(0,0,0));*/
		//break;
		return;
	case   splitBar:
		//重画分割条,使之为蓝色
		//rc.InflateRect(-5,-5);
		pDC->FillSolidRect(rc,RGB(0,0,255));   
		//pDC->Draw3dRect(rc,RGB(255,0,0),RGB(255,0,0));
		//break;
		return;
	default:     
		//ASSERT(FALSE);
		break;
	}     

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

 

 

你可能感兴趣的:(VC单文档分割窗口3--重绘分割条)