Home > Back-end >  Delphi how to access the external program Edit loses focus event
Delphi how to access the external program Edit loses focus event

Time:11-18

Form1 and I have a form a form Form2, Form1 program to monitor the inside of the Form2 edit (there are two edit, edit1 and edit2), when the focus from the edit1 moves to edit2 or from edit2 move to edit1, then showmessage focus content of the text box, before you leave the code in the Form1, Form2 only controls, could you tell me how to implement

CodePudding user response:

Form2 if triggered the lost focus event, send a message to Form1, then post-processing Form1 receives the message,

CodePudding user response:

Feeling is want to make a plugin

CodePudding user response:

reference 1st floor nikotin response:
if triggered in Form2 loses focus, just send a message to Form1, then Form1 post-processing, received the message

Could have any code, please refer to this to me I just need to receive prior to the events to handle to specify the edit loses focus to using findcontrol method to cast as Tedit found that returned to NIL online answer said two different process memory control so can't transfer directly

CodePudding user response:

refer to the second floor BlueStorm response:
feeling is want to make a plugin

Do you have done, I this is my company's software, there is no source only installation package, so just do plugins

CodePudding user response:

This software didn't do it

CodePudding user response:

Last time didn't watch carefully, so you are two different programs, said my train of thought: did you see the Edit window, if there is a window, went into a dynamic libraries in the target program, and then the dynamic library set a hook function to contact window, if found to be WM_KILL_FOCUS news, suggests the target window lost focus, and then you send a message to inform you the procedure, specific code search on the net, you should be a lot of,

CodePudding user response:

refer to 6th floor nikotin response:
last time didn't watch carefully, so you are two different programs, said my train of thought: did you see the Edit window, if there is a window, went into a dynamic libraries in the target program, and then the dynamic library set a hook function to contact window, if found to be WM_KILL_FOCUS news, suggests the target window lost focus, and then you send a message to inform you application, specific code search on the net, you should be a lot of,

I made the keyboard monitoring of hook because I can intercept keyboard shortcuts is F12 submitted as for external application of the edit loses focus I do not see a lot of is all about the keyboard or send a message to Form2 few judgment loses focus again I have to get a handle to the edit, you see if you can spare a little bit of your precious time to help me analyze the project a little thank you

CodePudding user response:

I have several years don't do this, details may not be accurate, but today I saw, with spy++ VCL the Edit loses focus, Edit WM_KILL_FOCUS message will be sent to the window, so the key is that you can hook function inside to capture this news, if you can, then judge the news is the window of the corresponding Edit, if is the Edit loses focus, if road closed, another method is to inject the target after the process, the Edit window procedure to a window procedure, you yourself wrote your own window procedure to adjust the original window procedure, so that all through the Edit messages you will receive, left nothing but the message can figure out whether the loses focus,

CodePudding user response:

refer to the eighth floor nikotin response:
I have several years don't do this, the details may not be accurate, but today I saw, with spy++ VCL the Edit loses focus, Edit WM_KILL_FOCUS message will be sent to the window, so the key is that you can hook function inside to capture this news, if you can, and then judge the news is the window of the corresponding Edit, if is the Edit loses focus, if road closed, another method is to inject the target after the process, the Edit window procedure to a window procedure, you yourself wrote your own window procedure to adjust the original window procedure, so that all through the Edit messages you will receive, left nothing but the message can figure out whether the loses focus,

Eldest brother more than half of what you said I probably can understand the meaning, if you can recommend me an article, I find something is not clear that do you say this,

CodePudding user response:

You search control subclassing, there should be a lot of code can refer to, is I said the second approach,

CodePudding user response:

The simplest method, through the mouse coordinates to solve
The first step: get FORM2 window handle coordinates
Step 2: obtain FORM2 edit1 edit form coordinates within 2
Step 3: direct judgment both ED1, equal and ED2 coordinates is solved

CodePudding user response:


The
reference 11 floor baody8 reply:
the most simple way to solved through the mouse coordinates
The first step: get FORM2 window handle coordinates
Step 2: obtain FORM2 edit1 edit form coordinates within 2
Step 3: determine both ED1 directly, and whether the coordinates of ED2 equal solved

Don't mean that, for example, I typing edit1 is I want to determine when the input to complete so judged by loses focus

CodePudding user response:

Frontal injection hook memory address jump to their own showmessage running hook code (above 5 bytes) jump back to the original code,
The key problem is the od the disassembly to find key call memory address edt loses focus,

CodePudding user response:

Can be obtained by the location of the mouse, specify a control handle, in this way, the control of events can be obtained,

CodePudding user response:

This kind of problem that across processes, I think I should need Windows hook function to solve it, may have a better solution,
 
The library MyHook;

USES the
SysUtils,
Windows,
Messages,
Classes;

{$R *. Res}

Var
Hook: HHook=0;

The function MyWndProc (ACode: Integer; AWParam: LongInt; ALParam: LongInt) : LResult; Stdcall;
Var
Log: TextFile;
SFN: string;
STxt: an array of char [0.. 255];
MSG: PCWPStruct;
The begin
If (ACode<0) then
The begin
Result:=CallNextHookEx (hook, ACode AWParam, ALParam);
exit;
end;

If (ACode<> Then HC_ACTION)
The begin
Result:=CallNextHookEx (hook, ACode AWParam, ALParam);
exit;
end;

MSG:=PCWPStruct (ALParam);
If the MSG. Message=WM_SETFOCUS then
The begin
SFN:='c: \ HookRS TXT';
AssignFile (Log, sFN);
Try
If not FileExists (sFN) then
ReWrite (Log)
The else Append (Log);

GetWindowText (MSG. WParam sTxt, 256);
WriteLn (Log, 'lost focus content of the window:' + sTxt);
GetWindowText (MSG. The HWND sTxt, 256);
WriteLn (Log, 'gains focus window content: + sTxt);
The finally
CloseFile (Log);
end;
end;

Result:=CallNextHookEx (hook, ACode AWParam, ALParam);

end;

The function SetHook: Boolean; Stdcall;
The begin
Result:=False;
If hook> 0 then the exit;
Hook:=SetWindowsHookEx (WH_CALLWNDPROC, @ MyWndProc hInstance, 0).
Result:=hook<> 0;
end;

The function DelHook: Boolean; Stdcall;
The begin
Result:=UnHookWindowsHookEx (hook);
end;

Exports
SetHook,
DelHook;

The begin

End.


Call:
 
.

Implementation

{$R *. DFM}

The function SetHook: Boolean; External 'MyHook. DLL';
The function DelHook: Boolean; External 'MyHook. DLL';

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related