Link to home
Start Free TrialLog in
Avatar of Ogni
Ogni

asked on

TWebBrowser-component...

Hi !
I'm using D5 Enterprise (engl. version) and Win98SE/NT4.0.
I'm "playing" a bit with the TWebbrowser-component and the shdocvw.dll...
First: Is the shdocvw.dll the only sh*.dll needed for TWebbrowser?
Second: When i change the url, the new page will be displayed in a new browser-window.
I want to use the same window - how can i do this?
Third: Is there a universal methode for checking if a browser is already started...
Not code with strings like "IEXPLORE" or "NETSCAPE" 'cause it could be another one ;-)
Thanks a lot!
Best regards,
Ingo
Avatar of RickHalle
RickHalle

First: There are various dll's use by TWebBrowser. mshtml, shdocvw.dll, etc. If you want to know what all of them are then go to MS site and look for a list of files installed by IE4 or IE5. The TWebBrowser uses the IE4/5/6 WebBrowser ActiveX control via a Delphi Wrapper. If you need to distribute the WebBrowser itself you will need to get a license from MS(free) to distribute Internet Explorer and then install it(Not the individual dlls). This is seldom the case any more though since almost all PCs already have IE4 or above on them. Win98 and above all have the required dlls in th OS itself.

Second: You can catch this in the NewWindow2 event. Keep in mind there is a bug in the code below regarding absolute vs. relative links. I have not had time to find a solution for it but it should give you something to start with.
**************************************************
procedure DynamicWBNewWindow2(Sender: TObject; var ppDisp: IDispatch;
  var Cancel: WordBool);
var
  Doc: IHTMLDocument2;
  S: string;
  varUrl: OLEVariant;
  Flags: OLEVariant;
begin
  Flags := 0;
  begin
    {Prevents new windows from popping up}
    Cancel := True;
    {Redirect new windows into current one, There is a bug here if the link is relative}
    Doc := IHTMLDocument2(TWebBrowser(Sender).Document);
    S := Copy(Doc.activeElement.outerHTML, pos('href=',
      Doc.activeElement.outerHTML) + 5, length(Doc.activeElement.outerHTML) -
      pos('href=', Doc.activeElement.outerHTML) + 5);
    S := Copy(S, 0, pos('>', S) - 1);
    if pos('"', S) = 1 then
      S := Copy(S, 2, Length(S) - 1);
    if pos('"', S) <> 0 then
      S := Copy(S, 0, pos('"', S));
    if pos('"', S) = Length(S) then
      S := Copy(S, 0, Length(S) - 1);
    {Currently only works with absolute links, relative links come back invalid}
    varURL := S;
    DynamicWB.Navigate2(varURL, Flags, Flags, Flags, Flags);
  end;
end;
**************************************************
Basically this cancels any new window from popping up. Then it determines the URL(If its an absolute link) clicked and calls it again using the same window. In the case of a relative link it is only getting the portion of the url that is relative to the current page so it is incomplete and comes back not found(but does not open a new window).

Third: There may be a way to determine if there is a particular browser open but not globally since they may or may not use standard dlls. Attempting to do this would be difficult though since there are several applications that embed browsers in them. I.E. It may indicate a browser is open and then if you attempt to load a page into it you could break it. I would avoid this unless you have a real pressing need for it.

Rick Halle
Avatar of Ogni

ASKER

Hi Rick !

No good news you wrote ;-)
Perhaps there're other ways:
First: It is possible to show the favourite browser via "ShellExecute(...'http://www.example.com'..." in a delphi-window?
Second: Thanks a lot!
Third: I've thought i can read something in the registry to get the browsername?!

Perhaps you've still an idea?

Regards,
Ingo
 
What exactly are you trying to do? It may be easier to find a solution that way.

Rick Halle
Avatar of Ogni

ASKER

Hi Rick !
Fast - Faster - Rick ;-) ...Thanks!
I've an url-catalog as database with a special theme. I want to select via tree-control starting the url in my browser (or TWebBrowser) with a click. It shall look like one app... Not my delphi-app and the browser-app ;-)
Hoe you understand my german english ;-)
Regards,
Ingo
BTW: Look at the points ;-)
You can embed the webbrowser to do this. In most cases you will not need to be concerned with the browser dlls because they are usually there already. Less than 1% of my customers need to install IE for it to work. I no longer distribute it either. If they need it I have them download it from MS. Like I said though the percentage is pretty low. Even for old Win95 machines this holds true since many applications these days require it. For your particular problem I can verify that this should work because I have a similar treeview URL list that gets updated regularly by one of my applications. To make your browser a bit more application specific you can dynamically create it with a TPanel as the parent. This gives you a little additional control over it. With a little work you can also give the window border a flat look and control additional properties of the document displayed. (fonts, backgrounds, etc.) If you decide to go this route then I can probably help with samples for these items and several other little things I have found. (Printing, Copy/Paste, etc.)

Rick Halle
Avatar of Ogni

ASKER

Hi Rick !
Okay, i'll use the webbrowser-component ;-)
I've had some problems using imagelist and actionbar for the buttons/functions (creating, enabled, disabled, which event). How can i select automatic the real information of a page? I want to print or put to clipboard with one click the contents of the main page - not frame-contents or title-images...
Some goodies giving the webbrowser a unique Design will be welcomed, too.
Thanks a lot!
Ingo
   
To print the main page in a frame you need to know in advance what the frame name is. You have a little control over the printing but not a great deal. I.E. If you try to print a frames page it will print all frames.(unless you allow a preview dialog) This is related directly to the html not the browser component. If you know ahead of time the frame you need to print then you can print just that one. If you have control of the site then this is pretty easy. Otherwise it is just a guess and can be problematic.

I have put up a Dynamic Browser sample demonstrating some of the capabilities of various things you can do here:

http://home.ec.rr.com/rickhalle/

This demonstrates creating the browser dynamically, catching files with specified extensions, Flat borders, No Right Clicks, Canceling New Windows and opening them in the current one. (Note: I have corrected the relative vs. absolute link problem in the code I pasted above), a couple of document level over rides, (fonts, etc.) a progress bar, an animated image(showing browser busy). Keep in mind this is not a complete browser project. It does not track the history or have an address bar. Therefore back, forward, and refresh are just calling the defaults. I have found that this does not always work well so it should have a way to track these. Then you can navigate back or forward. For refresh I normally reload(navigate to) the current url stored in the history list. I opted to not put the history and address bar in this to simplify it. For your particular use you will probably be removing the toolbar anyway and launching the urls from the tree. Take a look at this and let me know if you have any specific questions or want further explanation.

Rick Halle
ASKER CERTIFIED SOLUTION
Avatar of RickHalle
RickHalle

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
Avatar of Ogni

ASKER

Hi Rick !
I've tested your dynamic browser... I'll think there're some good ideas for me in it ;-)
I'll look from time to time to your helpsite...
Again thanks a lot!!!
Best regards,
Ingo
BTW: Look at the points
 
No Problem, Drop me an email if you have any more questions. I'm working on a connection testing unit right now that may be useful to you also. Essentially this will verify that there is a valid connection to the internet prior to launching the browser. As is the browser will launch the default connection but it does not do a very good job in either a lan situation or when AOL is used. I have already done this in another project but am cutting it out and cleaning it up some for a new project I am working on.

Rick Halle
Avatar of Ogni

ASKER

Hi Rick !

I've found something... Perhaps it helps ;-)

Best regards,
Ingo

This is for "if there's a connection to the internet?"
Uses
   {...,} WinInet;

{...}

function IsConnectedToInternet : boolean;
begin
  result := (InternetGetConnectedState(nil, 0))
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 if IsConnectedToInternet then
   ShowMessage('Connected.')
 else
   ShowMessage('Not Connected.')
end;

Here's another one:
uses
  StdCtrls,registry;

Function IsConnected : Boolean;
var
  reg  : TRegistry;
  buff : dword;
begin
  reg:= tregistry.Create ;
  Reg.RootKey:=HKey_local_machine;
  if reg.OpenKey('\System\CurrentControlSet\Services\RemoteAccess',false) then
  begin
    reg.ReadBinaryData('Remote Connection',buff,sizeof(buff));
    result := buff = 1;
    reg.CloseKey ;
    reg.Free ;
  end;
end;

This is for "What kind of internet-connection...?"
uses wininet;

Function ConnectionKind :boolean;
var
  flags: dword;
begin
  Result := InternetGetConnectedState(@flags, 0);
  if Result then
  begin
    if (flags and INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM then
    begin
      showmessage('Modem');
    end;
    if (flags and INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN then
    begin
      showmessage('LAN');
    end;
    if (flags and INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY then
    begin
      showmessage('Proxy');
    end;
    if (flags and INTERNET_CONNECTION_MODEM_BUSY)=INTERNET_CONNECTION_MODEM_BUSY then
    begin
      showmessage('Modem Busy');
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ConnectionKind;
end;