Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send an url to the current active browser

Posted on 2004-10-01
5
Medium Priority
?
269 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

705 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