Solved

Send an url to the current active browser

Posted on 2004-10-01
5
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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