0

我编写了一个带有工具栏的 MDI 应用程序,但是子窗口过度绘制了框架窗口的工具栏。这里是效果,我要点击左上角才能看到工具栏图标。

在此处输入图像描述

我使用以下代码创建工具栏:

CToolBar::CToolBar(HINSTANCE hInst, HWND hParent, LPCTSTR lpszWindowName) :
        CWindow(hInst, hParent, lpszWindowName)
{
        INITCOMMONCONTROLSEX icex;

        // Ensure that the common control DLL is loaded.
        icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
        icex.dwICC  = ICC_BAR_CLASSES;
        InitCommonControlsEx(&icex);

        lstrcpy(m_szClassName, TOOLBARCLASSNAME);
}

BOOL CToolBar::Create()
{
        //create the toolbar
        m_hWnd = CreateWindowEx(0, TOOLBARCLASSNAME, (LPCTSTR) NULL,
                WS_CHILD, 0, 0, 0, 0, m_hParent,
                (HMENU) ID_TOOLBAR, m_hInst, NULL);

        //for backword compatibility
        SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);

        if (m_hWnd == NULL)
                return FALSE;
        return TRUE;
}

BOOL CToolBar::Init()
{
        TBBUTTON tbb[3];
        TBADDBITMAP tbab;

        if (! Create() )
                return FALSE;

        //Add standard toolbar bitmaps
        tbab.hInst = HINST_COMMCTRL;
        tbab.nID = IDB_STD_SMALL_COLOR;
        SendMessage(m_hWnd, TB_ADDBITMAP, 0, (LPARAM)&tbab);

        //Add buttons
        ZeroMemory(tbb, sizeof(tbb));
        tbb[0].iBitmap = STD_CUT;
        tbb[0].idCommand = IDS_CUT;
        tbb[0].fsState = TBSTATE_ENABLED;
        tbb[0].fsStyle = TBSTYLE_BUTTON;

        tbb[1].iBitmap = STD_COPY;
        tbb[1].idCommand = IDS_COPY;
        tbb[1].fsState = TBSTATE_ENABLED;
        tbb[1].fsStyle = TBSTYLE_BUTTON;

        tbb[2].iBitmap = STD_PASTE;
        tbb[2].idCommand = IDS_PASTE;
        tbb[2].fsState = TBSTATE_ENABLED;
        tbb[2].fsStyle = TBSTYLE_BUTTON;

        SendMessage(m_hWnd, TB_ADDBUTTONS, (WPARAM) 3, (LPARAM) (LPTBBUTTON) &tbb);
        ShowWindow(m_hWnd, SW_NORMAL);
        return TRUE;
}

我用 SDI 窗口对其进行了测试,它运行良好,但是在我创建 MDICLIENT(客户端)窗口之后,它很糟糕。

请帮助我解决这个特殊问题。您可以在https://code.google.com/p/jcyangs-code/source/browse/trunk/com/lib/获得所有源代码

谢谢。

4

1 回答 1

0

处理 Frame Window 的 WM_SIZE 消息。

于 2012-06-20T01:26:55.247 回答