Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   C++ Builder (https://www.clubdelphi.com/foros/forumdisplay.php?f=13)
-   -   Como creo un aaceso directo desde C++ Builder 6 (https://www.clubdelphi.com/foros/showthread.php?t=79476)

DSK25 10-07-2012 01:30:58

Como creo un aaceso directo desde C++ Builder 6
 
Buenas tardes, quiero saber como puedo mediante codigo crear un acceso directo tanto en el escritorio como en el menu inicio en la barra de programas. Gracias.

Ñuño Martínez 10-07-2012 01:44:57

Esto es una pregunta típica para buscar en MSDN. :)

ecfisa 10-07-2012 08:23:10

Hola DSK25.

Para crear los accesos directos podes hacer:
Código:

#include<shlobj.h>
#include<comobj.hpp>

void CreateShortcut(char *ExeFileName, char *LnkFileName)
{
IUnknown *UInterface;
IShellLink *ISlink;
IPersistFile *IPfile;

  OleCheck(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL,
    IID_IUnknown, (void**) &UInterface));
  __try {
    OleCheck(UInterface->QueryInterface(IID_IShellLink,(void**) &ISlink));
    __try {
      ISlink->SetPath(ExeFileName);
      OleCheck(UInterface->QueryInterface(IID_IPersistFile,(void**) &IPfile));
      __try {
        IPfile->Save((WideString)LnkFileName, False);
      }
      __finally {
        IPfile->Release();
      }
    }
    __finally {
      ISlink->Release();
    }
  }
  __finally {
    UInterface->Release();
  }
}

Ejemplo de llamada:
Código:

void __fastcall TForm1::Button1Click(TObject *Sender)
}
char PathToShortcut[260];
char *ExeFileName = "C:\\MiPrograma.exe"; // ruta al programa
char *LnkFileName = "MiPrograma.lnk";    // nombre del a. directo

  /* componer ruta a escritorio */
  wsprintf(PathToShortcut,"%s%s%s", getenv("USERPROFILE"),
    "\\Desktop\\", LnkFileName);

  /* Crear acceso directo */
  CreateShortcut(ExeFileName, PathToShortcut);

  /* componer ruta a Menu de inicio */
  ZeroMemory(PathToShortcut, sizeof(PathToShortcut));
  wsprintf(PathToShortcut,"%s%s%s", getenv("APPDATA"),
    "\\Microsoft\\Windows\\Start Menu\\Programs\\", LnkFileName);

 /* Crear acceso directo */
  CreateShortcut(ExeFileName, PathToShortcut);
}

Para evitar el error "Multiple declaration for ..." , hace lo siguiente:
Project -> Options -> Directories/Conditionals -> Conditional defines, click sobre el boton con puntos suspensivos (...), escribí NO_WIN32_LEAN_AND_MEAN en el cuadro de edición y hace click sobre el botón Add.

Saludos.

DSK25 10-07-2012 15:40:56

Gracias ecfisa, me funciono perfectamente.


La franja horaria es GMT +2. Ahora son las 22:19:26.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi