2013-12-21
展开全部
他们都好麻烦!你只是需要获取窗体名字而已是吧?很简单'在模块中添加下面的API函数Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 然后在FORM1窗体添加个command按钮和label标签Private Sub Command1_Click()
Dim 窗口句柄 As Long
窗口句柄 = FindWindow(vbNullString, "窗口标题")
Label1.Caption = 窗口句柄
End Sub 这样就行咯这样就可以获取到了
Dim 窗口句柄 As Long
窗口句柄 = FindWindow(vbNullString, "窗口标题")
Label1.Caption = 窗口句柄
End Sub 这样就行咯这样就可以获取到了
2013-12-21
展开全部
窗口必须是顶置的Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private 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 Form_Load()
Label1.AutoSize = True
Timer1.Interval = 500
End SubPrivate Sub Timer1_Timer()
hWnd1 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
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
Private 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 Form_Load()
Label1.AutoSize = True
Timer1.Interval = 500
End SubPrivate Sub Timer1_Timer()
hWnd1 = GetForegroundWindow() '得到活动窗口的句柄
Label1.Caption = getCaption(hWnd1)
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-21
展开全部
在VB中要实现查找文件功能,我们可以利用VB的DIR函数进行递归来实现。每次使用DIR函数后,比较是否有要查找的文件,再检查是否有...程序与注释如下: 1.在窗体中加一命令按钮Command1,Caption=查找示例,双击此按钮,写如下代码: Private Sub Command1-Click
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-21
展开全部
GetWindowText:取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)返回值private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询