码迷,mamicode.com
首页 > 其他好文 > 详细

如何得到桌面窗口的句柄(桌面图标)

时间:2015-06-29 10:07:13      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

包含图标的窗口实际上是DesktopWindow的一个子窗口。确切地讲,Desktop Window包含一个无标题的、类名为“SHELLDLL_DefView”的子窗口,这个
窗口又包含一个无标题的、类名为“SysListView32”的子窗口——这才是那个真正包含桌面图标的窗口。
桌面图标是放在 SysListView32这个列表中,下面得到了它的句柄,
如何遍历它得到各各桌面图标的句柄? 
如果桌面上有文件夹,文件什么的怎么分辨?
以下三句得到列表的句柄,哪个能告诉我下面该怎么做,我的目标是通过 MoveWindow函数来任意改变桌面上所有图标的位置。。。 
HWND  hwndParent = ::FindWindow(L"Progman",L"Program Manager"); 
HWND  hwndSHELLDLL_DefView = ::FindWindowEx(hwndParent,NULL,L"shelldll_defview", NULL); 
HWND  hwndSysListView32 = ::FindWindowEx(hwndSHELLDLL_DefView,NULL,L"syslistview32",L"FolderView");
<pre name="code" class="cpp">void C***::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);
}

上面的代码 实现把桌面前10图标排成一个圆 楼主去查ListView_RedrawItems这类函数的用法
void C***::OnSetDeskIcon()
{
    HWND hDestTop; 
    hDestTop = ::FindWindow("progman", NULL); 
    hDestTop = ::FindWindowEx(hDestTop, 0, "shelldll_defview", NULL); 
    hDestTop = ::FindWindowEx(hDestTop, 0, "syslistview32", NULL); 
    int count=(int)::SendMessage( hDestTop, LVM_GETITEMCOUNT, 0, 0);
    LVITEM lvi, *_lvi;
    char item[512], subitem[512];
    char *_item, *_subitem;
    unsigned long pid;
    HANDLE process;
    GetWindowThreadProcessId( hDestTop, &pid);
    process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);
    _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
    _item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
    _subitem=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
    RECT  rc;
    rc.left = LVIR_ICON;  //这个一定要设定 可以去看MSDN关于LVM_GETITEMRECT的说明
    RECT* _rc =(RECT*)VirtualAllocEx( process, NULL, sizeof(RECT), MEM_COMMIT, PAGE_READWRITE); 
    lvi.cchTextMax=512;
    for( int i=0; i< 10; i++) {
        lvi.iSubItem=0;
        lvi.pszText=_item;
        WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
        ::SendMessage( hDestTop, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
        lvi.iSubItem=1;
        lvi.pszText=_subitem;
        WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
        ::SendMessage( hDestTop, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
        ::WriteProcessMemory( process, _rc, &rc, sizeof(rc), NULL);
        ::SendMessage( hDestTop, LVM_GETITEMRECT, (WPARAM)i, (LPARAM)_rc);
        ReadProcessMemory(process, _item, item, 512, NULL);
        ReadProcessMemory(process, _subitem, subitem, 512, NULL);
        ReadProcessMemory(process, _rc, &rc, sizeof(rc), NULL);
        CString str;
        str.Format("LF:%d TP:%d RT:%d BT:%d", rc.left,rc.top,rc.right,rc.bottom);
        AfxMessageBox(str);
        str.Format("%s - %s/n", item, subitem);
        AfxMessageBox( str );
    }
    VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
   VirtualFreeEx(process, _item, 0, MEM_RELEASE);
    VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);
    VirtualFreeEx(process, _rc, 0, MEM_RELEASE);
    CloseHandle( process );
}

如何得到桌面窗口的句柄(桌面图标)

标签:

原文地址:http://blog.csdn.net/jiangqin115/article/details/46675215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!