|
|
|
|
|
Dicas
|
|
Visual Basic (Forms/MDI)
|
|
|
Título da Dica: Fechando aplicações através do título da janela ( Usando API )
|
|
|
|
Postada em 31/7/2003 por Danilo Onofre
danilonofre@ig.com.br
Private Const WM_CLOSE = &H10 Private Const INFINITE = &HFFFFFFFF
Private Declare Function apiPostMessage _ Lib "user32" Alias "PostMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) _ As Long
Private Declare Function apiFindWindow _ Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) _ As Long
Private Declare Function apiWaitForSingleObject _ Lib "kernel32" Alias "WaitForSingleObject" _ (ByVal hHandle As Long, _ ByVal dwMilliseconds As Long) _ As Long
Private Declare Function apiIsWindow _ Lib "user32" Alias "IsWindow" _ (ByVal hWnd As Long) _ As Long
Private Declare Function apiGetWindowThreadProcessId _ Lib "user32" Alias "GetWindowThreadProcessId" _ (ByVal hWnd As Long, _ lpdwProcessID As Long) _ As Long
Function fCloseApp(lpClassName As String) As Boolean On Error Resume Next Dim lngRet As Long, hWnd As Long, pID As Long
hWnd = apiFindWindow(vbNullString, lpClassName) If (hWnd) Then lngRet = apiPostMessage(hWnd, WM_CLOSE, 0, ByVal 0&) Call apiGetWindowThreadProcessId(hWnd, pID) Call apiWaitForSingleObject(pID, INFINITE) fCloseApp = Not (apiIsWindow(hWnd) = 0) End If End Function
'Exemplo: Private Sub Form_Load() If fCloseApp("Sem nome - Bloco de Notas") = False Then Msgbox "Erro" Else Msgbox "Fechei" End If End Sub
|
|
|
|
|