How to send text to current InputFocus???

A program to send text to current Input Focus Such as a edit or memo control or
a edit in the IE current browering web
page.

How can I do it?

:)  thanks
keronAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
Hi
something like this:

procedure TForm1.Button1Click(Sender: TObject);
Var
 Explorer, Worker, Bar, ComboEx, Combo, Edit : HWND;
 Address : String;
begin
 Edit := 0;

 Explorer := FindWindow('IEFrame', nil);
 If Explorer <> 0 Then Begin
  Worker := FindWindowEx(Explorer, 0, 'Worker', nil);
  If Worker <> 0 Then Begin
   Bar := FindWindowEx(Worker, 0, 'ReBarWindow32', nil);
   If Bar <> 0 Then Begin
    ComboEx := FindWindowEx(Bar, 0, 'ComboBoxEx32', nil);
    If ComboEx <> 0 Then Begin
     Combo := FindWindowEx(ComboEx, 0, 'ComboBox', nil);
     If Combo <> 0 Then Begin
      Edit := FindWindowEx(Combo, 0, 'Edit', nil);
     End;
    End;
   End;
  End;
 End;

 If Edit <> 0 Then Begin
  Address := 'www.microsoft.com';
  SendMessage(Edit, WM_SETTEXT, 0, Integer(Address));
  SendMessage(Edit, WM_KEYDOWN, VK_RETURN, $011C001);
 End;
end;

Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
for interent explorer 5 i had to do:

procedure TForm1.Button1Click(Sender: TObject);
Var
 Explorer, Worker, Bar, ComboEx, Combo, Edit : HWND;
 Address : String;
begin
 Edit := 0;
 Explorer := FindWindow('CabinetWClass', nil);
 If Explorer <> 0 Then Begin
  Worker := FindWindowEx(Explorer, 0, 'WorkerA', nil);
  If Worker <> 0 Then Begin
   Bar := FindWindowEx(Worker, 0, 'ReBarWindow32', nil);
   If Bar <> 0 Then Begin
    ComboEx := FindWindowEx(Bar, 0, 'ComboBoxEx32', nil);
    If ComboEx <> 0 Then Begin
     Combo := FindWindowEx(ComboEx, 0, 'ComboBox', nil);
     If Combo <> 0 Then Begin
      Edit := FindWindowEx(Combo, 0, 'Edit', nil);
     End;
    End;
   End;
  End;
 End;

 If Edit <> 0 Then Begin
 showmessage('got here');
  Address := 'www.microsoft.com';
  SendMessage(Edit, WM_SETTEXT, 0, Integer(Address));
  SendMessage(Edit, WM_KEYDOWN, VK_RETURN, $011C001);
 End;
end;

0
edeyCommented:
If, as I read it, you want to get the active control from *any* process (or rather, the control containing the caret) you would need to find the window in the foreground, attach your message thread to it's queue, then call getfocus to find the active control & then send it a WM_SETTEXT message, the pertinent api's are:

The GetForegroundWindow function returns the handle of the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.

HWND GetForegroundWindow(VOID)

The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window. This function supersedes the GetWindowTask function.

DWORD GetWindowThreadProcessId(

    HWND hWnd,      // handle of window
    LPDWORD lpdwProcessId       // address of variable for process identifier
   );

The AttachThreadInput function attaches the input processing mechanism of one thread to that of another thread.

BOOL AttachThreadInput(

    DWORD idAttach,      // thread to attach
    DWORD idAttachTo,      // thread to attach to  
    BOOL fAttach       // attach or detach
   );

The GetFocus function retrieves the handle of the window that has the keyboard focus, if the window is associated with the calling thread's message queue.

HWND GetFocus(VOID)

WM_SETTEXT  
wParam = 0;                     // not used; must be zero
lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string


GL
Mike
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

rwilson032697Commented:
Listening
0
MadshiCommented:
Yep, Mike is right... AttachThreadInput is the way to go.
0
yk030299Commented:
listen
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.