Is there a way to get the Icons and their positions on the desktop without forcibly reading through the memory space of Explorer.exe? I am looking for a cleaner solution then the one I found on the net. Here is a snippet of how I find the Program Manager:
Once there I just read the memory:
HWND progmanHwnd = 0;
HWND desktopViewHwnd = NULL;
HWND listViewHwnd = NULL;
// First find the main window of program that houses the desktop.
progmanHwnd = FindWindow(NULL, "Program Manager");
// Then get the desktop window
desktopViewHwnd = FindWindowEx(progmanHwnd, NULL, "SHELLDLL_DefView", NULL);
// Finally get the handle to the listview on the desktop.
listViewHwnd = FindWindowEx(desktopViewHwnd, NULL, "SysListView32", NULL);
The problem is that the names of the icons are read as they are seen on the desktop and therefore don't have a Path, and sometimes (in the case of hidden LNK files) do not have an extension. Therefore it is hard to cross reference them with a directory listing. Is there a better way of getting these Icons, possibly polling the registry?? or reading some setting file??
// First we get the icon position.
result = SendMessage(listViewHwnd, LVM_GETITEMPOSITION, i, (LPARAM) iconPos);
// Get the data from the shared memory
ReadProcessMemory(explorer, iconPos, &iconPoint, sizeof(POINT), NULL);
// Set stuff up to retrieve the label of the icon.
// Write the list source
WriteProcessMemory(explorer, iconLabel, &iconListLabel, sizeof(LVITEM), NULL);
// Request the label.
result = SendMessage(listViewHwnd, LVM_GETITEMTEXT, i, (LPARAM) iconLabel);
ReadProcessMemory(explorer, iconNameBuffer, &buffer, sizeof(buffer), NULL);
// Save the Icon name and Position
Any help is appreciated,
Thanks in advance.