MFC CControlBar

Posted

技术标签:

【中文标题】MFC CControlBar【英文标题】: 【发布时间】:2016-03-18 00:18:30 【问题描述】:

您如何确定/确定(从控制栏,或从它附加到的框架)CControlBar 附加到框架的哪一侧?

我知道你可以:

    通过 BOOL IsFloating( ) const 确定控制栏是否浮动; 告诉控制栏允许将框架的哪一侧连接到 CBRS_ALIGN_TOP、AFX_IDW_DOCKBAR_TOP

但我不知道如何检索它已停靠在哪一侧。希望有一个像 CurrentDockedTo() 这样的方法可以返回 CBRS_ALIGN_TOP, AFX_IDW_DOCKBAR_TOP ...

我正在寻找找出主窗口中剩余多少灰色空间的最快方法...灰色矩形的大小

【问题讨论】:

您可以获取控制栏位置并将其转换为容器的客户端坐标并比较值。 好吧,我在想这个解决方案可能是我唯一的选择......希望有更好的选择...... GetAttachSide() 方法。谢谢。 【参考方案1】:

您应该可以使用 GetBarStyle

https://msdn.microsoft.com/en-us/library/6y1e7ff1.aspx

【讨论】:

【参考方案2】:

我为我的问题找到了一个非常简单的解决方案。正是我需要的答案。在以下帖子中找到了引导我走上正确道路的初步提示:

Detecting when a CControlBar's docking state has changed

我要求的代码如下:

CPtrList& list = this->m_listControlBars;
POSITION pos = list.GetHeadPosition();

int total_cntrl_bars_found = 0;
while(pos)

  CControlBar* pBar = (CControlBar*)list.GetNext(pos);
  if(pBar)
  
    if(!pBar->IsFloating())
    
      total_cntrl_bars_found++;

      int total_matched_styles = 0;
      DWORD bar_style = pBar->GetBarStyle();
      if(bar_style & CBRS_ORIENT_VERT)
      
        // Then the bar is vertially oriented
        // Will additionally also pass either the
        // right oriented or left oriented check depending
        total_matched_styles++;
      
      if(bar_style & CBRS_ORIENT_HORZ)
      
        // Then the bar is vertially oriented
        total_matched_styles++;
      
      if(bar_style & CBRS_ALIGN_RIGHT)
      
        // Then the bar is right aligned                                          
        total_matched_styles++;
      
      if(bar_style & CBRS_ALIGN_LEFT)
      
        // Then the bar is left aligned
        total_matched_styles++;
      
      // There is also a check for top align
      // and bottom aligned
    
  
       

这里有一些关于 GetBarStyle() 的更多信息

https://msdn.microsoft.com/en-us/library/6y1e7ff1.aspx

【讨论】:

以上是关于MFC CControlBar的主要内容,如果未能解决你的问题,请参考以下文章

在mfc中如何使用按钮依次输入数据

c++ mfc 代码

(转载)DLL动态链接库编程入门之五:MFC扩展DLL

MFC控件消息

VS2010-MFC(MFC常用类:MFC异常处理)

mfc 关于Accept函数