Detecting when a CControlBar's docking state has changed

后端 未结 1 360
长发绾君心
长发绾君心 2021-01-24 05:05

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 goe

1条回答
  •  北海茫月
    2021-01-24 05:12

    You can override the CControlBar::OnBarStyleChange virtual function to detect changes in the control bar style (CBRS_XXX values - look in the header file for details).

    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.

    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            
            }
        }
    }
    

    I hope this helps!

    0 讨论(0)
提交回复
热议问题