Solved

Send an url to the current active browser

Posted on 2004-10-01
5
256 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev Express grid collapse 2 45
SUM 2 INTEGER ARRAYS INTO 1 10 109
DBGrid or StringGrid ? 6 105
Firemonkey BASS_Init into a thread 17 33
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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