灰色背景工具栏 C++
我正在尝试使用 Win32 API(无 MFC 或 VC++)在 C++ 中创建工具栏。我能够创建一个如下所示的工具栏,没有背景,只有基本的窗口颜色。
我希望它看起来像下面的图片,带有光泽条和灰色渐变
当我遇到未定义的错误时,我尝试使用 TBSTYLE_FLAT
,我将其声明为等于0x0800
仍然没有任何区别。我需要添加更多属性吗?我将在下面粘贴我的代码。
HWND hTbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)12, GetModuleHandle(NULL), NULL);
SendMessage(hTbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
TBBUTTON tb[5];
TBADDBITMAP tBmp;
tBmp.hInst = HINST_COMMCTRL;
tBmp.nID = IDB_STD_SMALL_COLOR;
SendMessage(hTbar, TB_ADDBITMAP, 0, (LPARAM)&tBmp);
ZeroMemory(tb, sizeof(tb));
tb[0].iBitmap = STD_FILEOPEN;
tb[0].fsState = TBSTATE_ENABLED;
tb[0].fsStyle = TBSTYLE_BUTTON;
SendMessage(hTbar, TB_ADDBUTTONS, sizeof(tb)/sizeof(TBBUTTON), (LPARAM)&tb);
我使用的是 Windows 7 和 Win32 C++ API。谢谢。
I am trying to create a toolbar in C++ using Win32 API (no MFC or VC++). I am able to create a toolbar which looks like this and has no background, just the basic window color.
I would like it to look like picture below with the glossy bar and a grey gradiant
I have tried using TBSTYLE_FLAT
when I got an undefined error, I declared it as equal to 0x0800
which still did not make any difference. Do I need to add more properties? I will paste my code below.
HWND hTbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU)12, GetModuleHandle(NULL), NULL);
SendMessage(hTbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
TBBUTTON tb[5];
TBADDBITMAP tBmp;
tBmp.hInst = HINST_COMMCTRL;
tBmp.nID = IDB_STD_SMALL_COLOR;
SendMessage(hTbar, TB_ADDBITMAP, 0, (LPARAM)&tBmp);
ZeroMemory(tb, sizeof(tb));
tb[0].iBitmap = STD_FILEOPEN;
tb[0].fsState = TBSTATE_ENABLED;
tb[0].fsStyle = TBSTYLE_BUTTON;
SendMessage(hTbar, TB_ADDBUTTONS, sizeof(tb)/sizeof(TBBUTTON), (LPARAM)&tb);
I am using Windows 7 and the Win32 C++ API. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
背景可能来自父窗口。要免费获得视觉样式背景渐变效果,请将工具栏放入 rebar 并使用 TBSTYLE_FLAT 和 TBSTYLE_TRANSPARENT 工具栏样式。
The background probably comes from the parent window. To get the visual style background gradient effect for free, put your toolbar inside a rebar and use the TBSTYLE_FLAT and TBSTYLE_TRANSPARENT toolbar styles.