VB 有关SendMessage与EnumWindow

我是个初学者,现在遇到了一些难题,所以请各位高手帮帮忙,如下:哪位兄弟可以给个用FindWindow,EnumWindow等函数得到文本框的句柄然后用SendMessag... 我是个初学者,现在遇到了一些难题,所以请各位高手帮帮忙,如下:
哪位兄弟可以给个用FindWindow,EnumWindow等函数得到文本框的句柄
然后用SendMessage发送消息的实例,后面有说明的更好!
SendMessage发送时要发送中文的!

还有不要在网上复制过来哦!因为网上的我都找遍了,我在这里先谢谢了,暂时先给出100分,完成后再加100(我想各位有心帮我的话也肯定不是为了分数而来)
谢谢一楼的老兄,不过你的SendMessage只能在文本里输入中文,如果在Wowd里面,它就不起作用了
展开
 我来答
匿名用户
2008-11-26
展开全部
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
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
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) 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()
If Command1.Caption = "开始抓取(&S)" Then
Timer1.Enabled = True
Command1.Caption = "停止抓取(&S)"
Else
Timer1.Enabled = False
Command1.Caption = "开始抓取(&S)"
End If
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H1 Or &H2
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
Dim tPoint As POINTAPI
Dim hWin As Long
Dim str As String * 255
Dim Abc As String * 64000
Dim Txt(64000) As Byte
GetCursorPos tPoint
hWin = WindowFromPoint(tPoint.x, tPoint.y)
If hWin = Me.hwnd Or hWin = Command1.hwnd Or hWin = Command2.hwnd Or hWin = Text1.hwnd Then Exit Sub
GetClassName hWin, str, 255
SendMessage hWin, &HD, 64000, Txt(0)
Label1.Caption = "窗口名柄" & hWin
Label2.Caption = "窗口类" & str
Text1.Text = StrConv(Txt, vbUnicode)
End Sub

-------------------以上是获得句柄

Private Const WM_CHAR = &H102
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Command1_Click()
SendMessage hwndText, WM_CHAR, AscW("科"), ByVal 0
End Sub
------------发送单个中文字符
下面可以发送多个中文字符 到记事本

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long

Private Sub Command1_Click()
Dim s As String
Dim FT_hWnd As Long
Dim ID_Control_hWnd As Long

s = "test" & vbCrLf & "中文啊"

FT_hWnd = FindWindow("Notepad", vbNullString)
If FT_hWnd = 0 Then
MsgBox "False", vbInformation, "Title"
End
End If

ID_Control_hWnd = GetDlgItem(FT_hWnd, &HF)
SendMessage ID_Control_hWnd, WM_SETTEXT, 0, ByVal s
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式