再问:如何向打开的记事本写入一段文本???

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

但是:
发现在第一次有效果,但关掉记事本后,再执行一次,记事本里没什么反应,空白一片,怎么回事呢???




...全文
125 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yzg100 2005-11-01
不用那么麻烦的,楼上已解。
  • 打赏
  • 举报
回复
hamadou 2005-11-01
Dim myprocess As New Process
myprocess.StartInfo.FileName = "f:\1.txt"
myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myprocess.Start()
myprocess.WaitForInputIdle(1000)
If myprocess.Responding Then
SendKeys.SendWait("123456")
Else
myprocess.Kill()
End If
  • 打赏
  • 举报
回复
相关推荐
发帖
VB
加入

1.6w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
申请成为版主
帖子事件
创建了帖子
2005-11-01 01:45
社区公告
暂无公告