A class to toggle image display in Internet Explorer 5 (Views: 29)
Problem/Question/Abstract: Internet Explorer 5 (and others) allows you to toggle image displays. If you are using Twebbrowser this can speed up retrieving webpages as the graphics are not longer fetched. Answer: A year ago I had an article published in Delphi Developer on writing Web-robots using the twebbrowser that is part of Internet Explorer and which you can install in Delphi 3 or 4 and comes pre-installed in Delphi 5. My only gripes with using Twebbrowser are that there is a fair bit of baggage- it renders every web-page which slows things down (especially when it has to retrieve every image on the page). The class below implements a way of disabling image display (toggling the IE switch programmatically) in IE 5 to speed up web-robots written using it. It hasn’t beeen tested in IE 4 or IE 5.5 though I suspect it will probably work. type TViewIEImage = class private fSavedimagesVisible: Boolean; function GetState: Boolean; procedure SetVisible(Visible: Boolean); public BroadcastChange: Boolean; constructor Create; destructor Destroy; override; property ImagesVisible: Boolean read GetState write SetVisible; property SavedImagesVisible: Boolean read fSavedimagesVisible write fSavedimagesVisible; end; constructor TViewIEImage.Create; begin fSavedimagesVisible := GetState; BroadcastChange := True; end; destructor TViewIEImage.Destroy; begin SetVisible(fSavedimagesVisible); end; function TViewIEImage.GetState: Boolean; begin Result := GetRegistryValue = 'yes'; end; procedure TViewIEImage.SetVisible(Visible: Boolean); var Reg: TRegistry; Str: string; begin if Visible then Str := 'yes' else Str := 'no'; Reg := TRegistry.Create; try Reg.RootKey := HKEY_CURRENT_USER; if Reg.OpenKey('\Software\Microsoft\Internet Explorer\Main', False) then Reg.WriteString('Display Inline Images', Str); finally Reg.CloseKey; Reg.Free; inherited; end; if BroadcastChange or Visible then PostMessage( HWND_BROADCAST, WM_WININICHANGE, 0, Longint(pchar('HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main'))); end; In future articles I will look at writing web robots without using twebbrowser. |