- 公开视频 -> 链接点击跳转公开课程
- 博客首页 -> 链接点击跳转博客主页
目录
工具栏图标 - TBADDBITMAP - TB_ADDBITMAP
工具栏(ToolBar)
创建工具栏 - CreateWindowEx
初始工具栏 - TB_BUTTONSTRUCTSIZE
工具栏图标 - TBADDBITMAP - TB_ADDBITMAP
工具栏按钮 - TB_ADDBUTTONS
示例代码
case WM_INITDIALOG:
{
// 初始环境
INITCOMMONCONTROLSEX initComm = { 0 };
initComm.dwSize = sizeof(INITCOMMONCONTROLSEX);
initComm.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&initComm);
#define IDC_TOOLBAR 1111
#define IDC_FILENEW 1112
#define IDC_FILEOPEN 1113
#define IDC_FILESAVE 1114
// 工具栏创建
HWND hToolBar = CreateWindowEx(
NULL,
TOOLBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT,
0, 0, 0, 0,
hwnd,
(HMENU)IDC_TOOLBAR,
GetModuleHandle(NULL),
NULL
);
// 工具栏初始
SendMessage(hToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
// 工具栏图标
TBADDBITMAP tbad = { 0 };
tbad.hInst = HINST_COMMCTRL;
tbad.nID = IDB_STD_SMALL_COLOR;
SendMessage(hToolBar, TB_ADDBITMAP, 0, (LPARAM)&tbad);
// 工具栏按钮
TBBUTTON tbb[3] =
{
{STD_FILENEW, IDC_FILENEW , TBSTATE_ENABLED, TBSTYLE_BUTTON,},
{STD_FILEOPEN, IDC_FILEOPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON,},
{STD_FILESAVE, IDC_FILESAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON,}
};
// 工具栏添加
SendMessage(hToolBar, TB_ADDBUTTONS, 3, (LPARAM)&tbb);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_FILENEW:
{
OutputDebugString(L"IDC_FILENEW\r\n");
break;
}
case IDC_FILEOPEN:
{
OutputDebugString(L"IDC_FILEOPEN\r\n");
break;
}
case IDC_FILESAVE:
{
OutputDebugString(L"IDC_FILESAVE\r\n");
break;
}
}
break;
}
标签:case,工具栏,Windows,图形界面,FILENEW,FILEOPEN,TB,IDC
From: https://blog.csdn.net/2301_80612536/article/details/140560899