Advertisement
4_2005-2006 Windows System Services #162843

SwitchToThisWindow

Another way of changing the focus to a particular window, using an un-documented API called SwitchToThisWindow.This API works on Windows 3x, Windows 9x/ME and Windows 2000. I have found it much more reliable than Setfocus/SetFocusAPI or SetForegroundWindow

AI

Podsumowanie AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kod źródłowy
original-source
' Library imports
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SwitchToThisWindow Lib "user32" (ByVal hWnd As Long, ByVal hWindowState As Long) As Long
' Function to locate and focus on a MsgBox
Public Function GetMessageWindow() As Long
Dim hMessageBox As Long
' First get the message box's handle
hMessageBox& = FindWindow("#32770", vbNullString)
If hMessageBox Then
 ' Set focus on the message box
 GetMessageWindow& = SwitchToThisWindow
  (hMessageBox, vbNormalFocus)
Else
 GetMessageWindow& = 0
End If
End Function
' Calling the GetMessageWindow function 
RetVal& = GetMessageWindow()
If RetVal& Then
 ' Do something like SendKeys{Enter} 
End If
 
Oryginalne komentarze (3)
Odzyskane z Wayback Machine