Created
September 23, 2016 05:48
-
-
Save kirkbackus/bac43db43ab3d211ca5d0ae32bc55c95 to your computer and use it in GitHub Desktop.
Enumerate all of the icons and their positions on your desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define _WIN32_WINNT 0x0500 | |
#include <windows.h> | |
#include <commctrl.h> | |
#include <winuser.h> | |
#include <tchar.h> | |
HWND GetDesktopListViewHWND() | |
{ | |
HWND hDesktopListView = NULL; | |
HWND hWorkerW = NULL; | |
HWND hProgman = FindWindow(_T("Progman"), 0); | |
HWND hDesktopWnd = GetDesktopWindow(); | |
if (hProgman) { | |
HWND hShellViewWin = FindWindowEx(hProgman, 0, _T("SHELLDLL_DefView"), 0); | |
if (hShellViewWin) { | |
hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0); | |
} else { | |
do { | |
hWorkerW = FindWindowEx( hDesktopWnd, hWorkerW, _T("WorkerW"), NULL ); | |
hShellViewWin = FindWindowEx(hWorkerW, 0, _T("SHELLDLL_DefView"), 0); | |
} while (hShellViewWin == NULL && hWorkerW != NULL); | |
} | |
hDesktopListView = FindWindowEx(hShellViewWin, 0, _T("SysListView32"), 0); | |
} | |
return hDesktopListView; | |
} | |
int main() | |
{ | |
HWND hDesktopListView = GetDesktopListViewHWND(); | |
unsigned long processId; | |
GetWindowThreadProcessId(hDesktopListView, &processId); | |
DWORD procFlags = PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION; | |
HANDLE process = OpenProcess(procFlags, FALSE, processId); | |
POINT *_pt = (POINT*)VirtualAllocEx(process, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READWRITE); | |
std::cout << hDesktopListView << std::endl; | |
int icons = (int)SendMessage(hDesktopListView, LVM_GETITEMCOUNT, NULL, NULL); | |
std::cout << "Items: " << icons << std::endl; | |
for (int i=0; i<icons; i++) { | |
POINT point; | |
WriteProcessMemory(process, _pt, &point, sizeof(POINT), NULL); | |
SendMessage(hDesktopListView, LVM_GETITEMPOSITION, (WPARAM)i, (LPARAM)_pt); | |
ReadProcessMemory(process, _pt, &point, sizeof(POINT), NULL); | |
std::cout << "Icon: " << i << " - (" << point.x << "," << point.y << ")" << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment