Open the Desktop folder  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 17/09/99

Tip accessed 472 times

 


This tip allows to open the Desktop folder.
With the same code, we can open up the rest of 'Virtual' folders of Windows. Although I repeat, I will put each one of them in a tip, for facilitate the search for the Tip list.


The operation is the following one:
  • We will find the folder identificator (PIDL) and we will open it by means of ShellExecuteEx, since this function of the API allows to open up a portfolio knowing its identificator (PIDL)

  • Add 'ShellApi and ShlObj' in the uses of your form



     procedure TForm1.Button1Click(Sender: TObject);
     var
        PIDL:PItemIDList;
        Info:TShellExecuteInfo;
        pInfo:PShellExecuteInfo;
        WaitCode:DWord;
     begin
        {Obtenemos PIDL de la carpeta virtual}
        {get PIDL of the virtual folder}
        SHGetSpecialFolderLocation(Handle,
                                   CSIDL_DESKTOP,
                                   PIDL);
        {Puntero a Info}
        {Pointer to Info}
        pInfo:=@Info;
        {Rellenamos Info}
        {Fill info}
        With Info do
        begin
         cbSize:=SizeOf(Info);
         fMask:=SEE_MASK_NOCLOSEPROCESS+
                SEE_MASK_IDLIST;
         wnd:=Handle;
         lpVerb:=nil;
         lpFile:=nil;
         {Parametros al ejecutable}
         {Executable parameters}
         lpParameters:=nil;
         lpDirectory:=nil;
         nShow:=SW_ShowNormal;
         hInstApp:=0;
         lpIDList:=PIDL;
        end;
        {Ejecutamos}
        {Execute}
        ShellExecuteEx(pInfo);
    
        {Esperamos que termine}
        {Wait to finish}
        repeat
         WaitCode := WaitForSingleObject(Info.hProcess,500);
         Application.ProcessMessages;
        until (WaitCode <> WAIT_TIMEOUT);
    
     end;