以前写过使用Au3排列桌面图标的代码,感觉蛮有意思的。今天逛论坛的时候一不小心看到了一个C/C++操作桌面图标的代码,原理逻辑都是一样的,获得桌面SysListView32的句柄,利用该句柄对控件上的图标进行坐标的调整。排列后的效果及代码如下:
- #include <Windows.h>
- #include <commctrl.h>
- #include <cmath>
- void OnSetDeskIcon();
- int APIENTRY WinMain(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow
- )
- {
- OnSetDeskIcon();
- }
- void OnSetDeskIcon()
- {
- HWND hwndParent = ::FindWindow( "Progman", "Program Manager" );
- HWND hwndSHELLDLL_DefView = ::FindWindowEx( hwndParent, NULL, "SHELLDLL_DefView", NULL );
- HWND hwndSysListView32 = ::FindWindowEx( hwndSHELLDLL_DefView, NULL, "SysListView32", "FolderView" );
- int Nm = ListView_GetItemCount( hwndSysListView32 );
- int sNm = 0;
- if( Nm >= 10 )
- {
- sNm = 10;
- }else{
- sNm = Nm;
- }
- for( int i = 0; i < sNm; i++ )
- {
- int x = 400 + 150*cos( i*36*3.1415926/180 );
- int y = 400 + 150*sin( i*36*3.1415926/180 );
- ::SendMessage( hwndSysListView32, LVM_SETITEMPOSITION, i, MAKELPARAM( x,y));
- }
- ListView_RedrawItems(hwndSysListView32, 0, ListView_GetItemCount(hwndSysListView32) - 1);
- ::UpdateWindow(hwndSysListView32);
- }
复制代码
转自邓佳的博客 |
|