不好意思,正正经经的纠正一下。 因为一直用一个公用库里面的这个函数来实现类似功能,久而久之竟然把它当成了一个API。 准确的说对应的API 应该是GetWindowTextPrivate Function GetWindowCaption(ByVal hwnd As Long) As String Dim strText As String, ret As Long ret = GetWindowTextLength(hwnd) If ret > 0 Then strText = Space(ret) GetWindowText hwnd, strText, ret + 1 strText = Left(strText, ret) GetWindowCaption = strText Else GetWindowCaption = "" End If End Function
如果是MDI的话,可以用ActiveForm.Caption获得活动窗口的Caption
在每一个可能获得焦点的窗体中,调用form_gotfocuss事件 form_gotfocus '主窗体的label控件属性变更 MainForm.labelObj.caption =form.caption end
GetWindow API可以帮助你获取指定句柄的窗口的标题.
至于实时监测,用一个timer实现即可
因为一直用一个公用库里面的这个函数来实现类似功能,久而久之竟然把它当成了一个API。
准确的说对应的API 应该是GetWindowTextPrivate Function GetWindowCaption(ByVal hwnd As Long) As String
Dim strText As String, ret As Long
ret = GetWindowTextLength(hwnd)
If ret > 0 Then
strText = Space(ret)
GetWindowText hwnd, strText, ret + 1
strText = Left(strText, ret)
GetWindowCaption = strText
Else
GetWindowCaption = ""
End If
End Function
在每一个可能获得焦点的窗体中,调用form_gotfocuss事件
form_gotfocus
'主窗体的label控件属性变更
MainForm.labelObj.caption =form.caption
end