Board index » delphi » Opening File in 'My Computer'

Opening File in 'My Computer'

  I need to open a Dialog inside 'My Computer'.  --  I've got API call, I've
got the location, but I can't figure out what a 'LPITEMIDLIST' is...  Any
help?  --  Someone gave me a hand with this a while ago, but I accidentily
lost the E-mail...
  Thanks...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  You will be assimilated.  Resistance is Futile
--

 

Re:Opening File in 'My Computer'


Quote
Jason Wallace wrote in message <66foar$fg...@news.greatbasin.net>...
>  I need to open a Dialog inside 'My Computer'.  --  I've got API call,
I've
>got the location, but I can't figure out what a 'LPITEMIDLIST' is...  Any
>help?  --  Someone gave me a hand with this a while ago, but I accidentily
>lost the E-mail...
>  Thanks...

>--
>Jason Wallace

Jason:

Here's some Delphi 3 code that should get you started.  This code was
used to access various items in the Printers folder, which is close
to what you want to do:

  USES
    ShellAPI,   // TShellExecuteInfo, ShellExecuteEx
    SysUtils;   // Exception

  TYPE
    ESHprintersError = CLASS(Exception);

  FUNCTION ExecuteAddPrinter:  BOOLEAN;
    VAR
      AddPrinterItemIDList:  pItemIDList;
      Allocator           :  IMalloc;
      ShellExecuteInfo    :  TShellExecuteInfo;
  BEGIN
    RESULT := FALSE;
    IF   CoGetMalloc(MEMCTX_TASK, Allocator) = S_OK
    THEN BEGIN
      AddPrinterItemIDList := GetAddPrinterItem(Allocator);
      TRY
        IF   AddPrinterItemIDList = NIL
        THEN RESULT := FALSE
        ELSE BEGIN
          ZeroMemory(@ShellExecuteInfo, SizeOf(TShellExecuteInfo));
          WITH ShellExecuteInfo DO
          BEGIN
            cbSize   := SizeOf(TShellExecuteInfo);
            fMask    := SEE_MASK_INVOKEIDLIST OR SEE_MASK_FLAG_NO_UI;
            lpIDList := AddPrinterItemIDlist;
            nShow    := SW_SHOWDEFAULT
          END;
          ShellExecuteEx(@ShellExecuteInfo);
          RESULT := TRUE
        END
      FINALLY
        Allocator.Free(AddPrinterItemIDList)
      END
    END
  END {ExecuteAddPrinter};

  FUNCTION GetAddPrinterItem(CONST Allocator:  IMalloc):  pItemIDList;
    VAR
      DeskTopFolder    :  IShellFolder;
      EnumIDList       :  IEnumIDList;
      hOK              :  hResult;
      PrinterItemIDList:  pItemIDList;
      PrintersFolder   :  IShellFolder;
      Retrieved        :  INTEGER;
      TargetItemIDList :  pItemIDList;
      TempItemIDList   :  pItemIDList;
  BEGIN
    TargetItemIDList := NIL;
    IF   Allocator <> NIL
    THEN BEGIN
      IF   Succeeded(SHGetDesktopFolder(DeskTopFolder))
      THEN BEGIN
        PrinterItemIDList := GetPrinterItemIDList(DeskTopFolder);
        IF   PrinterItemIDList <> NIL
        THEN BEGIN
          // Get the IShellFolder for Printers
          hOK := DeskTopFolder.BindToObject(PrinterItemIDList,
                                            NIL,
                                            IID_IShellFolder,
                                            Pointer(PrintersFolder));
          IF  Succeeded(hOK)
          THEN BEGIN
            IF   Succeeded(PrintersFolder.EnumObjects(0, SHCONTF_FOLDERS OR
SHCONTF_NONFOLDERS,
                                                      EnumIDList))
            THEN BEGIN
              // Get the first item's ItemIDList.  This will be the item for
adding a printer.
              hOK := EnumIDList.Next(1, TempItemIDList, Retrieved);
              IF  (Retrieved > 0) AND Succeeded(hOK)
              THEN TargetItemIDList := ItemIDListsConcatenate(Allocator,

PrinterItemIDList,

TempItemIDList);
            END
          END
        END
      END;
    END;
    RESULT := TargetItemIDList
  END {GetAddPrinterItem};

  FUNCTION GetPrinterItemIDList(CONST DeskTopFolder:  IShellFolder):
pItemIDlist;
    VAR
      hOK              :  hResult;
      PrinterItemIDList:  pItemIDList;
  BEGIN
    IF   DeskTopFolder = NIL
    THEN RESULT := NIL
    ELSE BEGIN
      hOK := SHGetSpecialFolderLocation(0,
                                        CSIDL_PRINTERS, // Virtual folder of
installed printers
                                        PrinterItemIDList);
      IF   Failed(hOK)
      THEN RESULT := NIL
      ELSE RESULT := PrinterItemIDList
    END
  END {GetPrinterItemIDList};

  // Creates a new ItemIDList with List1 appended to List2
  FUNCTION ItemIDListsConcatenate(CONST Allocator:  IMalloc;
                                  CONST List1, List2:  pItemIDList):
pItemIDlist;
    VAR
      List1Length  :  INTEGER;
      List2Length  :  INTEGER;
      NewItemIDList:  pItemIDList;
  BEGIN
    List1Length := 0;
    // List1 can possibly be NIL if it points to the desktop.  Since we only
    // need a sngle NIL terminator, we remove the extra 2 bytes from the
size
    // of the first ItemIDList
    IF   List1 <> NIL
    THEN List1Length := ItemIDListGetSize(List1) - 2*SizeOf(BYTE);
    List2Length := ItemIDListGetSize(List2);
    // Create a new ItemIDList that is the size of List1 and List2, then
    // copy List1 and List2 to the new list.
    NewItemIDList := ItemIDListCreate(Allocator, List1Length + List2Length);
    IF   NewItemIDList <> NIL
    THEN BEGIN
      IF   List1 <> NIL
      THEN CopyMemory(NewItemIDList, List1, List1Length);
      CopyMemory(Pointer(INTEGER(NewItemIDList) + List1Length),
                 List2, List2Length)
    END;
    RESULT := NewItemIDList
  END {ItemIDListsConcatenate};

   // Returns total number of bytes in an ItemIDList (Microsoft's
Pidl_GetSize)
  FUNCTION ItemIDListGetSize(CONST ItemIDList:  pItemIDList):  INTEGER;
{size in bytes}
    VAR
      TempItemIDList:  pItemIDList;
  BEGIN
    RESULT := 0;
    TempItemIDList := ItemIDList;
    IF   TempItemIDList <> NIL
    THEN BEGIN
      WHILE (TempItemIDList.mkid.cb > 0) DO
      BEGIN
        INC(RESULT, TempItemIDList.mkid.cb);
        TempItemIDList := ItemIDListGetNextItem(TempItemIDList)
      END;
      // Requires a 16 bit zero value for the null terminator
      INC(RESULT, 2*SizeOf(BYTE))
    END
  END {ItemIDListGetSize};

efg
___________________________________
Earl F. Glynn        EarlGl...@WorldNet.att.net
MedTech Research Corporation
Lenexa, KS  USA

Other Threads