Ver Mensaje Individual
  #3  
Antiguo 10-07-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
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.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 10-07-2012 a las 14:28:10. Razón: agregar comentarios
Responder Con Cita