Appeler un fichier par un boutton en VB6

hakim_fth Messages postés 157 Statut Membre -  
jmwurth Messages postés 2622 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Bonjour,

J'ai une application développée en VB6 et je souahite avoir la commande qui me permet d'appeler un fichier PDF en cliquant sur un boutton.

Merci d'avance!

3 réponses

  1. jmwurth Messages postés 2622 Date d'inscription   Statut Membre Dernière intervention   863
     
    Bonjour
    exemples de commandes en appuyant sur une touche
    Private Sub signifext_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then okext_Click 'touche Enter
    'If KeyAscii = 27 Then extvert.Text = "" 'touche Echap
    If KeyAscii = 32 Then 'barre d'espace
    (...)
    End If
    End Sub
    Pour ouvrir un fichier, vous connaissez sans doute la commande
    0
  2. jmwurth Messages postés 2622 Date d'inscription   Statut Membre Dernière intervention   863
     
    Erreur. Il s'agit d'ouvrir un fichier via un button.

    Pour exécuter un fichier

    Private Sub execut_Click()
    On Error GoTo fin_exec
    exec = ShellExecute(hwnd, vbNullString, nomf, 0&, filelist.Path, 1)
    errexecut
    Exit Sub
    fin_exec:
    End Sub

    nomf est le nom du fichier, filelist.path est le dossier avec son chemin

    Private Sub errexecut()
    If Format(exec) = 2 Then messa = MsgBox("fichier non trouvé", 64)
    If Format(exec) = 3 Then messa = MsgBox("chemin non trouvé", 64)
    If Format(exec) = 5 Then messa = MsgBox("accès refusé", 64)
    If Format(exec) = 8 Then messa = MsgBox("mémoire insuffisante", 64)
    If Format(exec) = 12 Then messa = MsgBox("fichier incompatible avec Windows", 64)
    If Format(exec) = 26 Then messa = MsgBox("erreur de partage", 64)
    If Format(exec) = 27 Then messa = MsgBox("association incomplète", 64)
    If Format(exec) = 28 Then messa = MsgBox("DDE time out", 64)
    If Format(exec) = 29 Then messa = MsgBox("échec DDE", 64)
    If Format(exec) = 30 Then messa = MsgBox("DDE occupé", 64)
    If Format(exec) = 31 Then messa = MsgBox("L'extension n'a pas d'association", 64)
    If Format(exec) = 32 Then messa = MsgBox("shell32.dll non trouvé dans \windows\system", 64)
    End Sub
    0
    1. jmwurth Messages postés 2622 Date d'inscription   Statut Membre Dernière intervention   863
       
      A ajouter aux déclarations
      Option Explicit

      Private Type SHELLEXECUTEINFO
      cbSize As Long
      fMask As Long
      hwnd As Long
      lpVerb As String
      lpFile As String
      lpParameters As String
      lpDirectory As String
      nShow As Long
      hInstApp As Long
      lpIDList As Long
      lpClass As String
      hkeyClass As Long
      dwHotKey As Long
      hIcon As Long
      hProcess As Long
      End Type
      '
      Private Const SEE_MASK_INVOKEIDLIST = &HC
      Private Const SEE_MASK_NOCLOSEPROCESS = &H40
      Private Const SEE_MASK_FLAG_NO_UI = &H400

      Private Declare Function ShellExecuteEX Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long

      Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
      Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
      Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
      0
    2. hakim_fth Messages postés 157 Statut Membre
       
      Je te remercie infiniment pour ton retour " jmwurth", mais vraiment je n'arrive pas à appliquer tout ça. C'est très longue.
      0
  3. jmwurth Messages postés 2622 Date d'inscription   Statut Membre Dernière intervention   863
     
    Il y a beaucoup de choses qui concernent la recherche d'une éventuelle erreur, ainsi que des fonctions non utilisées ici. Je vais conserver l'essentiel

    Private Sub execut_Click()
    nomf, doss as string
    On Error GoTo fin_exec
    exec = ShellExecute(hwnd, vbNullString, nomf, 0&, doss, 1)
    Exit Sub
    fin_exec:
    MsgBox("ERREUR jmwurth", 64)
    End Sub

    nomf est le nom du fichier sans chemin, doss est le dossier avec son chemin

    A déclarer
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    0