Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Form_Click()
Dim str1 As String * 250
GetWindowText Form1.hwnd, str1, Len(str1)
MsgBox str1
End Sub'这里用变长的为什么不行?
'这样的传str1是地址传递,是不是我在别的API应用时,我只要把字符串的地址传给函数也能得到字符串的内容呢?
Dim str1 As String * 250
GetWindowText Form1.hwnd, str1, Len(str1)
MsgBox str1
End Sub'这里用变长的为什么不行?
'这样的传str1是地址传递,是不是我在别的API应用时,我只要把字符串的地址传给函数也能得到字符串的内容呢?
解决方案 »
- Commandbutton控件
- 送分100分:请讲解一下VB.NET中的托管。
- vb自带的报表的数据源除了接受recordset外,还能接受其他的吗?
- 如何将程序嵌入到mis中去
- 调用存储过程问题
- 妈的,喝过"黑松沙士"的过来接分,说说那个味道像什么
- 是否有像web中的<select>控件呢? 下拉项同时存value和name
- 高手求救,当我打开"外接程序->可视化数据管理器"是,出现了对话框
- 请问form 与 picturebox 的Cls方法用了哪些Api函数? 我想用Api函数代替cls方法。
- 关于Recordset的问题
- 急,我用VB向导工具把VB程序制作成安装文件,在本机上可安装成功,在别的机子上出现 "The Language Dll "vb6chs.dll" could not be found " 的错误提示??
- vb中使用oracle的序列
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPrivate Sub Form_Click()
Dim str1 As String
str1 = String(250, Chr(0))
GetWindowText Form1.hwnd, str1, Len(str1)
str1 = Left(str1, InStr(1, str1, Chr(0)) - 1) '未判断返回值为vbNullString的情况
MsgBox str1, , Len(str1)
End Sub
Declare Function GetActiveWindow Lib "user32" () As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongFunction ActiveWindowCaption() As String
Dim strCaption As String
Dim lngLen As Long
' 创建由空字符填充的字符串。
strCaption = String$(255, vbNullChar)
' 返回字符串长度。
lngLen = Len(strCaption) ' 调用 GetActiveWindow,返回活动窗口的句柄,
' 把句柄连同字符串和字符串长度一起传递给 GetWindowText。
If (GetWindowText(GetActiveWindow, strCaption, lngLen) > 0) Then
' 返回 Windows 写到字符串中的值。
ActiveWindowCaption = strCaption
End If
End Function
'GetWindowText 函数有 3 个参数:窗口句柄;准备接受窗口标题的 NULL 结束字符串;以及该字符串的长度。所调用的系统API是不会为应用程序申请内存的,所以存放结果的缓冲区必须在调用前初始化,无论是定长还是变长的string都需要一块足够大的内存,来存放调用结果GetWindowText Function--------------------------------------------------------------------------------The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application.Syntaxint GetWindowText( HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
ParametershWnd
[in] Handle to the window or control containing the text.
lpString
[out] Pointer to the buffer that will receive the text. If the string is as long or longer than the buffer, the string is truncated and terminated with a NULL character.
nMaxCount
[in] Specifies the maximum number of characters to copy to the buffer, including the NULL character. If the text exceeds this limit, it is truncated.
Return ValueIf the function succeeds, the return value is the length, in characters, of the copied string, not including the terminating NULL character. If the window has no title bar or text, if the title bar is empty, or if the window or control handle is invalid, the return value is zero. To get extended error information, call GetLastError. This function cannot retrieve the text of an edit control in another application.
ResIf the target window is owned by the current process, GetWindowText causes a WM_GETTEXT message to be sent to the specified window or control. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text. If the window does not have a caption, the return value is a null string. This behavior is by design. It allows applications to call GetWindowText without hanging if the process that owns the target window is hung. However, if the target window is hung and it belongs to the calling application, GetWindowText will hang the calling application. To retrieve the text of a control in another process, send a WM_GETTEXT message directly instead of calling GetWindowText. Windows 95/98/Me: GetWindowTextW is supported by the Microsoft® Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.ExampleFor an example, see Sending a Message.Function InformationHeader Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP