Solved

Send an url to the current active browser

Posted on 2004-10-01
5
253 Views
Last Modified: 2010-04-05
 Greeting experts!
  I need to know how I can do the following:

  *)Capture hot key with specific programs (for example, if the current active window is internet explorer, F1 key will be captured to my program (running in the background), but if the current active window is others, F1 key will function normally).
  *)If the current window is a browser, how can I send an url to it and force it go there? (in the current browser window, not open a new one).
  It's hard for me to figure out myself, so your help is very useful to me.

  Thanks in advance!
  Tri
0
Comment
Question by:dttri
  • 3
5 Comments
 
LVL 6

Expert Comment

by:so3
ID: 12222035
On the second question do you want to do it with a shortcut key or from the app and there is a file url or just a url
0
 
LVL 6

Expert Comment

by:so3
ID: 12222044
i have a sample of what you want to do and tomorow i'll send it to you after you answer the question above
0
 
LVL 7

Author Comment

by:dttri
ID: 12223427
 Thanks for you reply,
  My idea is this: for example, my current window is Internet Explorer, after I press F1 key (the F1 key associated with the help is disable), my current window will point to, eg, microsoft.com and go to it too.

  Waiting for your code,
  Tri
0
 
LVL 6

Accepted Solution

by:
so3 earned 500 total points
ID: 12232551
Here is the code. Put a Thotkey on your form.

The code is not complete you have to find the handle of edit. I don't know what i'm doing wrong that i can't find it. Maybe you or some expert can find it . I'll try tomorrow to find it now i'm to tired:)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls,Menus,SHELLAPI;

type
  TForm1 = class(TForm)
    HotKey1: THotKey;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Procedure HotKeyProc(var msg:TWmHotkey); message WM_HOTKEY;
  public
    { Public declarations }
    procedure RegisterShortcut(HKey: TShortCut);
    procedure UnRegisterShortCut;
  end;

var
  Form1: TForm1;
  Hotkey: integer;

implementation

{$R *.dfm}
procedure TForm1.RegisterShortcut(HKey:TShortCut);
var
  fuModifiers : Cardinal;
  Key: Word;
  Shift: TShiftState;
begin
  fuModifiers := 0;

  ShortCutToKey(HKey, Key, Shift);

  if  ssCtrl in Shift then
    fuModifiers := MOD_CONTROL;
  if ssShift in Shift then
    fuModifiers := fuModifiers or MOD_SHIFT;
  if ssAlt in Shift then
    fuModifiers := fuModifiers or MOD_ALT;  

  RegisterHotKey(Handle,HotKey,fuModifiers, Key);
end;

procedure TForm1.UnRegisterShortCut;
begin
  UnRegisterHotkey(Handle, HotKey);
  GlobalDeleteAtom(HotKey);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnRegisterShortCut;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    HotKey:=GlobalAddAtom(PChar('F1'));
    RegisterShortcut(HotKey1.HotKey);
end;

function FindControlByNumber(hApp: HWND; ControlClassName: string; ControlNr: Word = 1): HWND;
var
  i: Word;
  hControl: HWND;
begin
  Result := 0;
  if IsWindow(hApp) then
  begin
    Dec(ControlNr);
    hControl := 0;
    for i := 0 to ControlNr do
    begin
      hControl := FindWindowEx(hApp, hControl, PChar(ControlClassName), nil);
      if hControl = 0 then
        Exit;
    end;
  end;
  Result := hControl;
end;

procedure TForm1.HotkeyProc(var Msg: TWmHotkey);
var Whandle,hEdit: HWND;
    Clas:array[0..127] of Char;
begin

if MSG.HotKey = Hotkey then begin
  Whandle:=GetForegroundWindow;
  GetClassname(Whandle,Clas,Sizeof(Clas));

  if (Whandle<>0) and (Clas='IEFrame') then
       begin
        hEdit := FindControlByNumber(Whandle, 'Edit', 1);      //here is the pb where to find the IE edit handle
        if hEdit <> 0 then        //329586
          begin
           SendMessage(hEdit, WM_SETTEXT, 0, Integer(PChar('http://www.microsoft.com')));
           SendMessage(hEdit, WM_KEYDOWN, VK_RETURN, 0);
           SendMessage(hEdit, WM_KEYUP, VK_RETURN, 0);
          end;
       end
       else
         begin
         UnRegisterHotkey(Handle, HotKey);
         SendMessage(Whandle, WM_KEYDOWN, VK_F1, 0);
         Sleep(1000);
         SendMessage(Whandle, WM_KEYUP, VK_F1, 0);
         RegisterShortcut(HotKey1.HotKey);
         end;

  end;
end;

end.
0
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12235433
you can put the ie in the foreground and send the key F4
it will set the cursor into the adress bar and show the history
now you only need to send the whole adress at once
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now