Problème handle ShellExecute
Bonjour, j'essaie en vain d'utiliser ShellExecute pour afficher un PDF, j'ai trouvé un exemple dans le support Microsoft http://support.microsoft.com/kb/170918/fr , voici donc mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| Dim ret As Long
Dim Scr_hDC As Long
Try
Scr_hDC = GetDesktopWindow()
MessageBox.Show(filename, "Exper-PDF", MessageBoxButtons.OK, MessageBoxIcon.Error)
ret = ShellExecute(Scr_hDC, "Open", filename, "", "C:\TEMP\", 1)
Dim msg As String
If ret <= 32 Then
'There was an error
Select Case ret
Case SE_ERR_FNF
msg = "File not found"
Case SE_ERR_PNF
msg = "Path not found"
Case SE_ERR_ACCESSDENIED
msg = "Access denied"
Case SE_ERR_OOM
msg = "Out of memory"
Case SE_ERR_DLLNOTFOUND
msg = "DLL not found"
Case SE_ERR_SHARE
msg = "A sharing violation occurred"
Case SE_ERR_ASSOCINCOMPLETE
msg = "Incomplete or invalid file association"
Case SE_ERR_DDETIMEOUT
msg = "DDE Time out"
Case SE_ERR_DDEFAIL
msg = "DDE transaction failed"
Case SE_ERR_DDEBUSY
msg = "DDE busy"
Case SE_ERR_NOASSOC
msg = "No association for file extension"
Case ERROR_BAD_FORMAT
msg = "Invalid EXE file or error in EXE image"
Case Else
msg = "Unknown error"
End Select
MessageBox.Show(msg, "Exper-PDF", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show(CStr(ret), "Exper-PDF", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString & "ret :" & CStr(ret), "Exper-PDF", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try |
Le problème est qu'aucun message d'erreur ne s'affiche; le problème vient de l'initialisation de Scr_hDC (Scr_hDC = GetDesktopWindow()) pour en avoir le coeur net j'ai fait suivre cette instruction d'un affichage de MessageBox, qui ne s'affiche jamais non plus), dans d'autres topics j'ai vu qu'on pouvait récupérer un handle hwnd, mais je ne sais comment récupérer cette objet, ma fenêtre principale s'appelle MainPage et l'auto complétion ne me propose pas d'attribut hwnd.
Merci beaucoup pour votre aide.