Getting Icons from the Desktop
Greetings,
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:
Code:
HWND WindowsSystem::FindListView()
{
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");
if (progmanHwnd)
{
// Then get the desktop window
desktopViewHwnd = FindWindowEx(progmanHwnd, NULL, "SHELLDLL_DefView", NULL);
if (desktopViewHwnd)
{
// Finally get the handle to the listview on the desktop.
listViewHwnd = FindWindowEx(desktopViewHwnd, NULL, "SysListView32", NULL);
}
}
return listViewHwnd;
}
Once there I just read the memory:
Code:
// First we get the icon position.
result = SendMessage(listViewHwnd, LVM_GETITEMPOSITION, i, (LPARAM) iconPos);
if (result)
{
// Get the data from the shared memory
ReadProcessMemory(explorer, iconPos, &iconPoint, sizeof(POINT), NULL);
// Set stuff up to retrieve the label of the icon.
[....my code....]
// Write the list source
WriteProcessMemory(explorer, iconLabel, &iconListLabel, sizeof(LVITEM), NULL);
// Request the label.
result = SendMessage(listViewHwnd, LVM_GETITEMTEXT, i, (LPARAM) iconLabel);
if (SUCCEEDED(result))
{
ReadProcessMemory(explorer, iconNameBuffer, &buffer, sizeof(buffer), NULL);
// Save the Icon name and Position
[....my code....]
}
}
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??
Any help is appreciated,
Thanks in advance.