設定漂亮的工具條(代碼是拷貝來的,但是經過實驗)

來源:互聯網
上載者:User

預設的VC單文檔或者多文檔的工具條是一個個的表徵圖,下面這段代碼可以讓你得到一個上邊是表徵圖下邊是文字的工具條。

代碼:

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
        | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to create toolbar/n");
        return -1;      // fail to create
    }

    if (!m_wndStatusBar.Create(this) ||
        !m_wndStatusBar.SetIndicators(indicators,
          sizeof(indicators)/sizeof(UINT)))
    {
        TRACE0("Failed to create status bar/n");
        return -1;      // fail to create
    }
/*這裡插入代碼*/
    // 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);

 

/*插入以下代碼*/
    m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
        CBRS_GRIPPER | CBRS_BORDER_3D | CBRS_TOOLTIPS | CBRS_FLYBY |
CBRS_SIZE_DYNAMIC);

    // Add text to each button
    for(int i = 0; i < m_wndToolBar.GetCount(); i++)
    {
        UINT id = m_wndToolBar.GetItemID(i);
        CString s;
        if(!s.LoadString(id))
            continue;
        int j = s.Find(_T('/n'));
        if(j < 0)
            continue;
        s = s.Right(s.GetLength() - j - 1);
        m_wndToolBar.SetButtonText(i, s);
    }
    CRect rect;
    m_wndToolBar.GetItemRect(0, &rect);
    m_wndToolBar.SetSizes(rect.Size(),CSize(16, 15));

 

思路:設定工具條的Style,並擷取每個ID所對應的字串,從中提取ToolTip的內容作為ButtonText的內容,然後重新安排工具條的大小。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.