views:

203

answers:

1

Hi;

I have a dialog box on which controls are added with resource editor. But I am trying to create a toolbar on the fly in WM_INITGDIALOG message but the toolbar is not visible. Is there something else to do make it visible(I dont think so but...). If this is not possible how can add a toolbar in resource editor.

As you guessed I use 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);

}
A: 

You have to call

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

at the end of your function.

And I think you should use an TBBUTTON array instead of three separate variables. Then you can add them all at once with

SendMessage(hwndSysButtonTB, (UINT) TB_ADDBUTTONS, 3, (LPARAM)&ButtonArray);
Stefan
Thanks, it worked now
whoi