买衣服哪个网站好便宜:VB中怎样在TextBox中显示当前活动窗口标题

来源:百度文库 编辑:高考问答 时间:2024/04/27 07:50:38
还有,怎样判断一个窗口是否处于活动状态.

你需要使用到很多的API函数。
下面的是一个枚举所有正在运行窗口标题的例子。所有窗口标题会在LIST列表中显示。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function EnableWindow& Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Long)
Private Declare Function FlashWindow Lib "user32" (ByVal hWnd As Long, ByVal bInvert As Long) As Long
Private Declare Function SendMessageA Lib "user32" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
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 SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) 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 getparent Lib "user32" Alias "GetParent" (ByVal hWnd As Long) As Long

Private Sub Command13_Click()
List1.Clear
Dim TN As String
wndow = GetWindow(Me.hWnd, 0)
While wndow <> 0
TN = Space(GetWindowTextLength(wndow) + 1)
If GetWindowText(wndow, TN, GetWindowTextLength(wndow) + 1) > 0 And Left(TN, Len(TN) - 1) <> Me.Caption Then List1.AddItem Left(TN, Len(TN) - 1)
wndow = GetWindow(wndow, 2)
Wend
End Sub

Private Sub Form_Load()
Command13_Click
End Sub

text1.text=form1.caption