Getting Icons from the Desktop

This is a discussion on Getting Icons from the Desktop within the Windows Programming forums, part of the Platform Specific Boards category; Greetings, Is there a way to get the Icons and their positions on the desktop without forcibly reading through the ...

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    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.
    Founder and avid member of the Internationsl Typo Associateion

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Could you use the code from here? http://faq.cprogramming.com/cgi-bin/...&id=1044780608

    It would necessitate knowing the location of the user's desktop.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    A directory listing is only part of what I require. The icons on the desktop only contain filenames (without absolute paths/extensions). I need both, the absolute path of the icon and its position on the desktop.

    Thanks for the link, it will prove useful later on
    Founder and avid member of the Internationsl Typo Associateion

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You mean, you need "C:\Windows\notepad.exe" as well as "notepad.exe"?

    It's quite simple to search for the last '\\' and take the string from there on. In C without error checking:
    Code:
    const char *path = "C:\\Windows\\notepad.exe";
    const char *filename = strrchr(path, '\\') + 1;
    [edit] Or do you mean the actual [quasi-]physical positioning of the icon on the desktop; for example, at (100,200)? If so, why would you need that? . . . [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Yes I need the Physical Icon position on the desktop and the absolute path that the icon represents. For example:
    Code:
    Icon name on the desktop: songs.
    Absolute Path: C:\Documents and Settings\Mastadex\Desktop\songs.txt
    Position: {20, 20}
    Currently I don't know how to get the Absolute Path.
    Founder and avid member of the Internationsl Typo Associateion

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    The icon positions are probably stored in the registry, like you said. I don't know how you'd get them. But why would you need this information? The only reason I can think of is if you wanted to simulate a click on the icon, or make sure you don't place another icon on top of an old one, or simulate the desktop itself. Or something like that.

    As for the absolute paths, you could probably determine them by reading in the .LNK and .PIF files yourself. I don't know what format they're in, but I'm sure it's consistent.

    Or you could just use some Windows-specific function(s); but I'm not a Windows programmer and so I can't help you there.

    BTW, you should probably be using the word "shortcut" instead of the word "icon". An icon is a little image. A shortcut is a reference to another file somewhere else on the filesystem.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Icons are the right term because Not all Icons are shortcuts. For example, The recycle bin/my computer/network neighborhood icons are technically referred to as "Virtual folders" and do not have any corresponding shortcut on the hard disk. Also, you can have actual files on your desktop that are not shortcuts. I need this information in order to duplicate the desktop's icon orientation within my program; in essence, simulate a desktop environment. I don't want to simulate clicks on these icons, I just need the information that these Icons represent.

    Is there a way to read the desktop as a folder where by you would get an array of PIDLs? Can Icon positions be read out of the Shell using such a method? Does the shell store Icon positions within a folder (ie. Large Icon view) in the same way a Desktop does?
    Founder and avid member of the Internationsl Typo Associateion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended Desktop Dimensions
    By Jaken Veina in forum Windows Programming
    Replies: 2
    Last Post: 01-16-2009, 08:15 AM
  2. [C] Problem with icons in a toolbar
    By pc2-brazil in forum Windows Programming
    Replies: 3
    Last Post: 12-22-2008, 10:04 PM
  3. "Organizing" Your Desktop for Coding
    By skim in forum Windows Programming
    Replies: 2
    Last Post: 03-13-2006, 05:52 PM
  4. Showing Desktop SW_DEFAULT
    By Yuri in forum Windows Programming
    Replies: 6
    Last Post: 11-20-2005, 12:28 PM
  5. Do you use your desktop?
    By MethodMan in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 12-06-2002, 03:06 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21