如何用VB获取Windows最顶端窗体的标题?

请问如何用VB的API获取Windows最顶端窗体的标题?

最好有代码

谢谢先。
哪个是窗体标题的变量?

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

Private Sub Command1_Click()
Dim hwnd As Long
Dim str1 As String
hwnd = GetForegroundWindow
str1 = Space(100)
GetWindowText hwnd, str1, 100
str1 = Trim(str1)
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-06-30
Private Sub Form_Load()
On Error Resume Next
Call PutWindowOnTop(Me)

End Sub
模块中
Option Explicit

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

Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1

Public Function PutWindowOnTop(pFrm As Form)
Dim lngWindowPosition As Long

lngWindowPosition = SetWindowPos(pFrm.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

End Function