【CSplitterWnd技巧一】改变分割窗口拖动条的大小
作者:周焱
大家都知道默认的CSplitterWnd的拖动条很宽,看起来占地方,也不美观。怎么改变它呢?
研究CSplitterWnd的构造函数发现,拖动条的宽度是可以设置的。下面是我写的一个简单的CMySplitter类。他的效果如下:
下面是CMySplitter的代码:
=========================================================
//MySplitter.h
#pragma once
#include "stdafx.h"
class CMySplitter : public CSplitterWnd
{
public:
CMySplitter();
DECLARE_DYNCREATE(CMySplitter)
public:
~CMySplitter();
protected:
DECLARE_MESSAGE_MAP()
};
=========================================================
//MySplitter.cpp
#include "MySplitter.h"
IMPLEMENT_DYNCREATE(CMySplitter, CSplitterWnd)
//在构造函数中改变分割条的宽度和属性!
CMySplitter::CMySplitter()
{
m_cxSplitter = 4; //must >=4 ,拖动时拖动条的宽度
m_cySplitter = 4;
m_cxBorderShare = 0; //按下鼠标时拖动条的偏移量
m_cyBorderShare = 0;
m_cxSplitterGap= 1; //splitter拖动条的宽度
m_cySplitterGap= 1;
}
CMySplitter::~CMySplitter()
{
}
BEGIN_MESSAGE_MAP(CMySplitter, CSplitterWnd)
END_MESSAGE_MAP()
=========================================================
使用时,在主窗口中包含头文件MySplitter.h,将CSplitterWnd改成CMySplitter就可以了。