gettopwindowcaption.txt

来自「一部分关于VB编程的小技巧」· 文本 代码 · 共 32 行

TXT
32
字号
Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Const GW_HWNDNEXT = 2
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As Any, ByVal lpszWindow As Any) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal Hwnd As Long, lpdwprocessid As Long) As Long

Function GetCaption(Hwnd As Long) As String
Dim Wintext As String
Dim slength As Long
Dim retval As Long

'Gets the Length of the Caption
slength = SendMessage(Hwnd, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
'Makes Space for the Caption
Wintext = Space(slength)
'Gets The Caption
retval = SendMessage(Hwnd, WM_GETTEXT, ByVal slength, ByVal Wintext)
'Puts It in GetCaption
GetCaption = Left(Wintext, retval)
End Function

Function GetTopWindowCaption() As String
GetTopWindowCaption = GetCaption(GetForegroundWindow)
End Function



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?