I am creating a toolbar with the TBSTYLE_EX_DRAWDDARROWS style so that I can use a drop down button.
I have a function AddButtonToToolbar() that adds a dropdown button to the toolbar.
void AddButtonToToolbar(HWND hToolbar, int bitmapId){
int btnIndex;
TBADDBITMAP tbab;
TBBUTTON tbButton;
tbab.hInst = NULL;
tbab.nID = (UINT_PTR)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(bitmapId),
IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE | LR_DEFAULTCOLOR | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
btnIndex = (int)SendMessage(hToolbar, TB_ADDBITMAP, 8, (LPARAM)&tbab);
tbButton.iBitmap = btnIndex;
tbButton.idCommand = bitmapId;
tbButton.fsState = TBSTATE_ENABLED;
tbButton.fsStyle = BTNS_DROPDOWN;
tbButton.dwData = 0L;
tbButton.iString = (INT_PTR) ""; //Set empty string to prevent toolbar from expanding!
// Add the button to the end of the toolbar
SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbButton);
//Ensures toolbar recalculates its size based on its content
SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
}
If, after creating the toolbar, I do not include the statements:
DWORD exstyle = (int)SendMessage(hwndToolbar, TB_GETEXTENDEDSTYLE,0,0);
SendMessage(hwndToolbar, TB_SETEXTENDEDSTYLE, 0, exstyle | TBSTYLE_EX_DRAWDDARROWS);
then when I call the function AddButtonToToolbar(...) the drop down arrow is not shown although the button is displayed.
1. As I included the TBSTYLE_EX_DRAWDDARROWS style when I created the toolbar, why do I need to include these two lines of code?
2. If I change the button style to BTNS_WHOLEDROPDOWN in the function AddButtonToToolbar() then all the buttons become more widely spaced out. How can I prevent this from happening?