VB 获取窗口句柄
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB 获取窗口句柄相关的知识,希望对你有一定的参考价值。
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Timer1_Timer()
Dim hwnd As Long
hwnd = FindWindow("elementclient window", "element client")
Print hwnd
End Sub
这样写游戏双开就崩溃了,
怎么写是不是要用到别的函数详细解释下,我菜鸟多多担待
1。新建一个标准VB6的EXE工程,加入Timer控件
2。API函数的声明
private Declare Function GetForegroundWindow Lib "user32" () as Long
private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (byval hwnd as Long, _
byval lpString as string, byval cch as Long) as Long
3。在窗体的Load事件中加入代码:
Private Sub Form_Load()
Timer1.Interval = 100 '设置间隔时间
End Sub
4。在Timer控件中的Timer事件中加入代码:
Private Sub Timer1_Timer()
Static CurrentHwnd As Long
Dim ForegroundWindowHwnd As Long
Dim sText As String * 255
ForegroundWindowHwnd = GetForegroundWindow
If ForegroundWindowHwnd = CurrentHwnd Then Exit Sub
CurrentHwnd = ForegroundWindowHwnd
If CurrentHwnd <> hwnd Then
Caption = "ActiveWidow's Caption: " & Left$(sText, GetWindowText(CurrentHwnd, sText, 255))
Else
Caption = "ActiveWindow's Caption: Form1"
End If
End Sub本回答被提问者采纳
以上是关于VB 获取窗口句柄的主要内容,如果未能解决你的问题,请参考以下文章