VC关于获得窗体标题的具体做法

来源:百度知道 编辑:UC知道 时间:2024/06/25 08:20:56
我大概知道是用GetForegroundWindow获得最前窗体句柄,再用getwindowtext获取标题 可本人水平有限也没有MSDN,不知道函数的具体用法。假如把获得的窗体标题保存在str字符中 请问具体代码怎么超做?万分感激!假设需要获得的窗体是个VB窗体!
谢谢2位 不过我想补充下 当我使用了.
CString str;
HWND pWnd =::GetForegroundWindow();
::GetWindowText(pWnd,(LPTSTR)&str,256);
SetDlgItemText(IDC_ADDRESS,str);
捕捉了窗体标题以后窗体被自动强行关闭 不知道是什么原因 答案满意者我这100分就献上了 谢谢 也感谢2位

CString str;
HWND pWnd =::GetForegroundWindow();
::GetWindowText(pWnd,str.GetBuffer(256),256);
::SetDlgItemText(pWnd,IDC_ADDRESS,str);

----- 试试修改后的 -------

CString wndtext;
HWND pWnd = GetForegroundWindow();
ShowWindow(pWnd, nCmdShow);
UpdateWindow(pWnd);
GetWindowText(pWnd,(LPTSTR)&wndtext,1000);

1000是要COPY的最多字符数,你可以自己指定

上面是VC,VB的例程如下

Dim len As Integer = API.GetWindowTextLength(hWnd)
If len > 0 Then
Dim b As New System.Text.StringBuilder(ChrW(0), len + 1)
Dim ret = API.GetWindowText(hWnd, b, b.Capacity)
If ret <> 0
Then
Return b.ToString Else
Throw New API.Win32APIException End If Else
Dim ex As New API.Win32APIException
If ex.Nat