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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
'utilisé pour word
Dim docword As New Word.Application
'utilisé pour Adobe Acrobat Reader
'Ouvre AAR
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
'Permet de fermer la fenetre
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
' La fonction GetParent recherche le handle du parent propriétaire de la fenêtre indiquée.
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
' La fonction GetWindow recherche le handle de la fenêtre active
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
' La fonction GetWindowTextLength recherche la longueur, en caractères, du texte de barre du titre de la fenêtre indiquée (si la fenêtre a une barre de titre). Si la fenêtre indiquée est une commande, la fonction recherche la longueur du texte dans la commande. Cependant, GetWindowTextLength ne peut pas rechercher la longueur du texte d'une commande d'édition dans une autre application.
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
' La fonction GetWindowText copie le texte de la barre du titre de la fenêtre indiquée (si elle a un) dans un buffer. Si la fenêtre indiquée est une commande, le texte de la commande est copié. Cependant, GetWindowText ne peut pas rechercher le texte d'une commande dans une autre application.
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private meHwnd As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Public Sub GoImprime(unChemin As String)
'teste permettant de savoir si le fichier est un RTF ou un PDF
Dim teste As String
Dim toto As Boolean
teste = Right$(unChemin, 3)
If teste = "pdf" Or teste = "PDF" Then
Dim Retour As Long
'la fonction ShellExecute va ouvrir l'application adapté à l'extention et le paramètre Print va permetre d'imprimer, l'application sara ensuite fermé
Retour = ShellExecute(hwnd, "print", unChemin, "", vbNullString, 0)
'mise en route du timer
Timer2.Enabled = True
'10 sec avant la fermeture de word
Timer2.Interval = 10000
Call Timer2_Timer
Else
'Enonciation des variables
'Création d'une instance de WinWord
Set docword = CreateObject("word.application")
'True pour word visible et false pour le mettre en arrière plan
docword.Visible = False
docword.DisplayAlerts = False 'évite les erreurs de traitement
'ouverture du document, sans la sélection du type de selui-ci
doc = docword.Documents.Open(unChemin, 0)
'impression de celui ci
docword.ActiveDocument.PrintOut
'mise en route du timer
Timer1.Enabled = True
'10 sec avant la fermeture de word
Timer1.Interval = 1000
End If
End Sub
Private Sub Timer1_Timer()
'estinction du timer
Timer1.Enabled = False
'fermeture de word
docword.Application.Quit (0)
End Sub
Private Sub Timer2_Timer()
Dim reSultat As Long
MsgBox (meHwnd)
'Récupération des handle afin de trouver celui de acrobat Reader
Dim CurrWnd As Long
Dim Parent As Long
Dim Length As Long
Dim NomTache As String
Dim NomAAR As String
Dim monHandle As Long
Dim reSultat As Long
' Handle de la fenetre active
CurrWnd = GetWindow(hwnd, GW_HWNDFIRST)
While CurrWnd <> 0
' On prend la fenetre mere de l'application
Parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
NomTache = Space$(Length + 1)
Length = GetWindowText(CurrWnd, NomTache, Length + 1)
' Ici on a le nom de la fenetre qui apparait dans la barre du CTRL+ALT+SUPP
NomTache = Left$(NomTache, Len(NomTache) - 1)
If NomTache <> "" Then
List1.AddItem NomTache + ":" + Str(CurrWnd)
'récupération d'une partie du nom du processus
NomAAR = Left$(NomTache, 14)
'on recherche un certain processus afin de récupérer son handle
If NomAAR = "Acrobat Reader" Then
meHwnd = CurrWnd
'on ferme l'application
reSultat = PostMessage(meHwnd, WM_CLOSE, vbNull, vbNull)
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
Wend
End Sub |
Partager