[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to send text to current InputFocus???

Posted on 2000-01-31
6
Medium Priority
?
209 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:keron
6 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2476707
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
 
LVL 17

Expert Comment

by:inthe
ID: 2476720
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
 
LVL 6

Expert Comment

by:edey
ID: 2476950
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2477149
Listening
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2477189
Yep, Mike is right... AttachThreadInput is the way to go.
0
 
LVL 1

Expert Comment

by:yk030299
ID: 2477420
listen
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question