简体   繁体   English

仅通过焦点将消息发送到任何Windows文本框

[英]Sending a message to any windows textbox just by focus

I need to know how I can send a message to any text box of windows. 我需要知道如何将消息发送到Windows的任何文本框。

If a focus the google chrome url textbox, then I will "auto paste" the message, or if I focus a Word Document string, or notepad, or anything! 如果将焦点放在google chrome url文本框上,那么我将“自动粘贴”邮件,或者如果我将Word Document字符串,记事本或其他任何内容作为焦点!

I got a code ho sends by setting the iHwnd , findwindow and findwindowex , but I need to set any time I want to change the final program, and thats why I need an automatic program "focus based". 我通过设置iHwndfindwindowfindwindowex获得了发送的代码,但是我需要随时更改最终程序,这就是为什么我需要自动程序“基于焦点”的原因。

Here is what I have so far... 这是我到目前为止所拥有的...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim iHwnd As IntPtr = FindWindow("notepad", vbNullString) 
    Dim iHwndChild As IntPtr = FindWindowEx(iHwnd, IntPtr.Zero, "Edit", vbNullString) 
    SendMessage(iHwndChild, WM_SETTEXT, 0, "Hello World!") 
End Sub

Sorry for my bad english! 对不起,我的英语不好!

SendMessage is always going to require a specific window handle, or broadcast to all top level windows. SendMessage总是需要特定的窗口句柄,或广播到所有顶级窗口。 To continue with your current code, you could first try to retrieve the active window's handle with GetActiveWindow or similar function. 要继续当前的代码,您可以首先尝试使用GetActiveWindow或类似函数来检索活动窗口的句柄。

Alternately, you could experiment with the SendKeys class to send your text. 或者,您可以尝试使用SendKeys类发送文本。 SendKeys always targets the currently active control (as if the user were typing directly on the keyboard), so you don't need to concern yourself with finding window handles or titles. SendKeys始终以当前活动的控件为目标(就像用户直接在键盘上键入)一样,因此您无需担心查找窗口句柄或标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM