External input system - similar to a universal plug-in

xiaoxiao2021-03-05  25

Many friends study on how to control the values ​​of controls such as the text box in the target program, and the accidental opportunity, I also need to do such a stuff, spending a night study finally getting, huh, huh, here to share with you.

The code ideas are not complicated. After the program runs, the handle of the target form is used, and then use the control on the ENUMCHILDWINDOWS to enumerate the "Send message to the target implementation with the PostMessage.

The implementation environment is Borland C Builder if you need to modify it with VC.

//

-------------------------------------------------- -------------------------

#include

<

vcl.h

>

#pragma hdrstop #include

"

Main.h

"

//

-------------------------------------------------- -------------------------

#pragma package (smart_init) #pragma link

"

Trayicon

"

#pragma resource

"

* .dfm

"

TForm1

*

Form1; hwnd heditlist [

64

];

int

Heditcount;

//

-------------------------------------------------- -------------------------

__fastcall tform1 :: tform1 (tcomponent

*

Owner: TFORM (OWNER)

{:: RegisterhotKey (Handle, 1000, Mod_Control, 'g'); // g: Get window}

//

-------------------------------------------------- -------------------------

LResult Callback NumchildProc (HWND HWND, LPARAM)

//

Enumerate the callback function of all controls

{Char Text [128], Title [128]; GetClassName (hwnd, text, 128); // sendMessage (hwnd, wm_gettext, (wparam) 128, (lparam) title); Form1-> listbox1-> items-> add (text); HeditList [heditcount] = hWnd; // form1-> listbox1-> items-> add (title); HEDITCOUNT ; return true; // true means continuing to take, FALSE does not take}

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: getActiveWindow ()

{Char szCaption [255]; hWindow = GetForegroundWindow (); GetWindowText (hWindow, szCaption, 255); Edit3-> Text = szCaption; // :: SetForegroundWindow (Handle); // Activate the current window // ShowWindow (Handle, SW_RESTORE ); // Application-> bringtofront (); trayicon1-> restore ();} //

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: sendtoedit ()

{// setwindowtext (hwindow, "jjjjjj"); // hWnd Hedit = :: FindWindowEx (hwindow, null, edit1-> text.c_str (), null); // Find Edit Handle hWnd Hedit = HEDITLIST [listbox1-> ItemIndex]; if (HEDIT == NULL) Return; if (: getforegroundwindow ()! = Hwindow) :: setForegroundWindow (hwindow); // Activate the current window :: setfocus (hedit); // to focus char * msgsend; :: SendMessage (Hedit, WM_SETTEXT, 255, (LPARAM) Edit2-> text.c_str ()); // :: PostMessage (Hedit, WM_KEYUP, VK_RETURN, 0); :: PostMessage (Hedit, WM_KeyDown, vk_return, 0) ; //: PostMessage (Hedit, WM_Keyup, vk_return, 0);

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: Button1Click (TOBJECT

*

Sender)

{If (hwindow == null) {showMessage ("Please use Ctrl G to get the target form"); return;} // showMessage (edit2-> text); sendtoEdit ();

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: wndproc (tMessage

&

MSG)

//

Heat bond here

{If (msg.msg == wm_hotKey) // Get hot key message {if (loword (msg.lparam) == mod_control & brown (msg.lparam) == 'g') {getActiveWindow (); if (hwindow = = Null; listbox1-> clear (); heditcount = 0; enumchildWindows (hwindow, (int (__stddcall *) ()) NumchildProc, 0); // enumerate all controls all controls}} else TForm :: WNDPROC (Msg); // transfer the message down} //

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: Button2Click (TOBJECT

*

Sender)

{Hide ();

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: listbox1click (TOBJECT

*

Sender)

{Edit1-> text = listbox1-> items-> strings [listbox1-> itemindex];

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: edit3dblclick (TOBJECT

*

Sender)

{Edit3-> text = "";

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: edit1dblclick (TOBJECT

*

Sender)

{Edit1-> text = "";

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: edit2dblclick (TOBJECT

*

Sender)

{Edit2-> text = "";

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: formcreate (TOBJECT

*

Sender)

{SetWindowPOS (Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); // Settings the window is at the top. }

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: hide ()

{Trayicon1-> minimize ();

//

-------------------------------------------------- ------------------------- void

__fastcall tform1 :: show ()

{Trayicon1-> restore ();

//

-------------------------------------------------- -------------------------

Void

__fastcall tform1 :: trayicon1click (TOBJECT

*

Sender)

{Show ();

转载请注明原文地址:https://www.9cbs.com/read-34262.html

New Post(0)