Link to home
Start Free TrialLog in
Avatar of myleseven
myleseven

asked on

How to make Internet Connection dialog stay on top

Hi there I have built an Internet surfing program.
I have a button in my program that when I click it it will load up the internet connection dialog box.
However I have discovered that if I then click on my form, the dialog box will 'dissapear' behind the form.
Is there anyway that I can keep it on top even if I click on my form?
I notived that the same thing happens for IE...

regards
Myles :)
Avatar of RadikalQ3
RadikalQ3
Flag of Spain image

Hi!
What is the code are you using for show the dialog?
Do you know handle of this connection dialog? If yes, you may use this:
SetWindowLong(wnd, gwl_exstyle, GetWindowLong(wnd, gwl_exstyle) or ws_ex_topmost)
Avatar of myleseven
myleseven

ASKER

Hi guys,
To show the dialog all I do is naviagate to my Browser... This seems to be quite a good universal method for loading up the Internet Dialog box...(by the way I am using TembeddedWB) Here is my code:

procedure tForm1.GoNow();
begin
  inherited;
  // Hook the embedded browser control
  FWebSelfPopup:=TWebSelfPopup.CreateHook(theBrowser);
  // Post message to our handle - the message handler will perform the
  // actual navigation. This is recommended by MS to ensure that the IE control
  // is in a loaded state and able to handle the call.
  PostMessage(Handle, WM_NAVIGATE, 0, 0);
end;

I quite like the idea of getting the handle and using the SetWindowLong, I will have a go to see if I can make this work...

cheers
Myles :)
whoops I left this part out...

procedure TForm1.WMNavigate(var Msg: TMessage);
var  ovURL:         OleVariant;
begin
  // Set the url
  ovURL := edURL.Text;
  // Perform the navigation
  theBrowser.Navigate2(ovURL);
end;
Actually I have no idea how to get the handle of theInternet Connection Dialog box...

Do you have any suggestions?

Myles:)
ASKER CERTIFIED SOLUTION
Avatar of ZhaawZ
ZhaawZ
Flag of Latvia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Zhaawz,
I have found a way to get the handle of the Internet Dialog box. THe problem is that it depends on the Title at the top of the box and I am not sure how universal this is.
Here is the code that I am using... It would be great to hear what you think...

procedure TForm1.btnConnectToNetClick(Sender: TObject);
//Purpose: To connect to the internet
var
  wnd : HWND;
begin
  wnd := 0;
  ShellExecute(Handle, 'open', 'http://delphi.about.com',nil,nil, SW_SHOWNORMAL);
  Pause(1); //to give the Internet Connection Box time to display
  wnd := FindWindowByTitle('Dial-up Connection');
  {if wnd = 0 then wnd := FindWindowByTitle('Try another Title');
  if wnd = 0 then wnd := FindWindowByTitle('Try another Title');
  if wnd = 0 then wnd := FindWindowByTitle('Try another Title'); }
  SetWindowPos(wnd, HWND_TOPMOST, Left,Top, Width,Height, SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
  SetWindowLong(wnd, GWL_USERDATA, 0);
end;

function TForm1.FindWindowByTitle(WindowTitle: string): Hwnd;
var
  NextHandle: Hwnd;
  NextTitle: array[0..260] of char;
begin
   //ListBox1.Clear;
   //ListBox1.Items.Add('Looking for: ' + WindowTitle);
  // Get the first window
  NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
  while NextHandle > 0 do
  begin
    // retrieve its text
    GetWindowText(NextHandle, NextTitle, 255);
   // if nextTitle <> '' then ListBox1.Items.Add(nextTitle);
    if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
    begin
      Result := NextHandle;
      Exit;
    end
    else
      // Get the next window
      NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
  end;
  Result := 0;
end;

// pause for Secs seconds, but allow the application to respond to windows messages.
Procedure TForm1.Pause(Secs : Integer);
var
  i : Integer;
begin
  for i := 1 to Secs * 10 do begin
    Sleep(100);                    // sleep for 1/10 seconds
    Application.ProcessMessages;
  end;
end;
Well I couldn't have gotten this far without your help Zaaawz so I will give you the points, thanks heaps
:)
Myles