Make Browser to redirect to another URL

Suppose I'm using IE 4.0, and I active that IE only once, then go to http://www.somewhere.blablabla.
I want to write a program in delphi that after a button has been pressed, that IE redirect to another site in my textbox. The IE has been activated before the delphi application run. And note that if before I run the appl and there were 2 or more IE, the appl would only affect to one random IE, then if I press the button once again, it affects the same IE as previous.
I want procedure button1click() code.

Sorry if you got confused with my English, I'm not native English speaker...

Regards,

LexZEUS.
LVL 5
LexZEUSAsked:
Who is Participating?
 
SlavakConnect With a Mentor Commented:
Sorry, I'm not understanding what your program should do.
If you want redirect your IE window to another URL and know only window coordinates of link (how you can know this?) you can write something like this:

procedure TForm1.Button2Click(Sender: TObject);
Var
 Explorer, Doc, Server : HWND;
 XPos, YPos : Integer;
begin
 Server := 0;

 Explorer := FindWindow('IEFrame', nil);
 If Explorer <> 0 Then Begin
  Doc := FindWindowEx(Explorer, 0, 'Shell DocObject View', nil);
  If Doc <> 0 Then Begin
   Server := FindWindowEx(Doc, 0, 'Internet Explorer_Server', nil);
  End;
 End;

 If Server <> 0 Then Begin
  XPos := 311;  YPos := 196;

  // activate explorer window
  PostMessage(Server, WM_LBUTTONDOWN, MK_LBUTTON, (YPos shl 16) + XPos);
  PostMessage(Server, WM_LBUTTONUP, 0, (YPos shl 16) + XPos);

  // click mouse at XPos / YPos.
  PostMessage(Server, WM_LBUTTONDOWN, MK_LBUTTON, (YPos shl 16) + XPos);
  PostMessage(Server, WM_LBUTTONUP, 0, (YPos shl 16) + XPos);
 End;
end;

In this way you can imitate mouse click at specified position, but I don't know any way, using window messages, to know what a result of sending to IE this message.

Tell, what your program should do and may be I can advise you another way to do it.
0
 
LexZEUSAuthor Commented:
Adjusted points to 100
0
 
LexZEUSAuthor Commented:
Maybe the first step is to find HWND of the IE, and put them on a global variable, but how to do that ?

Then the Delphi send message to IE to redirect or something.. Can it be done ?

And one more, how can I told IE using MESSAGES that a left mouse button is clicked on (X,Y) ?
Should I use SetPosition(X,Y) API and then send the message ? Can u give an example ?
If your answer satisfies me, I'm willingly to increase my point to 200.

LexZEUS
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
SlavakCommented:
Hi, may be the function will help you.

procedure TForm1.Button1Click(Sender: TObject);
Var
 Explorer, Worker, Bar, ComboEx, Combo, Edit : HWND;
 Address : String;
begin
 Edit := 0;

 Explorer := FindWindow('IEFrame', nil);
 If Explorer <> 0 Then Begin
  Worker := FindWindowEx(Explorer, 0, 'Worker', nil);
  If Worker <> 0 Then Begin
   Bar := FindWindowEx(Worker, 0, 'ReBarWindow32', nil);
   If Bar <> 0 Then Begin
    ComboEx := FindWindowEx(Bar, 0, 'ComboBoxEx32', nil);
    If ComboEx <> 0 Then Begin
     Combo := FindWindowEx(ComboEx, 0, 'ComboBox', nil);
     If Combo <> 0 Then Begin
      Edit := FindWindowEx(Combo, 0, 'Edit', nil);
     End;
    End;
   End;
  End;
 End;

 If Edit <> 0 Then Begin
  Address := 'www.microsoft.com';
  SendMessage(Edit, WM_SETTEXT, 0, Integer(Address));
  SendMessage(Edit, WM_KEYDOWN, VK_RETURN, $011C001);
 End;
end;
0
 
LexZEUSAuthor Commented:
Hey Slavak, I'm interested in you, just wait for a minute before I accept your answer, maybe I would increase my points to 200 if you answer all of my question at my previous comment ( about the 2'nd way, using mouse ).
And what is that $011C001 means ?
Answer all my q. and it worth 200 pt !

LexZEUS

0
 
SlavakCommented:
OK.

"LParam" parameter of WM_KEYDOWN message should receive key data. $011C001 means Repeat=1,ScanCode=$1C,
Key is extended and released. For more information see Delphi help for WM_KEYDOWN message.

About 2'nd way. I cannot understand what you want to do using mouse. Tell me more an I'll try to help you.

Regards.
0
 
LexZEUSAuthor Commented:
Ok, I assume that after a button is clicked, the application get minimized and then IE reshows. Then I want to put the mouse cursor on position(x,y) on IE, it must be using API's SetCursorPos() , I got it. And then how to send message to IE that a left mouse button has been clicked and ensure that there's no error after clicking ( I've placed the cursor exactly on a link ).
The error I mean is a msg dialog error, i.e Javascript error, server terminated the connection or etc (which need OK button being clicked).


Thanx,

LexZEUS
0
 
umuligCommented:
think this might have what you need.
http://www.euromind.com/iedelphi/

Ted
0
 
LexZEUSAuthor Commented:
Great !!! I'm satisfied with your answer...

> (how you can know this?)
Yes, I do generate the HTML content myself, of course I know the exact position of the link. Honestly, this program is a tutorial application, and I use IE to show the tutorial content. So I must manipulate the cursor to move around and then click... Both two of your codes work.. Thanx very much.

Regards,

LexZEUS
0
All Courses

From novice to tech pro — start learning today.