getdesktopicons
#include <WindowsX.h>
#include <atlstr.h>//可以用 cstring了
#include <stdio.h>
#include <locale>
#include <CommCtrl.h>//windows通用控件接口
int main()
{
_tsetlocale(LC_CTYPE,TEXT(""));
HWND hwndLv=GetFirstChild(GetFirstChild(
FindWindow(TEXT("ProgMan"), NULL)));//获取到桌面图标所在的 ListView
if (hwndLv==NULL)
{
_tprintf(TEXT("Error Find Destop Window"));//寻找桌面图标列表框失败
return -1;
}
int iMaxCount=ListView_GetItemCount(hwndLv);//图标数
_tprintf(TEXT("%d Items hwnd:%d/r/n"),iMaxCount,hwndLv);
_tsystem(TEXT("pause"));
DWORD dwPid;
GetWindowThreadProcessId(hwndLv,&dwPid);//获取进程ID
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,dwPid);//打开进程
if (hProcess==INVALID_HANDLE_VALUE)
{
_tprintf(TEXT("Error Open Process"));//打开进程失败
return -1;
}
LVITEM *plvitem=(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof(LVITEM),
MEM_COMMIT, PAGE_READWRITE);//在目标进程内分配一块小内存
TCHAR *pszName=(TCHAR*)VirtualAllocEx(hProcess, NULL, MAX_PATH*sizeof(TCHAR),
MEM_COMMIT, PAGE_READWRITE);//分配名字
POINT *ppt=(POINT*)VirtualAllocEx(hProcess, NULL, sizeof(POINT),
MEM_COMMIT, PAGE_READWRITE);//获取坐标用
for (int i=0;i<iMaxCount;i++)
{
TCHAR szName[MAX_PATH];
//ListView_GetItemText(hwndLv, i, 0, szName,sizeof(szName));//获取图标名称
LVITEM lv={0};
lv.cchTextMax=MAX_PATH*sizeof(TCHAR);
lv.pszText=pszName;
WriteProcessMemory(hProcess,plvitem,&lv,sizeof(LVITEM),NULL);//吧信息写入
SendMessage(hwndLv,LVM_GETITEMTEXT,i,(LPARAM)plvitem);//发送消息
ReadProcessMemory(hProcess,pszName,szName,sizeof(szName),NULL);//读取名字
POINT pt;
//ListView_GetItemPosition(hwndLv, i, &pt);//获取图标所在坐标
SendMessage(hwndLv,LVM_GETITEMPOSITION,i,(LPARAM)ppt);
ReadProcessMemory(hProcess,ppt,&pt,sizeof(POINT),NULL);//读取图标坐标
_tprintf(TEXT("%4d,%-4d %s/r/n"),pt.x,pt.y,szName);
}
VirtualFreeEx(hProcess, plvitem, 0, MEM_RELEASE);//释放内存 打扫战场
VirtualFreeEx(hProcess, pszName, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, ppt, 0, MEM_RELEASE);
CloseHandle(hProcess);
_tsystem(TEXT("pause"));
return 0;
}