使用Win32 API添加工具栏Dialogbox

时间:2009-12-24 12:33:10

标签: winapi toolbar dialog

我有一个对话框,在其上使用资源编辑器添加控件。但我正在尝试在WM_INITGDIALOG消息中动态创建工具栏,但工具栏不可见。还有别的事可以让它可见(我不这么认为,但......)。如果无法做到这一点,如何在资源编辑器中添加工具栏。

正如您猜测我使用的是VS 2008。

CreateButtons(HWND hwnd)
{
    HIMAGELIST m_hTBImageList;
    HIMAGELIST m_hTBHottrack;



    HWND hwndSysButtonTB = CreateWindowEx(0,
        TOOLBARCLASSNAME, 
        _T(""), 
        WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NORESIZE | CCS_NOPARENTALIGN,
        toolbarRect.left, toolbarRect.top, toolbarRect.right-toolbarRect.left, toolbarRect.bottom-toolbarRect.top, 
        hwnd,
        (HMENU)IDR_TOOLBAR, 
        (HINSTANCE)hAppInstance, 
        NULL);

    m_hTBImageList = ImageList_LoadImage((HINSTANCE)hAppInstance, 
        MAKEINTRESOURCE(IDB_BITMAP_ICONS), toolbarButtonSize.cx, 1, 
        0, IMAGE_BITMAP, LR_CREATEDIBSECTION|LR_SHARED);
    m_hTBHottrack  = ImageList_LoadImage((HINSTANCE)hAppInstance, 
        MAKEINTRESOURCE(IDB_MOUSEOVER), toolbarButtonSize.cx, 1, 
        0, IMAGE_BITMAP, LR_CREATEDIBSECTION|LR_SHARED);

    SendMessage(hwndSysButtonTB, (UINT) TB_SETIMAGELIST, 0, (LPARAM)m_hTBImageList);
    SendMessage(hwndSysButtonTB, (UINT) TB_SETHOTIMAGELIST, 0, (LPARAM)m_hTBHottrack);
    SendMessage(hwndSysButtonTB, (UINT) TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

    // win2k: set color of hot tracking frame
    COLORSCHEME scheme;
    scheme.dwSize = sizeof(scheme);
    scheme.clrBtnHighlight = RGB(175,175,175);
    scheme.clrBtnShadow = RGB(175,175,175);
    SendMessage(hwndSysButtonTB, (UINT) TB_SETCOLORSCHEME, 0, (LPARAM)&scheme);

    TBBUTTON ButtonEnd =            {0,ID_BUTTON_END,TBSTATE_ENABLED,TBSTYLE_BUTTON};
    TBBUTTON ButtonRefresh =        {1,ID_BUTTON_REFRESH,TBSTATE_ENABLED,TBSTYLE_BUTTON};
    TBBUTTON ButtonOptions =        {2,ID_BUTTON_PROPERTIES,TBSTATE_ENABLED,TBSTYLE_BUTTON};



    SendMessage(hwndSysButtonTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonEnd);
    SendMessage(hwndSysButtonTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonRefresh);
    SendMessage(hwndSysButtonTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonOptions);

} 

1 个答案:

答案 0 :(得分:0)

你必须致电

SendMessage(hwndSysButtonTB, TB_AUTOSIZE, 0, 0); 
ShowWindow(hwndSysButtonTB , SW_SHOW); 

在你的功能结束时。

我认为你应该使用TBBUTTON数组而不是三个独立的变量。然后你可以用

一次性添加它们
SendMessage(hwndSysButtonTB, (UINT) TB_ADDBUTTONS, 3, (LPARAM)&ButtonArray);