TBBUTTON has the following structure:
typedef struct _TBBUTTON {
int iBitmap;
int idCommand;
BYTE fsState;
BYTE fsStyle;
#ifdef _WIN64
BYTE bReserved[6]; // padding for alignment
#elif defined(_WIN32)
BYTE bReserved[2]; // padding for alignment
#endif
DWORD_PTR dwData;
INT_PTR iString;
} TBBUTTON, NEAR* PTBBUTTON, *LPTBBUTTON;
typedef const TBBUTTON *LPCTBBUTTON;
Now if you see, fsStyle
is a BYTE
(range 0-255); however, the values you can pass are:
#define TBSTYLE_TOOLTIPS 0x0100
#define TBSTYLE_WRAPABLE 0x0200
#define TBSTYLE_ALTDRAG 0x0400
#define TBSTYLE_FLAT 0x0800
#define TBSTYLE_LIST 0x1000
#define TBSTYLE_CUSTOMERASE 0x2000
#define TBSTYLE_REGISTERDROP 0x4000
#define TBSTYLE_TRANSPARENT 0x8000
None of these can fit into a BYTE
; and, quite correctly, the compiler gives a warning (warning C4305: '=': truncation from 'int' to 'BYTE'
) when using for example:
TBBUTTON button;
button.fsStyle = TBSTYLE_TOOLTIPS;
MSDN does not mention anything about this, so what am I missing here?
CodePudding user response:
The 'style flag' constants you have listed (TBSTYLE_TOOLTIPS
thru TBSTYLE_TRANSPARENT
) are window styles for a toolbar itself, not for any buttons it contains.
In the MSDN document you linked, the sentence, "A toolbar button can have a combination of the following styles.", comes after the list of those styles and refers to the list/box with the BTNS_AUTOSIZE
thru TBSTYLE_SEP
styles, which have values in the range 0x0000
thru 0x0080
– and these do fit in the fsStyle
(BYTE
) field of the TBBUTTON
structure.
Here's the section of the "CommCtrl.h" header that defines these:
#define BTNS_BUTTON TBSTYLE_BUTTON // 0x0000
#define BTNS_SEP TBSTYLE_SEP // 0x0001
#define BTNS_CHECK TBSTYLE_CHECK // 0x0002
#define BTNS_GROUP TBSTYLE_GROUP // 0x0004
#define BTNS_CHECKGROUP TBSTYLE_CHECKGROUP // (TBSTYLE_GROUP | TBSTYLE_CHECK)
#define BTNS_DROPDOWN TBSTYLE_DROPDOWN // 0x0008
#define BTNS_AUTOSIZE TBSTYLE_AUTOSIZE // 0x0010; automatically calculate the cx of the button
#define BTNS_NOPREFIX TBSTYLE_NOPREFIX // 0x0020; this button should not have accel prefix
#define BTNS_SHOWTEXT 0x0040 // ignored unless TBSTYLE_EX_MIXEDBUTTONS is set
#define BTNS_WHOLEDROPDOWN 0x0080 // draw drop-down arrow, but without split arrow section