Cómo utilizar la programación VB para monitorear si una ventana está abierta y forzar su cierre si está abierta.
Opción explícita
Función de declaración privada GetDesktopWindow Lib "user32" () siempre
Función de declaración privada GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Función de declaración privada GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Función de declaración privada FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName como cadena, ByVal lpWindowName como cadena) siempre y cuando
Función de declaración privada PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd Mientras, ByVal wMsg Mientras, ByVal wParam Mientras, ByVal lParam Mientras) Mientras
Const privada WM_CLOSE = & H10
Const privada GW_ CHILD = 5
Const privada GW_HWNDNEXT = 2
Manejo privado siempre
' Supervise la cantidad de texto contenido.
Atenuar CloseCX(1) como cadena
Private Sub Command1_Click()
Si Command1.Caption = "Iniciar monitoreo" Entonces
Timer1.Enabled = True
Command1.Caption = "Pausar monitoreo"
Else
Command1.Caption = "Iniciar monitoreo"
Timer1.Enabled = False
GetWindowText hwnd, strTitle, Len(strTitle)
Si queda$(strTitle, 1) <>vbNullChar Entonces
Para Fx = 0 To UBound(CloseCX, 1)
Si InStr(Left$(strTitle, InStr(1, strTitle, vbNullChar)), CloseCX(Fx)) 0 entonces 'verifique si contiene caracteres definidos'.
Handle = FindWindow(vbNullString, vbNullString, vbNullString, vbNullChar, vbNullChar, vbNullChar, vbNullChar, vbNullChar, vbNullChar))Left$(strTitle, InStr(1, strTitle, vbNullChar)))
PostMessage Handle, WM_CLOSE, 0, 0 'Si contiene un comando de envío y cierre.
End If
Next
End If
'Llama a la función GetWindow para obtener la siguiente ventana
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Bucle
Finalizar función
Private Sub Timer1_Timer()
Llamar a GetAllWindows
Fin del subtítulo