Post by BennettI've tried using your code, but I can't get a subToolbar to appear. I
think I'm confused as to the difference between mParentHandle and
mToolbarHandle. Also, are you using MFC or ATL?
I've been trying to use NM_CUSTOMDRAW as well, but I can't seem to get
that to work. I can capture the NM_CUSTOMDRAW message, but then my
buttons just don't seem to get drawn, even when I try to just do the
default behavior.
Have you had any more luck?
I had some luck, but I can still use some more. The toolbar renders
the button now, but the refreshing of the button doesn't work like it
should. It repaints without erasing it's backgroud, so the result is
that the highlighting causes blurriness in the toolbar icon. Because
it keeps painting over itself.
Also the highlighting is different than that of the other buttons. The
other buttons show a rounded highlighting rectangle, and the
subtoolbar button has sharp cornered highlighting.
I am not using ATL or MFC, just pure Win32 API calls.
The code looks like this now:
hWndParent is the parent window of the main toolbar
mToolbarHandle is the handle to the main toolbar
mSubToolbar is the handle to the second toolbar
RECT rc;
GetClientRect(hWndParent, &rc);
mToolbarHandle = CreateWindowEx
(
0,
TOOLBARCLASSNAME,
0,
WS_CHILDWINDOW
//| WS_CLIPSIBLINGS
//| WS_CLIPCHILDREN
| WS_TABSTOP
| TBSTYLE_FLAT
// Version 4.70. Creates a flat toolbar. In a flat toolbar, both the
toolbar and the buttons are
// transparent and hot-tracking is enabled. Button text appears under
button bitmaps. To prevent
// repainting problems, this style should be set before the toolbar
control becomes visible.
//| TBSTYLE_WRAPABLE
// Creates a toolbar that can have multiple lines of buttons. Toolbar
buttons can "wrap" to the next
// line when the toolbar becomes too narrow to include all buttons on
the same line. When the toolbar
// is wrapped, the break will occur on either the rightmost separator
or the rightmost button if there
// are no separators on the bar. This style must be set to display a
vertical toolbar control when the
// toolbar is part of a vertical rebar control. This style cannot be
combined with CCS_VERT.
| TBSTYLE_TRANSPARENT
// Version 4.71. Creates a transparent toolbar. In a transparent
toolbar, the toolbar is transparent
// but the buttons are not. Button text appears under button bitmaps.
To prevent repainting problems,
// this style should be set before the toolbar control becomes
visible.
| TBSTYLE_LIST
// Version 4.70. Creates a flat toolbar with button text to the right
of the bitmap. Otherwise, this
// style is identical to TBSTYLE_FLAT. To prevent repainting problems,
this style should be set before
// the toolbar control becomes visible.
// | TBSTYLE_CUSTOMERASE
// Version 4.70. Generates NM_CUSTOMDRAW notification messages when
the toolbar processes
// WM_ERASEBKGND messages.
| TBSTYLE_TOOLTIPS
// Creates a ToolTip control that an application can use to display
descriptive text for the buttons
// in the toolbar.
| CCS_NODIVIDER
// Prevents a two-pixel highlight from being drawn at the top of the
control.
| CCS_NOPARENTALIGN
// Prevents the control from automatically moving to the top or bottom
of the parent window. Instead,
// the control keeps its position within the parent window despite
changes to the size of the parent.
// If CCS_TOP or CCS_BOTTOM is also used, the height is adjusted to
the default, but the position and
// width remain unchanged.
| CCS_NORESIZE
// Prevents the control from using the default width and height when
setting its initial size or a
// new size. Instead, the control uses the width and height specified
in the request for creation or
// sizing.
| CCS_TOP
// Causes the control to position itself at the top of the parent
window's client area and sets the
// width to be the same as the parent window's width. Toolbars have
this style by default.
// | CCS_ADJUSTABLE
// Enables a toolbar's built-in customization features, which let the
user to drag a button to a new
// position or to remove a button by dragging it off the toolbar. In
addition, the user can
// double-click the toolbar to display the Customize Toolbar dialog
box, which enables the user to
// add, delete, and rearrange toolbar buttons.
// | CCS_BOTTOM
// Causes the control to position itself at the bottom of the parent
window's client area and sets the
// width to be the same as the parent window's width. Status windows
have this style by default.
// | CCS_LEFT
// Version 4.70. Causes the control to be displayed vertically on the
left side of the parent window.
| CCS_NODIVIDER
// Prevents a two-pixel highlight from being drawn at the top of the
control.
// | CCS_NOMOVEX
// Version 4.70. Causes the control to resize and move itself
vertically, but not horizontally, in
// response to a WM_SIZE message. If CCS_NORESIZE is used, this style
does not apply.
// | CCS_NOMOVEY
// Causes the control to resize and move itself horizontally, but not
vertically, in response to a
// WM_SIZE message. If CCS_NORESIZE is used, this style does not
apply. Header windows have this style
// by default.
| CCS_NORESIZE
// Prevents the control from using the default width and height when
setting its initial size or a new
// size. Instead, the control uses the width and height specified in
the request for creation or
// sizing.
// | CCS_RIGHT
// Version 4.70. Causes the control to be displayed vertically on the
right side of the parent window.
// | CCS_TOP
// Causes the control to position itself at the top of the parent
window's client area and sets the
// width to be the same as the parent window's width. Toolbars have
this style by default.
// | CCS_VERT
// Version 4.70. Causes the control to be displayed vertically.
,rc.left,rc.top,rc.right-rc.left,cIconHeight,
hWndParent,
(HMENU)(INT_PTR)eToolbarPane_Toolbar,
mModuleHandle,
0
);
mSubToolbar = CreateWindowEx
(
0,
TOOLBARCLASSNAME,
NULL,
0
| WS_CHILD
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
| WS_VISIBLE
| TBSTYLE_FLAT
| TBSTYLE_TRANSPARENT
| CCS_NODIVIDER
| CCS_NOPARENTALIGN
| CCS_NORESIZE
| CCS_TOP
| TBSTYLE_TOOLTIPS
| TBSTYLE_LIST
| WS_TABSTOP
,
0,0,100,24, // give some extra width and height
mToolbarHandle, // original toolbar
(HMENU)(INT_PTR)inId,
mModuleHandle,
NULL
);
SendMessage(mSubToolbar , TB_BUTTONSTRUCTSIZE, (WPARAM)
sizeof(TBBUTTON), 0);
// Create the image list, himlHot.
HIMAGELIST hImageList = ImageList_Create
(
80,
16,
ILC_COLOR32,
10,
10
);
CGdiPlusBitmapResource theBmpRes
(
MAKEINTRESOURCE(inIconResourceId),
RT_RCDATA,
mModuleHandle
);
HICON theIcon;
theBmpRes.m_pBitmap->GetHICON(&theIcon);
ImageList_AddIcon(hImageList, theIcon);
DeleteObject(theIcon);
TBBUTTON theToolbarButton;
theToolbarButton.iBitmap = (int)0;
theToolbarButton.idCommand = inCommandId;
theToolbarButton.fsState = TBSTATE_ENABLED;
theToolbarButton.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE;
theToolbarButton.dwData = 0;
theToolbarButton.iString = (INT_PTR)TEXT("");
SendMessage(mSubToolbar , TB_SETIMAGELIST, 0, (LPARAM)hImageList);
SendMessage(mSubToolbar , TB_ADDBUTTONS, (WPARAM)1, (LPARAM)
(LPTBBUTTON) &theToolbarButton);
SendMessage(mSubToolbar , TB_AUTOSIZE, 0, 0);
SendMessage((HWND)mSubToolbar , (UINT) TB_SETEXTENDEDSTYLE, (WPARAM)0,
(LPARAM) TBSTYLE_EX_DRAWDDARROWS);
//ShowWindow(mSubToolbar , SW_SHOW);
I hope this helps, don't hesitate to ask for clarification if needed.
I'll also have a look at NM_CUSTOMDRAW and I'll keep you updated if I
make any progress...