VB 读取十六进制窗口句柄

来源:百度知道 编辑:UC知道 时间:2024/05/10 09:08:00
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Text1.Text = GetForegroundWindow()

我用以上这句代码可以获得大多数焦点窗口的句柄,可是不能获得我最想要的那个窗口的句柄,因为那个窗口是一个游戏窗口,我相信这个游戏窗口的句柄应该是十六进制的,因为我使用以下代码发现的:

Option Explicit
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Sub Command1_Click()
Dim WinHandle As Long, sWindow As String * 26
Dim ParHandle As Long

用GetForegroundwindow

函数功能:该函数返回前台窗口(用户当前工作的窗口)。系统分配给产生前台窗口的线程一个稍高一点的优先级。
函数原型:HWND GetForegroundwindow(VOID)
参数:无。
返回值:函数返回前台窗回的句柄。

有了句柄就可以调用GetWindowText 获得标题进行比较了