VB.net发送消息到控制台盒
大家好,我正在尝试从我的 vb 程序发送一些文本到控制台框(dos 框),但我似乎无法让它工作。
这是我当前的代码:
Dim blah As Long
Private Const WM_GETTEXT As Integer = &HD
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
blah = FindWindow1(vbNullString, "Form1")
blah = FindWindowEx(blah, vbNullString, "ConsoleWindowClass", vbNullString)
Debug.Print(blah)
SendMessage(blah, WM_SETTEXT, 200, "A")
虽然这确实有效,但它只在标题栏上放置一个 A ,而不是在控制台内。
任何帮助都会很棒! :o)
大卫
Hey all, i am trying to send some text to a console box (dos box) from my vb program but i can not seem to get it working.
Here is my current code:
Dim blah As Long
Private Const WM_GETTEXT As Integer = &HD
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
blah = FindWindow1(vbNullString, "Form1")
blah = FindWindowEx(blah, vbNullString, "ConsoleWindowClass", vbNullString)
Debug.Print(blah)
SendMessage(blah, WM_SETTEXT, 200, "A")
Though that does work, it only puts a A for the title bar and not within the console.
Any help would be great! :o)
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有尝试过,但我想你可能想看看 AttachConsole 将您的进程附加到命令行进程的控制台。然后您应该能够使用Console.WriteLine 和我假设的类似方法。
您可以在 PInvoke 页面。
I've not tried it but I think you might want to look at AttachConsole to attach your process to the console of the command line process. Then you should be able to use the
Console.WriteLine
and similar methods I'd assume.You can find a sample (in C#, but should be easy to convert to VB using one of the online converters) on the PInvoke page.