Win32 SDK的Toolbar使用标准位图
来源:互联网 发布:linq实战源码 编辑:程序博客网 时间:2024/05/29 15:13
最终效果如图所示:
1.定义CreateSimpleToolbar方法:
//新建工具栏HWND CreateSimpleToolbar(HWND hwndParent){HWND hwndToolbar;//工具栏上按钮的数目const int BUTTONNUMS = 2;//按钮TBBUTTON tbb[2];ZeroMemory(tbb, sizeof(tbb));tbb[0].iBitmap = STD_FILENEW;tbb[0].fsState = TBSTATE_ENABLED;tbb[0].fsStyle = TBSTYLE_BUTTON;tbb[1].iBitmap = STD_REDOW;tbb[1].fsState = TBSTATE_ENABLED;tbb[1].fsStyle = TBSTYLE_BUTTON;//位图,commctl中的标准位图TBADDBITMAP tbBitmap1;tbBitmap1.hInst = HINST_COMMCTRL;tbBitmap1.nID = IDB_STD_SMALL_COLOR;RECT windowRect;GetWindowRect(hwndParent,&windowRect);hwndToolbar = CreateWindowEx(0L,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,0,0,0,0,hwndParent,(HMENU)ID_TOOLBAR,hInst,NULL);//将位图添加到工具栏SendMessage(hwndToolbar,TB_ADDBITMAP,0,(LPARAM)&tbBitmap1);//计算工具栏大小SendMessage(hwndToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);//添加按钮到工具栏SendMessage(hwndToolbar,TB_ADDBUTTONS,(WPARAM)BUTTONNUMS,(LPARAM)&tbb);return hwndToolbar;}
2.在WndProc窗口过程中,处理WM_CREATE,即窗口新建时即调用生成工具栏的方法:
switch (message)
{
case WM_CREATE:
CreateSimpleToolbar(hWnd);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
附上MSDN对于标准位图的说明:
This section specifies index values of images within standard bitmaps.
Index values for IDB_HIST_LARGE_COLOR and IDB_HIST_SMALL_COLOR:
- HIST_ADDTOFAVORITES
Add to favorites.
- HIST_BACK
Move back.
- HIST_FAVORITES
Open favorites folder.
- HIST_FORWARD
Move forward.
- HIST_VIEWTREE
View tree.
Index values for IDB_STD_LARGE_COLOR and IDB_STD_SMALL_COLOR:
- STD_COPY
Copy operation.
- STD_CUT
Cut operation.
- STD_DELETE
Delete operation.
- STD_FILENEW
New file operation.
- STD_FILEOPEN
Open file operation.
- STD_FILESAVE
Save file operation.
- STD_FIND
Find operation.
- STD_HELP
Help operation.
- STD_PASTE
Paste operation.
- STD_PRINT
Print operation.
- STD_PRINTPRE
Print preview operation.
- STD_PROPERTIES
Properties operation.
- STD_REDOW
Redo operation.
- STD_REPLACE
Replace operation.
- STD_UNDO
Undo operation.
Index values for IDB_VIEW_LARGE_COLOR and IDB_VIEW_SMALL_COLOR:
- VIEW_DETAILS
Details view.
- VIEW_LARGEICONS
Large icons view.
- VIEW_LIST
List view.
- VIEW_NETCONNECT
Connect to network drive.
- VIEW_NETDISCONNECT
Disconnect from network drive.
- VIEW_NEWFOLDER
New folder.
- VIEW_PARENTFOLDER
Go to parent folder.
- VIEW_SMALLICONS
Small icon view.
- VIEW_SORTDATE
Sort by date.
- VIEW_SORTNAME
Sort by name.
- VIEW_SORTSIZE
Sort by size.
- VIEW_SORTTYPE
Sort by type.
Remarks
You use these values to specify an image index within a standard image list that was loaded with theTB_LOADIMAGES message. The index values correspond to images within the standard bitmaps used by common controls.
The following tables list the constants by value so that they can be mapped to the icons in the bitmaps.
IDB_HIST_LARGE_COLOR and IDB_HIST_SMALL_COLOR:
Standard images
Standard images
IDB_STD_LARGE_COLOR and IDB_STD_SMALL_COLOR:
Standard images
Standard images
IDB_VIEW_LARGE_COLOR and IDB_VIEW_SMALL_COLOR:
Standard images
Standard images
如果要使用自己的位图,则需要改写一下CreateSimpleToolbar方法:
//创建工具栏HWND CreateSimpleToolbar(HWND parentHwnd){const int ImageListID = 0;const int ImageButtonNums = 2;const int bitmapSize = 40;const DWORD buttonStyle = BTNS_BUTTON;toolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,0,0,0,0,parentHwnd,NULL,hInst,NULL);g_imagelist = ImageList_Create(bitmapSize,bitmapSize, ILC_COLOR24,ImageButtonNums,0);//加载自己的位图int iBitmap = ImageList_Add(g_imagelist,LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1)),NULL);SendMessage(toolbar,TB_SETIMAGELIST,(WPARAM)ImageListID,(LPARAM)g_imagelist);TBBUTTON tbButtons[ImageButtonNums];tbButtons[0].iBitmap = MAKELONG(iBitmap,ImageListID);tbButtons[0].fsState = TBSTATE_ENABLED;tbButtons[0].fsStyle = buttonStyle;tbButtons[1].iBitmap = MAKELONG(iBitmap+1,ImageListID);tbButtons[1].fsState = TBSTATE_ENABLED;tbButtons[1].fsStyle = buttonStyle;tbButtons[0].iString = 0;tbButtons[1].iString = 0;//添加按钮SendMessage(toolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);SendMessage(toolbar,TB_ADDBUTTONS,(WPARAM)ImageButtonNums,(LPARAM)&tbButtons);//调整工具栏大小,并展示它SendMessage(toolbar,TB_AUTOSIZE,0,0);ShowWindow(toolbar,TRUE);return toolbar;}
同时,需要在WM_PAINT中调用:SendMessage(toolbar,TB_AUTOSIZE,0,0);使得窗口改变时工具栏大小依旧可以自适应。
使用自己定义的图片,效果如下图所示:
- Win32 SDK的Toolbar使用标准位图
- WIN32汇编语言中位图的使用
- win32 sdk 显示位图简单示例
- Win32学习笔记——位图的使用
- ToolBar的Button上使用ToolTip的方法(SDK)
- ToolBar的Button上使用ToolTip的方法(SDK)
- C#读取Win32标准DLL文件中的Bitmap(位图)
- Win32位图
- win32 SDK开发中打开 保存文件对话框的使用
- Linux下面编译生成win32能够使用的sdk
- win32 sdk中ListView列表控件的使用
- win32强化练习4.5_标准工具栏的使用
- 使用Win32/MFC实现Splash窗口(含有alpha通道的位图窗口)
- 【win32】day08-位图的使用/坐标系和映射模式/文字和字体/对话框
- toolbar加载位图
- 一个标准的win32窗口
- Android开发百度SDK的使用--定位图层的使用
- ToolBar控件的使用
- mysql存储过程和函数使用
- Linux内核学习四库全书
- 黑马程序员---Java语言基础3
- hdu 2874 Connections between cities(最近公共祖先(LCA))
- 调用实现的方法
- Win32 SDK的Toolbar使用标准位图
- SwitchHosts工具浅析
- CSS基础详解3
- C/C++ sort函数的用法
- C++ 基本类型
- android:layout_weight详解
- 五个最佳RSS新闻阅读器
- C语言经典著作导读
- shell Bash使用技巧