VB.net发送消息到控制台盒

发布于 2024-09-26 23:49:36 字数 585 浏览 5 评论 0原文

大家好,我正在尝试从我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天邊彩虹 2024-10-03 23:49:36

我还没有尝试过,但我想你可能想看看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文