文档详情

如何操作桌面上的图标.doc

发布:2017-12-12约8.37千字共13页下载文档
文本预览下载声明
如何操作桌面上的图标,并取得图标的信息 2012 年 2 月 19 日 | Filed under: Windows程序设计 and tagged with: Windows API桌面图标是放在 SysListView32这个列表中,所以要想操作图标,要先得到了它的句柄,然后可以遍历它得到各桌面图标的句柄,下面的代码实现把桌面上的图标排成一个圆: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 voidC***::OnSetDeskIcon() { HWNDhwndParent = ::FindWindow(Progman,Program Manager); HWNDhwndSHELLDLL_DefView = ::FindWindowEx( hwndParent, NULL,SHELLDLL_DefView, NULL ); HWNDhwndSysListView32 = ::FindWindowEx( hwndSHELLDLL_DefView, NULL,SysListView32,FolderView); intNm = ListView_GetItemCount( hwndSysListView32 ); //取得图标的数目 for(inti = 0; i Nm; i++ ) { intx = 400 + 150*cos( i * 2 * 3.1415926/Nm ); inty = 400 + 150*sin( i * 2 * 3.1415926/Nm ); ::SendMessage( hwndSysListView32, LVM_SETITEMPOSITION, i, MAKELPARAM( x,y)); } ListView_RedrawItems(hwndSysListView32, 0, ListView_GetItemCount(hwndSysListView32) - 1); ::UpdateWindow(hwndSysListView32); } 操作了图标,那么怎样得到图标的信息呢,如图标的名称,大小,位置等等,在上一篇文章Stealing Programs Memory中提到了怎样取得别的进程中的信息,下面的代码实现了取得图标名称、位置、大小的功能: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 voidC***::OnSetDeskIcon() { HWNDhDestTop; hDestTop = ::FindWindow(progman, NULL); hDestTop = ::FindWindowEx(hDestTop, 0,shelldll_defview, NULL); hDestTop = ::FindWindowEx(hDestTop, 0,syslistview32, NULL); intcount=(int)::SendMessage( hDestTop, LVM_GETITEMCOUNT, 0, 0); LVITEM lvi, *_lvi; charitem[512], subitem[512]; char*_item, *_subitem; unsignedlongpid; HANDLEprocess; GetWindowThreadProcessId( hDestTop, pid); process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ |PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid); _lvi=(LVITEM*)Virtual
显示全部
相似文档