| View previous topic :: View next topic |
| Author |
Message |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 29/11/04 13:18 Post subject: get handle |
|
|
Hello all,
So, sorry for my writed, but I'm a french developper with a bad english.
I'm looking how to get the handle of a text area (witch can be memo, edit ...) of another software where is the keyboad focus.
my program run being hidded, and i have to get the handle od the area where the user is writting (notepad, word, ...) to modify some data.
how can i get it ?
Thanks all.
FireJocker. |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 29/11/04 18:08 Post subject: |
|
|
| Code: | function GetGlobalFocus: THandle;
var
GUIThreadInfo: TGUIThreadInfo;
begin
GUIThreadInfo.cbSize := SizeOf(TGUIThreadInfo);
if GetGUIThreadInfo(0, GUIThreadInfo) then
Result := GUIThreadInfo.hwndFocus
else
Result := 0;
end; |
|
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 30/11/04 07:11 Post subject: |
|
|
Good !! it run !
Really thanks from france !! |
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 30/11/04 12:36 Post subject: |
|
|
I don't understand something ...
Why
| Code: | procedure TForm1.test;
var
h,hedit: hwnd;
s: pchar;
str : string;
debut,fin:integer;
begin
hedit := GetGlobalFocus;
str := 'test';
SendMessage(hedit, WM_SETTEXT, 0,integer(Str));
end; |
works with notepad ... but doesn't with firefox ?
Last edited by firejocker on 14/12/04 10:16; edited 1 time in total |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 10/12/04 08:56 Post subject: |
|
|
| What's firefox? |
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 14/12/04 10:13 Post subject: |
|
|
it's an internet browser
http://www.firefox.com/
it works neither with firefox nor IE |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 14/12/04 12:34 Post subject: |
|
|
Edit fields in a browser are not as same as Windows edit fields. Therefor, you cannot use WM_SETTEXT message to set the text of a field.
I guess browser uses handleless control for edit fields of the forms. |
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 14/12/04 13:08 Post subject: |
|
|
so bad news !
there isn't any way to send data like with normal edit ? |
|
| Back to top |
|
 |
Kambiz Administrator

Joined: 07 Mar 2003 Posts: 412 Location: Tehran, Iran
|
Posted: 14/12/04 17:58 Post subject: |
|
|
| If you get the browser COM interface, you have full access to the entire web elements of a page. |
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 15/12/04 07:07 Post subject: |
|
|
| How doing this ? |
|
| Back to top |
|
 |
Stefan Member
Joined: 27 Sep 2004 Posts: 49 Location: Netherlands
|
Posted: 20/12/04 11:15 Post subject: |
|
|
I don't know if FF support ActiveX or COM, I believe there is a way to build FF so that it supports ActiveX. I think you might want to look for XPConnect for FF (or something like that).
To get a (IE) browser in Delphi, simply drop the TWebBrowser control (on the Internet tab) on your form et voila!
It all depends on what you want to do though. If you want to interact with a running instance of IE that the user is using try:
| Code: |
function GetRunningInstance: IWebBrowser2;
var
ShWindows: IShellWindows;
i: integer;
begin
ShWindows := CoShellWindows.Create;
for i := 0 to ShWindows.Count - 1 do
begin
Result := ShWindows.Item(i) as IWebBrowser2;
if Result.LocationURL =
'http://sourceforge.net/projects/extgraph' then
Break;
end;
end;
|
This returns a IWebBrowser2 interface for the user's current IE session if the LocationURL property equals 'http://sourceforge.net/projects/extgraph'.
Cheers
Stefan |
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 20/12/04 13:05 Post subject: |
|
|
I just want to get focus and send data like pressed on the keyboard,
It run with program but doesn't on a browser |
|
| Back to top |
|
 |
Stefan Member
Joined: 27 Sep 2004 Posts: 49 Location: Netherlands
|
Posted: 20/12/04 13:54 Post subject: |
|
|
This does not do *exactly* what you want. It does not allow you to get the handle of the control, though it does allow you to set the text and navigate to the specified URL:
| Code: |
function GetActiveIEBrowser: IWebBrowser2;
var
shellWindows: IShellWindows;
i: Integer;
webBrowser: IWebBrowser2;
begin
Result := nil;
shellWindows:= CoShellWindows.Create;
for i:=0 to shellWindows.Count -1 do
if Supports(shellWindows.Item(i), IWebBrowser2, webBrowser) then begin
// Separates IE from Explorer
if AnsiLowerCase(ExtractFileName(webBrowser.FullName)) = 'iexplore.exe' then begin
Result:= webBrowser;
Break;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
brwsr: IWebBrowser2;
begin
brwsr := GetActiveIEBrowser;
brwsr.Navigate('http://sourceforge.net/projects/extgraph', emptyparam,emptyparam,emptyparam,emptyparam);
end;
|
|
|
| Back to top |
|
 |
firejocker Member
Joined: 29 Nov 2004 Posts: 9
|
Posted: 20/12/04 14:52 Post subject: |
|
|
| with this, is it possible to set data in an online form ? |
|
| Back to top |
|
 |
Stefan Member
Joined: 27 Sep 2004 Posts: 49 Location: Netherlands
|
|
| Back to top |
|
 |
|