Toolbar button stays pressed (win32)

Jul 1, 2015 at 1:57pm
When I click and drag a toolbar button it stays pressed when it should be unpressed when I release the mouse. How do I fix this?
Last edited on Jul 1, 2015 at 8:43pm
Jul 2, 2015 at 2:01pm
probably you are losing some windows messages. Show some code.
Jul 2, 2015 at 9:23pm
Here is the code to create the toolbar and add buttons. Window procedure is only handling WM_DESTROY.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
HWND CreateToolbar(BOOL flat, HWND parent)
{
	DWORD styles = WS_VISIBLE | CCS_NODIVIDER | CCS_NOPARENTALIGN | TBSTYLE_TOOLTIPS | TBSTYLE_WRAPABLE | WS_CHILD;

	if (flat)
		styles |= TBSTYLE_FLAT | TBSTYLE_TRANSPARENT;

        HWND hwnd = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, styles, 
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		parent, NULL, GetModuleHandle(NULL), NULL);

	SendMessage(hwnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DOUBLEBUFFER | TBSTYLE_EX_DRAWDDARROWS);
	SendMessage(hwnd, TB_SETMAXTEXTROWS, 0, 0);
        SendMessage(hwnd, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

	return hwnd;
}

1
2
3
4
5
6
7
VOID InsertButton(HWND toolbar, INT idcmd, INT image, BOOL dropdown, LPCWSTR tooltip)
{
    TBBUTTON btn = { image, idcmd, TBSTATE_ENABLED, (idcmd < 0? BTNS_SEP: BTNS_BUTTON | (dropdown? BTNS_DROPDOWN: 0)), {0}, 0, (INT_PTR)tooltip };

    SendMessage(toolbar, TB_ADDBUTTONS, (WPARAM)1, (LPARAM)&btn);
    SendMessage(toolbar, TB_AUTOSIZE, 0, 0); 
}
Last edited on Jul 2, 2015 at 9:29pm
Jul 4, 2015 at 10:26am
Has anyone here ever made a toolbar in win32? Because this seems to be their default behavior. i've known about this thing for a long time but ignored it. It's easy to reproduce but not likely that anyone will accidentally: right-click and then left-click a toolbar button, drag outside of the button then release both mouse buttons and the toolbar button remains pressed. You have to click the button again to have it unpressed. It happens with or without visual styles.
Last edited on Jul 4, 2015 at 10:27am
Jul 6, 2015 at 1:48pm
Nobody huh? This is so annoying because other windows applications like wordpad don't have this bug so either i'm doing something wrong or there is something i'm missing.
Topic archived. No new replies allowed.