DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

get handle
Goto page 1, 2  Next
 
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming
View previous topic :: View next topic  
Author Message
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 29/11/04 13:18    Post subject: get handle Reply with quote

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
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 412
Location: Tehran, Iran

PostPosted: 29/11/04 18:08    Post subject: Reply with quote

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
View user's profile Send e-mail Visit poster's website
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 30/11/04 07:11    Post subject: Reply with quote

Good !! it run !

Really thanks from france !!
Back to top
View user's profile
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 30/11/04 12:36    Post subject: Reply with quote

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
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 412
Location: Tehran, Iran

PostPosted: 10/12/04 08:56    Post subject: Reply with quote

What's firefox?
Back to top
View user's profile Send e-mail Visit poster's website
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 14/12/04 10:13    Post subject: Reply with quote

it's an internet browser
http://www.firefox.com/

it works neither with firefox nor IE
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 412
Location: Tehran, Iran

PostPosted: 14/12/04 12:34    Post subject: Reply with quote

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
View user's profile Send e-mail Visit poster's website
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 14/12/04 13:08    Post subject: Reply with quote

so bad news !

there isn't any way to send data like with normal edit ?
Back to top
View user's profile
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 412
Location: Tehran, Iran

PostPosted: 14/12/04 17:58    Post subject: Reply with quote

If you get the browser COM interface, you have full access to the entire web elements of a page.
Back to top
View user's profile Send e-mail Visit poster's website
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 15/12/04 07:07    Post subject: Reply with quote

How doing this ?
Back to top
View user's profile
Stefan
Member


Joined: 27 Sep 2004
Posts: 49
Location: Netherlands

PostPosted: 20/12/04 11:15    Post subject: Reply with quote

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
View user's profile Send e-mail
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 20/12/04 13:05    Post subject: Reply with quote

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
View user's profile
Stefan
Member


Joined: 27 Sep 2004
Posts: 49
Location: Netherlands

PostPosted: 20/12/04 13:54    Post subject: Reply with quote

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
View user's profile Send e-mail
firejocker
Member


Joined: 29 Nov 2004
Posts: 9

PostPosted: 20/12/04 14:52    Post subject: Reply with quote

with this, is it possible to set data in an online form ?
Back to top
View user's profile
Stefan
Member


Joined: 27 Sep 2004
Posts: 49
Location: Netherlands

PostPosted: 20/12/04 15:40    Post subject: Reply with quote

Ah! For that we have torry...

http://www.swissdelphicenter.ch/torry/showcode.php?id=1732
Back to top
View user's profile Send e-mail
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group