win32sdk 编程整理的些资料
#win32sdk编程积累经验# ## ListView ##
- 创建imagelist HIMAGELIST hi;
HBITMAP hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BMP_PC));
hi =ImageList_Create(,,ILC_COLOR32|ILC_MASK,,);
ImageList_AddMasked(hi,hBmp,RGB(,,)); - 创建 listveiw并设置风格 DWORD dwStyle =WS_BORDER|LVS_ALIGNTOP| LVS_REPORT | LVS_SINGLESEL |WS_VISIBLE |WS_CHILD |LVS_SHOWSELALWAYS;//LVS_OWNERDRAWFIXED hMAINHostList = CreateWindowEx(WS_EX_WINDOWEDGE, WC_LISTVIEW,NULL,dwStyle,,,,,hwnd,(HMENU)IDC_LISTVIEW_HOSTLIST,hInst,NULL); SetTheme(hMAINHostList, L"ListView", L"Explorer", NULL); ListView_SetExtendedListViewStyleEx(hMAINHostList,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT);
- 插入列 static WCHAR* wszArryHostListColNames[] = {L"col1",L"col2",...};
LV_COLUMN lvColumn;
lvColumn.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT ;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = ;
for (int i=;i < ;i++)
{
lvColumn.pszText = wszArryHostListColNames[i];
SendMessage(hMAINHostList,LVM_INSERTCOLUMN,(WPARAM)i,(LPARAM)&lvColumn);
}
// 设置imagelist
ListView_SetImageList(hMAINHostList,hi,LVSIL_STATE);
- 插入行,并设置item LVITEM lvItem={};
lvItem.mask = LVIF_TEXT |LVIF_PARAM |LVIF_STATE;
lvItem.iItem = ;
//lvItem.iSubItem = 0;
lvItem.lParam = (LPARAM)lparam;
lvItem.state = INDEXTOSTATEIMAGEMASK(); // 图标
lvItem.pszText = szText ; // col 0
row = ListView_InsertItem(hListView,&lvItem);
// SetItemData (mask = LVIF_PARAM ; lvItem.lParam = (LPARAM)lparam;)
ListView_SetItem(hM4sterHostList,&lvItem);
// col 1
ListView_SetItemText(hListView,row,,szText); - 消息事件 LRESULT OnNotify(HWND hwnd,int idfrm,NMHDR* pnmhdr)
{
if (idfrm == IDC_LISTVIEW_HOSTLIST )
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pnmhdr);
iHostListSelId = pNMItemActivate->iItem ; if ( pnmhdr->code == NM_RCLICK )
{ if (pNMItemActivate && pNMItemActivate->iItem >-)
{
POINT pt ={};
GetCursorPos(&pt);
HMENU hMenu = GetSubMenu(LoadMenu(hInst,MAKEINTRESOURCE(IDR_MENU_POP)),); TrackPopupMenu(hMenu,,pt.x,pt.y,,hwnd,NULL); } }else if (pnmhdr->code == NM_DBLCLK )
{ }
} return false;
}
- 其他 ## status bar ##
- 创建控件 static int iArryStatusBarParts[] = { ,};
// 1. crate bar
hMAINStatusBar = CreateStatusWindow(WS_BORDER|WS_CHILD|WS_VISIBLE|CCS_BOTTOM|CCS_ADJUSTABLE,L"",hwnd,IDC_STATUSBAR_MAIN);
// 2. set parts
SendMessage(hMAINStatusBar,SB_SETPARTS,sizeof(iArryStatusBarParts),(LPARAM)iArryStatusBarParts); //SendMessage(hMAINStatusBar,SB_SETICON,0,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON_RED16)));
// 3. set text and icon SendMessage(hMAINStatusBar,SB_SETTEXT,,(LPARAM)L"1970/01/01 00:00:00 ");
SendMessage(hMAINStatusBar,SB_SETTEXT,,(LPARAM)L" "); ## treeview ##
- 创建控件 // 创建 imaglist
HIMAGELIST hi;
hi =ImageList_Create(,,ILC_COLOR24|ILC_MASK,,);
int ret ;
HBITMAP hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BMP_INFO24));
ret =ImageList_AddMasked(hi,hBmp,RGB(,,));
// 添加图标
hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BMP_SHELL24));
ret =ImageList_AddMasked(hi,hBmp,RGB(,,));
hBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BMP_FILE24));
ret =ImageList_AddMasked(hi,hBmp,RGB(,,)); DWORD dwStryle = WS_VISIBLE | WS_CHILD | TVS_HASLINES|TVS_SHOWSELALWAYS/*|TVS_LINESATROOT*/;// remove root-line style
HWND hTree = CreateWindow(WC_TREEVIEW,L"Control Station tree",dwStryle,,,,,hParent,(HMENU)IDC_CS_TREE,hInst,NULL);
if (hTree)
{ TreeView_SetImageList(hTree,hi,TVSIL_NORMAL); WCHAR* lpwszTreeNames[] = {L"tree1",L"tree2",L"tree3"}; TVINSERTSTRUCT ti = {}; ti.item.mask=TVIF_TEXT|TCIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
ti.hParent=NULL;
ti.hInsertAfter=TVI_ROOT; for (int i=;i<;i++)
{
ti.item.lParam = i;
ti.item.iSelectedImage= ti.item.iImage=i; ti.item.pszText=lpwszTreeNames[i];
TreeView_InsertItem(hTree,&ti);
}
}
- 事件消息 LRESULT OnNotify(HWND hwnd,int idfrm,NMHDR* pnmhdr)
{ if (idfrm == IDC_CS_TREE)
{
if ( pnmhdr->code == TVN_SELCHANGED )
{
// 处理 } } return FALSE ;
} - 其他 // 获取treeveiw当前选中的节点
HTREEITEM hSelected ;
hSelected = TreeView_GetNextItem(hTree,hSelected,TVGN_CARET);
// 获取 treeview的item的 Text\lparam
WCHAR szText[max_path];
TVITEM tvi = {};
tvi.mask = TVIF_TEXT |TVIF_PARAM;// GetTreeItemText \ GetTreeItemData 都可以通过mask指定获取
tvi.pszText = szText;
tvi.cchTextMax = MAX_PATH;
tvi.hItem = hSelected;
TreeView_GetItem(hTree,&tvi); // treeview has childrens 判断是否有子节点(未测试)
TV_ITEM tvitem = {};
tvitem.mask = TVIF_CHILDREN;
tvitem.hItem = hSel ;
TreeView_GetItem(hDirTree,&tvitem);
if (tvitem.cChildren > )
{ } // 删除TREEVIEW的子节点
VOID RemoveTreeviewSubItems(HWND hTree, HTREEITEM hItem)
{
HTREEITEM hSubs = TreeView_GetChild(hTree,hItem);
HTREEITEM hSub= ; while (hSubs)
{
hSub = hSubs ;
hSubs = TreeView_GetNextSibling(hTree,hSubs);
TreeView_DeleteItem(hTree,hSub);
} } // 展开 Treeview节点
TreeView_Expand(lpcs->hDirTree,hTreeItem,TVE_EXPAND); - win32 Treeview 值得参看下 http://blog.csdn.net/c395565746c/article/details/5679357
- 加上[+] [-]图标 TVS_HASBUTTONS http://blog.csdn.net/lifu119/article/details/7024268 ## 托盘图标 ##
- 创建 // GUID gidTrayNotify = {0}; 这2个都是全局的
// static NOTIFYICONDATA nid; gidTrayNotify.Data1 = 0xabcd;
gidTrayNotify.Data2 = 0x1234;
gidTrayNotify.Data3 = 0x2345;
memset(gidTrayNotify.Data4,0xab,); hMAINTrayMenu = LoadMenu(hInst,MAKEINTRESOURCE(IDR_MENU_TRAY));
hMAINTrayMenu = GetSubMenu(hMAINTrayMenu,); nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hwnd ; nid.uID = IDC_TRAYNOTIFY ;
nid.uFlags = NIF_MESSAGE | NIF_ICON |NIF_TIP |NIF_INFO |NIF_GUID;
nid.guidItem = gidTrayNotify ;
nid.hBalloonIcon= nid.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_MAIN));
nid.uCallbackMessage = WMU_NOTIFY ;
static WCHAR lpwszNotifyTip[] = L"MAIN v1.0";
wcscpy_s(nid.szTip,lpwszNotifyTip);; nid.uTimeout = ;
nid.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON;
//nid.uVersion = NOTIFYICON_VERSION_4 ;
Shell_NotifyIcon(NIM_ADD,&nid);
- 修改状态 // 这里可以删减的 自行测试删减代码
// 弹气泡 或者 只修改tip信息,需要自行改动
nid.cbSize = sizeof(NOTIFYICONDATA); nid.uFlags = NIF_MESSAGE | NIF_ICON |NIF_TIP |NIF_INFO |NIF_GUID;
nid.guidItem = gidTrayNotify ;
nid.hBalloonIcon= nid.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_MAIN));
nid.uCallbackMessage = WMU_NOTIFY ;
wcscpy_s(nid.szInfoTitle,L"MAIN Msg ");
wcscpy_s(nid.szInfo,szBuffer);
static WCHAR lpwszNotifyTip[] = L"MAIN v1.0";
wcscpy_s(nid.szTip,lpwszNotifyTip);;
nid.uTimeout = ;
nid.dwInfoFlags = NIIF_USER | NIIF_LARGE_ICON; Shell_NotifyIcon(NIM_MODIFY,&nid); - 删除 nid.uFlags = NIF_GUID ;
nid.guidItem = gidTrayNotify ;
Shell_NotifyIcon(NIM_DELETE,&nid); - 消息事件 // 响应 自定义消息
case WMU_NOTIFY: // custom msg : traynotify
{
MAIN_OnTrayNotify(hWnd,lParam);
}
break; // 处理过程
void MAIN_OnTrayNotify(HWND hWnd, LPARAM lParam)
{
static POINT pos;
switch(lParam)
{
case WM_RBUTTONDOWN:
{
GetCursorPos(&pos);
SetForegroundWindow(hWnd);
TrackPopupMenu(hMAINTrayMenu,TPM_RIGHTBUTTON,pos.x,pos.y,,hWnd,NULL);
}
break;
case WM_LBUTTONDBLCLK:
{
ShowWindow(hWnd,SW_SHOW); }
break; }
} ## 创建dialog的几种姿势##
- CreateDialogParam 不模态,带参数创建diaglog; 在OnInitDialog 中lparam就是传入的参数
- CreateDialog 不模态
- DialogBox 模态
- 以上都存在漂浮于主窗口的缺点,不过够用了
- FILETIME SYSTEMTIME LOCALTIME BOOL FileTimeToSystemTime(
const FILETIME* lpFileTime,
LPSYSTEMTIME lpSystemTime);
FileTimeToSystemTime
LocalFileTimeToFileTime
FileTimeToLocalFileTime
## 封装的一些win32小函数 ##
以下函数很多没有测试,只是给出思路。以后用到在改进 - CheckMenuItemX 设置菜单item上的勾选:当开发中来表示某些功能已经开启,通过设置勾选来提示用户 void CheckMenuItemX(HMENU hMenu,UINT id, bool bCheck)
{
CheckMenuItem(hMenu,id,MF_BYCOMMAND | bCheck ? MF_CHECKED : MF_UNCHECKED);
} - LVSetItemData 给ListView项绑定上数据:在开发中我们给某项绑定上数据后,可以在选中此项后轻松获取此项的身份(data);以及自绘时,根据绑定上的数据绘制各个项。 void LVSetItemData(HWND hCtrl,int iItem,LPARAM lpData)
{
LVITEM lvit = {} ;
lvit.mask = LVIF_PARAM ;
lvit.iItem = iItem ;
lvit.lParam = (LPARAM)lpData ; ListView_SetItem(hCtrl,&lvit);
} - LVGetItemData 和 LVSetItemData 对应的作用 LPARAM LVGetItemData(HWND hctrl,int iItem)
{
LVITEM lvit = {} ;
lvit.mask = LVIF_PARAM ;
lvit.iItem = iItem ;
ListView_SetItem(hCtrl,&lvit);
return lvit.lParam ;
}
- listview 使用分组和缩进 //创建listview
HWND listview1 = CreateWindowEx(WS_EX_STATICEDGE, TEXT("SysListView32"), NULL, WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL, , , , , hwnd, (HMENU), (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
ListView_SetExtendedListViewStyle(listview1, LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES);//设置listview扩展风格
SendMessage(listview1, WM_SETFONT, (WPARAM)GetStockObject(), ); SetWindowTheme(listview1, L"Explorer", NULL);
SendMessage(listview1, LVM_ENABLEGROUPVIEW, TRUE, );//启用分组支持 RECT rcThis;
GetClientRect(hwnd,&rcThis);
MoveWindow(listview1,,,rcThis.right,rcThis.bottom,TRUE); LVGROUP group1;
group1.cbSize = LVGROUP_V5_SIZE;
group1.mask = LVGF_HEADER | LVGF_GROUPID;
group1.pszHeader = L"组1";
group1.iGroupId = ;
ListView_InsertGroup(listview1, -, &group1); group1.pszHeader = L"组2 - Hello World";
group1.iGroupId = ;
ListView_InsertGroup(listview1, -, &group1); //创建图片列表
HIMAGELIST imglist1 = ImageList_Create(, , ILC_COLOR32, , );
ImageList_AddIcon(imglist1, LoadIcon((HINSTANCE)GetWindowLongPtr(hwnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDI_ICON1)));
ImageList_AddIcon(imglist1, LoadIcon((HINSTANCE)GetWindowLongPtr(hwnd, GWL_HINSTANCE), MAKEINTRESOURCE(IDI_ICON2)));
HICON ico;
ExtractIconEx(L"C:\\Program Files\\Microsoft Visual Studio 14.0\\Common7\\Tools\\spyxx.exe", , &ico, NULL, );
ImageList_AddIcon(imglist1, ico);
ListView_SetImageList(listview1, imglist1, LVSIL_SMALL); LV_COLUMN list1;
LVITEM item1 ;
//内存清零
ZeroMemory(&list1, sizeof(LVCOLUMN));
ZeroMemory(&item1, sizeof(LVITEM)); //创建列
list1.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;//掩码
list1.fmt = LVCFMT_LEFT;//左对齐
list1.cx = ;//列宽
list1.pszText = L"列1";
SendMessage(listview1, LVM_INSERTCOLUMN, , (LPARAM)&list1);//创建列
list1.pszText = L"list2";
list1.cx = ;
SendMessage(listview1, LVM_INSERTCOLUMN, , (LPARAM)&list1);
list1.pszText = L"hello world";
SendMessage(listview1, LVM_INSERTCOLUMN, , (LPARAM)&list1);
list1.pszText = L"happy";
SendMessage(listview1, LVM_INSERTCOLUMN, , (LPARAM)&list1); //创建项目
item1.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_INDENT | LVIF_GROUPID;
item1.pszText = L"项目";
item1.iItem = ;//项目号
item1.iImage = ;//图片号
item1.iIndent = ;
item1.iGroupId = ;
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1);
item1.iItem = ;
item1.iImage = ;
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1);
item1.pszText = L"item 3";
item1.iItem = ;
item1.iImage = ;
item1.iIndent = ;//缩进一个图像单位
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1);
item1.pszText = L"第四个";
item1.iItem = ;
item1.iImage = ;
item1.iIndent = ;
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1); item1.iGroupId = ;
item1.pszText = L"我在组2内";
item1.iItem = ;
item1.iImage = ;
item1.iIndent = ;
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1);
item1.pszText = L"item 5";
item1.iItem = ;
item1.iImage = ;
item1.iIndent = ;
SendMessage(listview1, LVM_INSERTITEM, , (LPARAM)&item1); //创建子项目
item1.mask = LVIF_TEXT | LVIF_IMAGE;
item1.iItem = ;
item1.iSubItem = ;
item1.iImage = -;
item1.pszText = TEXT("子项目");
SendMessage(listview1, LVM_SETITEM, , (LPARAM)&item1);
item1.iItem = ;
item1.iSubItem = ;
item1.pszText = TEXT("子项目");
SendMessage(listview1, LVM_SETITEM, , (LPARAM)&item1);
item1.iItem = ;
item1.iSubItem = ;
item1.pszText = TEXT("子项目");
SendMessage(listview1, LVM_SETITEM, , (LPARAM)&item1); - 启用高版本的comctrl支持 #pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
win32sdk 编程整理的些资料的更多相关文章
- 【Windows】windows核心编程整理(下)
windows核心编程整理(上) windows核心编程整理(下) 线程的堆栈 每当创建一个线程时,系统就会为线程的堆栈(每个线程有他自己的堆栈)保留一个堆栈空间区域,并将一些物理存储器提交给这个以保 ...
- 【Windows】windows核心编程整理(上)
小续 这是我11年看<windows核心编程>时所作的一些笔记,现整理出来共享给大家 windows核心编程整理(上) windows核心编程整理(下) 线程的基础知识 进程是不活泼的,进 ...
- [整理]FPGA学习资料汇总
01.特权同学倾情奉献海量FPGA学习资料 http://pan.baidu.com/s/1pJIb32F
- 04---XML编程整理
一.XML概述 XML(eXtensible Markup Language),可扩展标记语言, 被设计的宗旨是传输数据,而非显示数据 W3C发布的,目前遵循1.0 ...
- GitHub上整理的一些资料(转)
技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddit:同上 MSDN:微软相关的官方技术集中地,主要是文档类 infoq:企业级应用,关注软件开发领域 ...
- GitHub上整理的一些资料
技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddit:同上 MSDN:微软相关的官方技术集中地,主要是文档类 infoq:企业级应用,关注软件开发领域 ...
- [osg]osgDB的加载机制,使用3DS插件做参考(转,整理现有osgDB资料)
参考:http://blog.sina.com.cn/s/blog_7cdaf8b60102uzu3.html http://blog.csdn.net/wang15061955806/article ...
- sqlserver整理的实用资料
1 --- 创建 备份数据的 device 2 3 USE DB_ZJ 4 EXEC sp_addumpdevice 'disk', 'testBack', 'c:\MyNwind_1.dat' 5 ...
- 整理的Python资料,包含各阶段所需网站、项目,收藏了
虽然强调过很多次了,但是还是要多提一句,不要看python2.x,如果你是零基础过来的,请直接开始你的py3.x 之路.建议3.6,3.7的一些特性可能对你不是很重要. 1.初出茅庐 我不会推荐你们去 ...
随机推荐
- svn使用svnsync实现双机热备
前提条件: 主:10.11.100.205从:10.11.100.50 源目录:http://10.11.100.205/svn/rep-ops目标目录:http://10.11.100.50/svn ...
- Java静态代码分析工具——FindBugs插件的安装与使用
1 什么是FindBugs FindBugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题.有了静态分析工具,就可以在不实际运行程序的情况对软件进行分 ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- .NET业务实体类验证组件Fluent Validation
认识Fluent Vaidation. 看到NopCommerce项目中用到这个组建是如此的简单,将数据验证从业务实体类中分离出来,真是一个天才的想法,后来才知道这个东西是一个开源的轻量级验证组建. ...
- iOS 顺传
ios 顺传一层的话,直接用属性 改变里面的值 顺传穿两到三层的话 使用KVO // 设置item - (void)setItem:(UITabBarItem *)item { _item = ite ...
- Error applying BeanValidation relational constraints 错误解决
来自http://blog.csdn.net/sivyer123/article/details/9185325 在hibernate.hbm.xml中加上 <property name=&qu ...
- 树形DP(统计直径的条数 HDU3534)
分析:首先树形dp(dfs计算出每个点为根节点的子树的最长距离和次长距离),然后找出L=dis[u][0]+dis[u][1]最长的那个点u,然后在以u为根节点dfs,统计长度为L的条数:具体做法:把 ...
- sdutoj 2604 Thrall’s Dream
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2604 Thrall’s Dream Time ...
- [原创]java WEB学习笔记60:Struts2学习之路--Actioin-声明式异常处理
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- [转]Java多线程干货系列—(一)Java多线程基础
Java多线程干货系列—(一)Java多线程基础 字数7618 阅读1875 评论21 喜欢86 前言 多线程并发编程是Java编程中重要的一块内容,也是面试重点覆盖区域,所以学好多线程并发编程对我们 ...