win7 win10 x64 有效
#include<Windows.h> #include<commctrl.h> #include <stdio.h> typedef struct tagLVITEM64A { UINT mask; int iItem; int iSubItem; UINT state; UINT stateMask; INT64 pszText; int cchTextMax; int iImage; LPARAM lParam; #if (_WIN32_IE >= 0x0300) int iIndent; #endif #if (_WIN32_WINNT >= 0x501) int iGroupId; UINT cColumns; // tile view columns PUINT puColumns; #endif } LVITEM64A, *LPLVITEM64A; void GetChromePT(HWND h) { DWORD dwProcessId; HWND hDeskTop; hDeskTop = ::FindWindow(L"progman", NULL); hDeskTop = ::FindWindowEx(hDeskTop, 0, L"shelldll_defview", NULL); hDeskTop = ::FindWindowEx(hDeskTop, 0, L"syslistview32", NULL); //获取桌面窗口bai句柄du; GetWindowThreadProcessId(hDeskTop, &dwProcessId);//通过桌面窗口句柄获取此窗口所在进程的PID,其实就是explorer进程 HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);//打开zhi指定PID进程,取得进程句柄 tagLVITEM64A *_lv,lvi; LPVOID lpvPt = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE);//在指定进程里面申请一个POINI结构大小的空间. _lv = (tagLVITEM64A*)VirtualAllocEx(hProcess, NULL, sizeof(tagLVITEM64A), MEM_COMMIT, PAGE_READWRITE);//在指定进程里面申请一个文本结构大小的空间. char item[512] = { 0 }; char *_item; POINT pt; //获取窗口listbox 句柄 与 获取桌面图标信息无关 可忽略 HWND h_list = GetListHandle(h); int m_iconCount = ListView_GetItemCount(hDeskTop); _item = (char*)VirtualAllocEx(hProcess, NULL, 512, MEM_COMMIT, PAGE_READWRITE); ZeroMemory(&lvi, sizeof(LVITEM)); //lv.mask = LVIF_TEXT; lvi.cchTextMax = 512; for (size_t i = 1; i < m_iconCount; i++) { //坐标 ListView_GetItemPosition(hDeskTop, i, lpvPt);//获取第一个图标的坐标,存入lpvPt ReadProcessMemory(hProcess, lpvPt, &pt, sizeof(POINT), NULL); //名称 lvi.iSubItem = 0; lvi.pszText = (INT64)_item; WriteProcessMemory(hProcess, _lv,&lvi,sizeof(LVITEM),NULL); SendMessage(hDeskTop, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lv); ReadProcessMemory(hProcess, _item, item, 512,NULL ); wchar_t pt_char[MAXBYTE] = { 0 }; //填充listbox wsprintf(pt_char, L"%ld---%ld--name:%s", pt.x,pt.y, item); //一句话解决 SendMessage(h_list, LB_ADDSTRING, 0, (LPARAM)pt_char); } //lpvPt不是本进程里面的,不能使用,所以就要 //利用ReadProcessMemory从指定进程给读出来 VirtualFreeEx(hProcess, lpvPt, 0, MEM_RELEASE); VirtualFreeEx(hProcess, _lv, 0, MEM_RELEASE); VirtualFreeEx(hProcess, _item, 0, MEM_RELEASE); //释放申请的空间 CloseHandle(hProcess);//关闭句柄 }