检测CControlBar的对接状态何时已更改 [英] Detecting when a CControlBar's docking state has changed
问题描述
我使用的是CControlBar派生的类,我想检测CControlBar的停靠状态何时更改(即,从垂直停靠到水平停靠或何时进入浮动模式).
I'm using a CControlBar-derived class and I would like to detect when the docking state of the CControlBar has changed (i.e., docking from vertical to horizontal or when it goes into floating mode).
当然,我可以处理WM_SIZE,但是每次触发WM_SIZE消息而不是仅当对接状态发生更改时,资源浪费在执行任务上都是浪费资源.
Of course, I could handle WM_SIZE but it seems to be a waste of ressources doing the task every time a WM_SIZE message is fired instead of only when the docking state has changed.
有人能指出我正确的方向吗?
Can anyone please point me in the right direction?
推荐答案
您可以覆盖CControlBar::OnBarStyleChange
虚拟函数以检测控制栏样式的更改(CBRS_XXX
值-在<afxres.h>
头文件中查找详细信息).
You can override the CControlBar::OnBarStyleChange
virtual function to detect changes in the control bar style (CBRS_XXX
values - look in the <afxres.h>
header file for details).
要确定控制栏是否浮动/停靠,请检查CBRS_FLOATING
样式.要检查水平/垂直方向,请使用CBRS_ORIENT_HORZ
和CBRS_ORIENT_VERT
样式.
To determine whether the control bar is floating/docked, check the CBRS_FLOATING
style. To check for horizontal/vertical orientation, use the CBRS_ORIENT_HORZ
and CBRS_ORIENT_VERT
styles.
因此,以CToolBar
(从CControlBar
派生)为例:
So, using CToolBar
(which is derived from CControlBar
) as an example:
class CMyToolBar : public CToolBar {
public:
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
};
void CMyToolBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
// Call base class implementation.
CToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
// Use exclusive-or to detect changes in style bits.
DWORD changed = dwOldStyle ^ dwNewStyle;
if (changed & CBRS_FLOATING) {
if (dwNewStyle & CBRS_FLOATING) {
// ToolBar now floating
}
else {
// ToolBar now docked
}
}
if (changed & CBRS_ORIENT_ANY) {
if (dwNewStyle & CBRS_ORIENT_HORZ) {
// ToolBar now horizontal
}
else if (dwNewStyle & CBRS_ORIENT_VERT) {
// ToolBar now vertical
}
}
}
我希望这会有所帮助!
这篇关于检测CControlBar的对接状态何时已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!