Problem Source: http://www.cnblogs.com/del/archive/2008/06/18/1083011.html#1229305
Tell Roy. Flex:
Your problem is still complicated. The first step is to complete it;
Next, if you want to capture other Program The mouse in needs to be DLL;
However, there is also a simple method, that is, to use ttimer to obtain it regularly, so that no hook is needed;
But still need to know the handle of the object to operate, this can refer to: http://www.cnblogs.com/del/archive/2008/03/09/1097942.html
In this example:
Code File:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, comctrls, extctrls; Type tform1 = Class (tform) edit1: tedit; memo1: tmemo; richedit1: batch; button1: tbutton; button2: tbutton; button3: tbutton; Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject ); procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} {function for retrieving selected text in the text container implemented by API} function geteditseletetext (H: hwnd): string; var Len, Sx, EX: integer; {total text length, selected Start position, selected end position} Buf: pchar; {all text} begin {get total text length} Len: = sendmessage (H, wm_gettextlength, 0, 0) + 1; {allocate memory for the buffer that accepts all text} Buf: = globalallocptr (0, Len); {getmem is not used here because global is required, otherwise, you cannot face other programs} {get all text} sendmessage (H, wm_gettext, Len, longint (BUF); {Get the selected Start position and end position} sendmessage (H, em_getsel, longint (@ SX), longint (@ ex); {extract selected text} result: = copy (BUF, SX + 1, ex-SX ); {release memory} globalfreeptr (BUF); end; {test tedit, and comparison with VCL} procedure tform1.button1click (Sender: tobject); begin showmessage (geteditseletetext (edit1.handle) + '-' + edit1.seltext); end; {test tmemo and compare it with the VCL obtaining method} procedure tform1.button2click (Sender: tobject); begin showmessage (geteditseletetext (memo1.handle) + '-' + memo1.seltext); end; {test trichedit and compare it with the VCL obtaining method} procedure tform1.button3click (Sender: tobject); begin showmessage (geteditseletext (richedit1.handle) + '-' + richedit1.seltext); end.
Form file:
Object form1: tform1 left = 0 Top = 0 caption = 'form1' clientheight = 145 clientwidth = 181 color = clbtnface font. charset = default_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] oldcreateorder = false position = podesktopcenter pixelsperinch = 96 textheight = 13 object button1: tbutton left = 95 Top = 8 width = 75 Height = 25 caption = 'button1' taborder = 0 onclick = button1click end object edit1: tedit left = 8 Top = 8 width = 81 Height = 21 taborder = 1 text = 'edit1' end object memo1: tmemo left = 8 Top = 35 width = 81 Height = 46 lines. strings = ('memo1') taborder = 2 end object richedit1: trichedit left = 8 Top = 87 width = 81 Height = 50 font. charset = gb2312_charset font. color = clwindowtext font. height =-11 font. name = 'tahoma 'font. style = [] lines. strings = ('richedit1') parentfont = false taborder = 3 end object button2: tbutton left = 95 Top = 56 width = 75 Height = 25 caption = 'button2' taborder = 4 onclick = button2click end object button3: tbutton left = 95 Top = 112 width = 75 Height = 25 caption = 'button3' taborder = 5 onclick = button3click endend