Using system; using system. windows. forms; using system. runtime. interopservices; namespace test {public partial class form1: FORM {public form1 () {initializecomponent ();} // The first and third are the [dllimport ("user32.dll")] public static extern intptr findwindow (string lpclassname, string lpwindowname) used to find the window handle ); [dllimport ("user32.dll", entrypoint = "sendmessage")] Private Static extern int sendmessage (intptr hwnd, Int MSG, intptr wparam, string lparam); [dllimport ("user32.dll")] public static extern intptr find1_wex (intptr parent, intptr Childe, string strclass, string frmtext ); [dllimport ("user32.dll")] public static extern bool setforegroundwindow (intptr hwnd); bool a = true; private void button#click (Object sender, eventargs e) {test (); if (A = true) {this.txt text. TEXT = "Lele ...! "; Form2 for2 = new form2 (); for2.showdialog ();} A = false;} hotkeys H = new hotkeys (); Private void form1_load (Object sender, eventargs E) {// enter the CTRL + e shortcut key H. regist (this. handle, (INT) hotkeys. hotkeymodifiers. control, keys. e, callback); // MessageBox. show ("registered");} // reload the wndproc function protected override void wndproc (ref message m) {H. processhotkey (m); // shortcut key message processing base. wndproc (ref m);} // crossProgram Enter public void test () {const int wm_settext = 0x000c; intptr hwnd = findwindow (null, "untitled-Notepad"); intptr htextbox = find1_wex (hwnd, intptr. zero, "edit", null); intptr htextbox2 = find1_wex (hwnd, htextbox, "edit", null); // enter the last obtained handle to obtain the next handle. Sendmessage (htextbox, wm_settext, intptr. Zero, this.txt text. Text);} // method called when the shortcut key is pressed public void callback () {test ();}
}}
Source code download