vb用SETTEXT改变TEdit编辑框内容
句柄已经找到了,但编辑框没有一点反应代码:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long'Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long'Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 LongPrivate Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As LongPrivate Const BN_CLICKED = 0Private Const BM_CLICK = &HF5Private Const WM_SETTEXT = 12Private Const WM_GETTEXT = &HD&Private Const WM_KEYDOWN = &H100 Private Sub Command1_Click()Dim hwnd As Long, hc As Long, hcc As Long, hccc As Long, hc4 As Long, hc5 As Long, hw As LongDim sBuffer As Stringhwnd = FindWindow(vbNullString, "安装 - EQK 版本 1.0")'MsgBox hwnd'hwnd = FindWindow(vbNullString, "1.txt - 记事本")hc = FindWindowEx(hwnd, 0, "TNewNotebook", vbNullString) 'MsgBox hchcc = FindWindowEx(hc, 0, "TNewNotebookPage", vbNullString)'MsgBox hcchccc = FindWindowEx(hcc, 0, "TNewNotebook", vbNullString)'MsgBox hccchc4 = FindWindowEx(hccc, 0, "TNewNotebookPage", vbNullString)hc5 = FindWindowEx(hc4, 0, "TEdit", vbNullString)hw = SendMessage(hc5, WM_SETTEXT, 0, App.Path & "EQK")'MsgBox hc5'sBuffer = Space(255)'Call SendMessage(hc, WM_GETTEXT, 255, ByVal sBuffer)'sBuffer = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)'MsgBox sBuffer End Sub
没有你的环境。无法真实帮你测试,但有2个问题
1、首先,你要保证所有的handle不能为0
在win10环境下,记事本的Edit框的类不再是TEdit.它就是Edit
你可以用spyxx看下程序得到的句柄与实际的是否一致
2.WM_SETTEXT必须是值,你的
hw = SendMessage(hc5, WM_SETTEXT, 0, App.Path & "EQK")
结果肯定不对。它传的是地址
要用
hw = SendMessage(hc5, WM_SETTEXT, 0, ByVal App.Path & "EQK")
下一篇:我电脑配置能玩武装突袭3吗?
上一篇:java版地图导入网易我的世界