VB如何获取程序标题
就是程序在后台运行的时候,能记录当前窗口上的标题。把标题记录到TEXT1.TEXT文本框中。该如何实现。。谢谢各位大虾。...
就是程序在后台运行的时候,能记录当前窗口上的标题。把标题记录到TEXT1.TEXT文本框中。该如何实现。。谢谢各位大虾。
展开
4个回答
展开全部
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
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
Dim WithEvents Tim As Timer
Private Sub Form_Load()
Set Tim = Controls.Add("vb.timer", "tim")
Tim.Interval = 500: Tim.Enabled = True
SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3 '使窗体置于最顶层,便于查看
End Sub
Private Sub Tim_Timer()
Dim hWnd As Long, st As String * 100
hWnd = GetForegroundWindow '得到活动窗口的句柄
GetWindowText hWnd, st, 100 '得到活动窗口的标题
Text1 = st
End Sub
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
Dim WithEvents Tim As Timer
Private Sub Form_Load()
Set Tim = Controls.Add("vb.timer", "tim")
Tim.Interval = 500: Tim.Enabled = True
SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3 '使窗体置于最顶层,便于查看
End Sub
Private Sub Tim_Timer()
Dim hWnd As Long, st As String * 100
hWnd = GetForegroundWindow '得到活动窗口的句柄
GetWindowText hWnd, st, 100 '得到活动窗口的标题
Text1 = st
End Sub
展开全部
Dim Caption,HWnd
HWnd = HWindow.GetForeGround() '得到活动窗口的句柄
hwstr = HWindow.GetCaption(HWnd)
hwstr 就是获得的标题内容,
上面两个用到的函数需要在模块里面定义才能使用
HWnd = HWindow.GetForeGround() '得到活动窗口的句柄
hwstr = HWindow.GetCaption(HWnd)
hwstr 就是获得的标题内容,
上面两个用到的函数需要在模块里面定义才能使用
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
TEXT1.TEXT=MsgBox Form1.Caption '获得当前窗口标题栏中的名字
End Sub
TEXT1.TEXT=MsgBox Form1.Caption '获得当前窗口标题栏中的名字
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
TEXT1.TEXT=Form1.Caption
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询