whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

40 Visitors Online


 
...Retrieve the Zone Icon for the specified URL in a TWebbrowser?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (8):  
     




uses
  
Urlmon;

procedure GetZoneIcon(IconPath: stringvar Icon: TIcon);
var
  
FName, ImageName: string;
  h: hInst;
begin
  
FName := Copy(IconPath, 1, Pos('#', IconPath) - 1);
  ImageName := Copy(IconPath, Pos('#', IconPath), Length(IconPath));
  h := LoadLibrary(Pchar(FName));
  try
    if 
h <> 0 then
    begin
      
Icon.Handle := LoadImage(h, Pchar(ImageName), IMAGE_ICON, 16, 16, 0);
    end;
  finally
    
FreeLibrary(h);
  end;
end;

function GetZoneAttributes(const URL: string): TZoneAttributes;
var
  
pw: Pwidechar;
  dwZone: Cardinal;
  ZoneAttr: TZoneAttributes; //Defined in Urlmon.pas
var
  
ZoneManager: IInternetZoneManager;
  SecManager: IInternetSecurityManager;
begin
  
ZeroMemory(@ZoneAttr, SizeOf(TZoneAttributes));
  if CoInternetCreateSecuritymanager(nil, SecManager, 0) = S_OK then
    if 
CoInternetCreateZoneManager(nil, ZoneManager, 0)  = S_OK then
    begin
      
SecManager.MapUrlToZone(PWideChar(WideString(URL)), dwZone, 0);
      ZoneManager.GetZoneAttributes(dwZone, Result);
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
ZoneAttr: TZoneAttributes;
  ZoneIcon: TIcon;
begin
  
ZoneAttr := GetZoneAttributes(Webbrowser1.LocationURL);
  ZoneIcon := TIcon.Create;
  try
    
GetZoneIcon(ZoneAttr.szIconPath, ZoneIcon);
    Caption := ZoneAttr.szDisplayName
    Application.Icon := ZoneIcon;
  finally
    
ZoneIcon.Free;
  end;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners