C language > Beginner questions

Toolbar dropdown buttons

(1/3) > >>

CFred:
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.


--- Code: ---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);
}
--- End code ---

If, after creating the toolbar, I do not include the statements:


--- Code: --- DWORD exstyle = (int)SendMessage(hwndToolbar, TB_GETEXTENDEDSTYLE,0,0);
SendMessage(hwndToolbar, TB_SETEXTENDEDSTYLE, 0, exstyle | TBSTYLE_EX_DRAWDDARROWS);

--- End code ---
   

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?

John Z:

--- Quote from: CFred on July 20, 2023, 12:34:40 PM ---
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?

--- End quote ---

Since I don't see the code you used to create the toolbar I assume you used the control resource editor in Pelles C to add a toolbar control?  I think the resource control method does not support extended styles, even if you edit the resource file as text.  So the message must be sent directly, in my experience.


--- Quote from: CFred on July 20, 2023, 12:34:40 PM ---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?

--- End quote ---
Don't use it  :D :)  (well true, but otherwise I don't know)

[Not getting exactly what you want is often the result of using higher level abstractions, ultimately you can only get whatever control features (for example) that the developer thought were important, or thought of at all.The higher the abstraction the less work you have but also less uniqueness, less ability to make it look/work how you want and not the originator wanted it to look/work. ]

John Z

CFred:
@John Z: I used the following code to create the toolbar instead of the resource editor:


--- Code: --- hwndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT | TBSTYLE_EX_DRAWDDARROWS, 0, 0, 0, 0,
        hparent, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
--- End code ---

This was shown in the file attached to the first post in this thread.

frankie:

--- Quote from: CFred on July 20, 2023, 12:34:40 PM ---If, after creating the toolbar, I do not include the statements:


--- Code: --- DWORD exstyle = (int)SendMessage(hwndToolbar, TB_GETEXTENDEDSTYLE,0,0);
SendMessage(hwndToolbar, TB_SETEXTENDEDSTYLE, 0, exstyle | TBSTYLE_EX_DRAWDDARROWS);

--- End code ---
   

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?

--- End quote ---
Because you don't have to use TBSTYLE_EX_DRAWDDARROWS in CreateWindowEx().
TBSTYLE_EX_DRAWDDARROWS is an extended control style, not an extended window style.
In your code nothing bad happens because no window style is defined with same numerical value of TBSTYLE_EX_DRAWDDARROWS. If case of conflict you should see an undesired style of the window.
WINAPI include the 2 messages TB_GETEXTENDEDSTYLE and TB_SETEXTENDEDSTYLE to allow settings of toolbar extended styles, that could be set per each button in the toolbar.
In a CreateWindowEx() call, you are allowed to set only control ordinarily styles, not extended ones.


--- Quote from: CFred on July 20, 2023, 12:34:40 PM ---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?

--- End quote ---
Not clear what you mean.
All buttons get the associated drop-down arrow that enlarge the button, exactly as the TBSTYLE_EX_DRAWDDARROWS does.


--- Quote from: MS ---BTNS_WHOLEDROPDOWN
Version 5.80. Specifies that the button will have a drop-down arrow, but not as a separate section. Buttons with this style behave the same, regardless of whether the TBSTYLE_EX_DRAWDDARROWS extended style is set.
--- End quote ---

CFred:
@frankie:

Thanks for explaining that I don't have to use TBSTYLE_EX_DRAWDDARROWS in CreateWindowEx(). It's difficult to find this sort of information easily.


--- Quote ---Quote from: CFred on Yesterday at 12:34:40 PM

    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?

Not clear what you mean.
--- End quote ---

What I meant is that the toolbar buttons are normally spaced a reasonable distance apart when they have the normal style applied to them. But when I use the style BTNS_WHOLEDROPDOWN for one dropdown button  all the buttons have a much larger space between them.

Navigation

[0] Message Index

[#] Next page

Go to full version