再问:如何向打开的记事本写入一段文本???
zwq78 2005-11-01 01:45:48 之前有问:
代码如下:
Dim p As System.Diagnostics.Process = System.Diagnostics.Process.Start("notepad.exe")
Dim str As String = ReadCurrRecord(ds, currMasterID)
SendMessage(p.MainWindowHandle.ToInt32, WM_SETTEXT, 0, str)
为什么记事本里总是空的呢????
回复人: pupo(泡泡) ( ) 信誉:105 2005-10-26 10:00:04 得分: 20
Public Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As IntPtr, ByVal wCmd As Integer) As IntPtr
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Public Const WM_SETTEXT = &HC
Public Const GW_CHILD = 5
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As Process = Process.Start("notepad")
Dim hwnd As IntPtr = GetWindow(p.MainWindowHandle, GW_CHILD)
SendMessage(hwnd, WM_SETTEXT, 0, "abcd")
End Sub
但是:
发现在第一次有效果,但关掉记事本后,再执行一次,记事本里没什么反应,空白一片,怎么回事呢???