关于SetWindowText和 GetWindowText的用法,折腾了好久了!还是没解决,请教大家看下哪里出问题了

mwm_ok 2009-06-15 09:41:42
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hWnd As Integer
Shell("C:\WINDOWS\system32\calc.exe", AppWinStyle.NormalFocus)
hWnd = FindWindow(vbNullString, "计算器")

Dim strText As String
strText = Space(30)

If hWnd Then
GetWindowText(hWnd, strText, 30)
MessageBox.Show(strText, "获取标题") 'strtext 没有显示出标题名称
SetWindowText(hWnd, "修改内容") '标题未修改成 “修改内容”,为空
End If

End Sub
...全文
1073 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tegusi 2010-09-15
  • 打赏
  • 举报
回复
LS弄错了
tegusi 2010-09-15
  • 打赏
  • 举报
回复
ggggggdd[b][/b]
mwm_ok 2009-06-15
  • 打赏
  • 举报
回复
现在又出现了个问题 还得请教下您:

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Integer

Public Const WM_GETTEXT = &HD

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hWnd As Integer
Dim hwnd1 As Integer

Shell("C:\WINDOWS\system32\calc.exe", AppWinStyle.NormalFocus)
hWnd = FindWindow(vbNullString, "计算器")

Dim strText As String
strText = Space(30)

Dim strText1 As String
strText1 = Space(30)

If hWnd Then

GetWindowText(hWnd, strText, 30)‘标题可以通过这得到了 但是好像SendMessage 也可以取到标题的 为什么这个 又不行了呢?SendMessage(hWnd, WM_GETTEXT, 30, strText)

hwnd1 = FindWindowEx(hWnd, 0, "Edit", "0.")
GetWindowText(hwnd1, strText1, 30)‘这段话也取不到内容 得到的是空的 上面那个GetWindowText可以取到标题 为什么这个就取不到内容了呢?

MessageBox.Show(strText, "获取标题")
MessageBox.Show(strText1, "获取内容")

' SetWindowText(hWnd, "修改内容")
End If
mwm_ok 2009-06-15
  • 打赏
  • 举报
回复
谢谢!非常感谢!
yanlongwuhui 2009-06-15
  • 打赏
  • 举报
回复
API声明有问题,参考如下:
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String) As Integer
yanlongwuhui 2009-06-15
  • 打赏
  • 举报
回复
API声明参考如下:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Object) As Integer

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧