Private Declare Function GetForegroundWindow Lib "user32" () As LongPrivate Declare Function GetFocus Lib "user32" () As LongPrivate Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long
Dim hWnd1 As LongPrivate Sub Command1_Click()End SubPrivate Sub Form_Load()
Label1.AutoSize = True
Timer1.Interval = 500
End SubPrivate Sub Timer1_Timer()
If Me.Hwnd <> GetForegroundWindow Then hWnd1 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
End If
End Sub
'根据窗口句柄得到该窗口的标题
Function getCaption(Hwnd As Long)
Dim hWndlength As Long, hWndTitle As String, A As Long
hWndlength = GetWindowTextLength(Hwnd)
hWndTitle = String$(hWndlength, 0)
A = GetWindowText(Hwnd, hWndTitle, (hWndlength + 1))
getCaption = hWndTitle
End Function
'获得当前焦点所在控件句柄
Public Function GetHwnd() As Long
Dim Hwnd As Long
Dim PID As Long
Dim TID As Long
Dim hWndFocus As Long
Hwnd = GetForegroundWindow
If Hwnd Then
TID = GetWindowThreadProcessId(Hwnd, PID)
AttachThreadInput App.ThreadID, TID, True
GetHwnd = GetFocus
AttachThreadInput App.ThreadID, TID, False
End If
End Function
按钮的代码没填写,我不会写
我想用一个timer判断当前窗体是不是form1,如果是的话则不记录句柄,如果不是则记录句柄。然后点击按钮发送按键到句柄记录的控件。各位大大要给力啊!!!
解决方案 »
- 请教VB公式求和
- 鼠标右击时触发左击事件?
- txt导入到access
- 各位谁帮我看看,在多客户端连接情况下如何才能让服务器反馈的信息返回原来的客户端上,而现在却总是每次反馈信息到最后一个连接的客户端上
- 关于软件发布的几个问题(每个问题20分,UP没分)
- 两个数值相加的问题
- 在VB6中如何将SQL7的数据库导成*.DBF数据库,或将DBF数据库导入SQL7中紧急求助
- vb能不能实现将数据生成图片文件,比如GIF格式的
- 关于setupfactory 打包mdac_typ.exe的问题
- 用WINSOCK读出本机IP?
- 正则表达式如果想提取一段字符里的中英文字符外加空格符/括号/全角字符(用来做文件名)要怎么写?
- 怎么把焦点发送到其他窗口上?
Private Declare Function SetForegroundWindow Lib "user32" _ (ByVal hwnd As Long) As Long
'代码
SetForegroundWindow 句柄
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
'代码
SetForegroundWindow 句柄