Solved

Open Desktop Items

Posted on 2002-04-22
9
243 Views
Last Modified: 2013-12-03
Hi,
I'm making a Desktop kind of program.
It scans the Desktop Folder via:

          if( SHGetDesktopFolder(&pDTF) == NOERROR )
          {
               if( pDTF->EnumObjects(hWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pEIL) == NOERROR )
               {
                    while( pEIL->Next(1, &pDTIcon, &uNumIcon) == NOERROR )
                    {
                         if( SHGetFileInfo((LPCTSTR)pDTIcon, 0, &fi, sizeof(fi), SHGFI_DISPLAYNAME | SHGFI_PIDL | SHGFI_ICON | SHGFI_TYPENAME | (bSmall ? SHGFI_SMALLICON : SHGFI_LARGEICON)) )
                         {


It works perfectly

But now my question:
I want to open all of the items in the Desktop Folder (not all at once ofcourse). There are also the items like "My Computer" "Internet Explorer" etc. those are "Sytem Folders" (fi.szTypeName). How can I open/run these system folder types??
The "My Documents" is no problem, I can get the path (SHGetPathFromIDList()) and ShellExecute it, but those other ones??

Can somebody help me?

If the question is too hard for 100 points just let me know!


0
Comment
Question by:KnoppenSpook
  • 4
  • 2
  • 2
  • +1
9 Comments
 

Author Comment

by:KnoppenSpook
ID: 6959990
I'm working is Visual C++
0
 
LVL 86

Expert Comment

by:jkr
ID: 6960006
You'd use 'SHGetSpecialFolderLocation()' together with 'SHGetPathFromIDList()' to open them...
0
 

Author Comment

by:KnoppenSpook
ID: 6960057
when I do this:

     CHAR     szCommand[MAX_PATH+1];
     LPMALLOC      pMem    = NULL;
     LPITEMIDLIST  pSpecFolder = NULL;

     if( SHGetMalloc(&pMem) == NOERROR )
     {
          SHGetSpecialFolderLocation(hWnd,CSIDL_DRIVES,&pSpecFolder);
          SHGetPathFromIDList(pSpecFolder,szCommand);


     }

szCommand is empty :(
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:KnoppenSpook
ID: 6960083
I'm working is Visual C++
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6964692
As you enumerate throught the contents of the desktop using the "Next" function, you get PIDLs for the items on the desktop returned in the 2nd argument to "Next".
( or at least the Address of an array of ITEMIDLIST pointers).
These PIDLs can be plugged back into the parent directory (the desktop in this case) using pDTF->BindToObject and...
you end up with an IShellFolder interface for the next level down the Namespace hierarchy. You can then EnumObjects on that interface and so on down until you reach the bottom of the tree.

But you will need patience, close attention to whether you've got an ILD, a PIDL or a PILD*. Oh and you will also need plenty of luck.

Cheers
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6964699
PS. I think the PIDLS you get from EnumObjects are always relative to their parent in the namespace so use IBindToObject on the parent IShellFolder not the root IShellFolder.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6965541
I'm doing it like this:

(1) Call IShellFolder.GetUIObjectOf to get an IContextMenu instance of the context menu of the desktop items.
(2) Call IContextMenu.InvokeCommand to "execute" the item. This should open the item.

Regards, Madshi.
0
 

Author Comment

by:KnoppenSpook
ID: 6972556
It's true, tx, one little question before you get your points :-) Can I just invoke command '0' Or do I have to check wich item of the ContextMenu is "open"
0
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 6972846
Hmmmmm... Let me look in my code again...

Sorry, I should have said that from the beginning. My Delphi code looks something like this (I've shorted it a bit):

procedure ExecuteDefaultItem(cm: IContextMenu; parentWnd: dword);
var ici  : TCMInvokeCommandInfo;
    menu : dword;
begin
  menu := CreatePopupMenu;
  try
    zeroMemory(@ici,sizeOf(ici));
    with ici do begin
      cbSize := sizeOf(TCMInvokeCommandInfo);
      fMask  := CMIC_MASK_FLAG_NO_UI;
      hwnd   := parentWnd;
      nShow  := SW_SHOW;
    end;
    cm.QueryContextMenu(menu, 0, 1, $7FFF, CMF_DEFAULTONLY);
    ici.lpVerb := pchar(GetMenuDefaultItem(menu, 0, 0) - 1);
    cm.InvokeCommand(ici);
  finally DestroyMenu(menu) end;
end;

Regards, Madshi.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question