在获取桌面图标时,,为啥取不到句柄???别人电脑可以我的不可以???

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 );

}



2个回答

CRY6666
CRY6666 我的是win64 VS2013 SP1,,第一个句柄(45行)能得到,但是第二个句柄(46行)无法得到
大约 3 年之前 回复

图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐