问题描述
解决方案
使用shell扩展可以实现
参考:
http://www.codeproject.com/Articles/448/The-Complete-Idiots-Guide-to-Writing-Shell-Exten
解决方案二:
至于根据快捷方式文件(.lnk)得到指向的文件和路径,参考:
http://www.codeguru.com/cpp/com-tech/shell/article.php/c1337/Getting-Shortcuts-lnk--Target-and-Arguments.htm
解决方案三:
http://blog.csdn.net/mycaibo/article/details/6002334
解决方案四:
我的目的是要遍历整个桌面的所有图标,获取每个图标的坐标,我在百度上搜了很多例子,也运行了,但是都不行,感觉最靠谱的就是这个
void Recurse(LPCTSTR pstr)
{
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< count; 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 - %sn", 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 );
return ;
}
但是这个例子运行起来不起作用messagebox 打出来的结果是空的
跟踪查到
_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);
这个地方获取出来的指针都是错误的指针,虽然有值但不起作用,不知道哪里出错了