状态栏总在CDialogBar上方的问题解决方法

在VC单文档工程中,当在文档底部创建不可拖放停靠的CDialogBar时,状态栏会出现在CDialogBar上方。解决方法包括在CMainFrame::OnCreate中调整创建代码,并重载ControlBar的鼠标左键单击和双击消息,目的是阻止拖放停靠功能。目前仅拦截鼠标消息,快捷键拦截尚未实现。
摘要由CSDN通过智能技术生成

状态栏总在CDialogBar上方的问题解决方法


场景: 一个VC单文档工程中在文档底部创建一个CDialogBar, 并且要求CDialogBar不能被拖放停靠, 

这就是要实现如图的效果:



按照步骤创建CDialogBar, 发现状态栏在CDialogBar的上方. 如图所示



解决方法如下:

1. CMainFrame::OnCreate中创建代码

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_TOOLTIPS) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	// RightBar的创建 注意创建风格
	if (!m_RightBar.Create(this, CRightBar::IDD, 
		CBRS_RIGHT | CBRS_TOOLTIPS | CBRS_HIDE_INPLACE | CBRS_FLYBY | CBRS_FLOATING, CRightBar::IDD))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	// BottomBar的创建 注意创建风格
	if (!m_BottomBar.Create(this, CBottomBar::IDD, 
		CBRS_BOTTOM | CBRS_TOOLTIPS | CBRS_HIDE_INPLACE | CBRS_FLYBY | CBRS_FLOATING, CBottomBar::IDD))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	//
	// 这下面两段代码就是使ControlBar停靠在状态栏上方的代码
	// 如果不添加这两段代码, 状态栏就会乱跑.. 但是, 上面的创建代码创建ControlBar的属性
	// 是不可拖放停靠的, 如果加了下面两段代码, ControlBar却变成了可以拖
	// 放停靠, 可以悬浮出来.
	// 现在的解决办法就是重载ControlBar的鼠标左键单击消息和鼠标左键双击消息.
	m_RightBar.EnableDocking(CBRS_ALIGN_RIGHT);
	EnableDocking(CBRS_ALIGN_RIGHT);
	DockControlBar(&m_RightBar);

	m_dlgBottomBar.EnableDocking(CBRS_ALIGN_BOTTOM);
	EnableDocking(CBRS_ALIGN_BOTTOM);
	DockControlBar(&m_BottomBar);
	//
	// TODO: Delete these three lines if you don't want the toolbar to be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	return 0;
}

1. 重载ControlBar的鼠标左键单击消息和鼠标左键双击消息.

void CRightBar::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	// 屏蔽掉父类的OnLButtonDown
	//CDialogBar::OnLButtonDown(nFlags, point);
}

void CRightBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	// 屏蔽掉父类的OnLButtonDblClk
	//CDialogBar::OnLButtonDblClk(nFlags, point);
}

void CBottomBar::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	// 屏蔽掉父类的OnLButtonDown
	//CDialogBar::OnLButtonDown(nFlags, point);
}

void CBottomBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	// 屏蔽掉父类的OnLButtonDblClk
	//CDialogBar::OnLButtonDblClk(nFlags, point);
}

其实原理就是, 工具栏或者ControlBar的拖放停靠功能需要鼠标点击或者双击消息来处理的, 把它们拦截掉就行了. 

  如果拖放停靠有快捷键的话, 那就还要拦截快捷键


现在还没有找到治本的方法.


参考:(收到这篇文章的启发的)

http://www.vckbase.com/index.php/wv/359


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值