|
Sujet : [VB] fonctions de kernel32.dll |
| trictrac |
Je me suis super inspire du code que tu m'as donne, et voila ce que ca donne, pour le lancement de acrobat reader 5.0.. il le lance, mais refuse de le tuer.
PS: non, c'est po si urgent, mais disons que pour l'instant je suis en stage, et que j'ai plus que ca pour finir mon petit prog... alors je ne peux pas ne plus rien faire d'ici ce soir
Code :
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
- Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
- Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
- Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
- Private Declare Function GetDesktopWindow Lib "user32" () As Long
- Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
- Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
- Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
- Const GW_HWNDNEXT = 2
- Dim mWnd As Long
- Private CurrentPath$
- Function InstanceToWnd(ByVal target_pid As Long) As Long
- Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
- 'Find the first window
- test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
- Do While test_hwnd <> 0
- 'Check if the window isn't a child
- If GetParent(test_hwnd) = 0 Then
- 'Get the window's thread
- test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
- If test_pid = target_pid Then
- InstanceToWnd = test_hwnd
- Exit Do
- End If
- End If
- 'retrieve the next window
- test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
- Loop
- End Function
- Private Sub Form_Load()
- Dim Pid
- On Error GoTo ErrHanlder
- Pid = Shell("C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", 1)
- DestroyWindow mWnd
- ErrHanlder:
- If Err.Number = 76 Then
- MsgBox "Acrobat Reader 5.0 doit etre à cet endroit: C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe"
- End If
- End
- End Sub
|
|
| trictrac |
Je me suis super inspire du code que tu m'as donne, et voila ce que ca donne, pour le lancement de acrobat reader 5.0.. il le lance, mais refuse de le tuer.
PS: non, c'est po si urgent, mais disons que pour l'instant je suis en stage, et que j'ai plus que ca pour finir mon petit prog... alors je ne peux pas ne plus rien faire d'ici ce soir
Code :
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
- Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
- Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
- Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
- Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
- Private Declare Function GetDesktopWindow Lib "user32" () As Long
- Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
- Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
- Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
- Const GW_HWNDNEXT = 2
- Dim mWnd As Long
- Private CurrentPath$
- Function InstanceToWnd(ByVal target_pid As Long) As Long
- Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
- 'Find the first window
- test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
- Do While test_hwnd <> 0
- 'Check if the window isn't a child
- If GetParent(test_hwnd) = 0 Then
- 'Get the window's thread
- test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
- If test_pid = target_pid Then
- InstanceToWnd = test_hwnd
- Exit Do
- End If
- End If
- 'retrieve the next window
- test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
- Loop
- End Function
- Private Sub Form_Load()
- Dim Pid
- On Error GoTo ErrHanlder
- Pid = Shell("C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe", 1)
- DestroyWindow mWnd
- ErrHanlder:
- If Err.Number = 76 Then
- MsgBox "Acrobat Reader 5.0 doit etre à cet endroit: C:\Programs\Adobe\Acrobat 5.0\Reader\AcroRd32.exe"
- End If
- End
- End Sub
|
|