(CodeLib-Manager)
Registriert seit: 10. Jun 2002
4.648 Beiträge
Delphi XE Professional
|
Re: UserAgent von TWebBrowser ändern
24. Feb 2008, 08:35
So setzt der TEmbeddedWeb den Useragent. Es wird also noch "Eigenwerbung" angehängt.
Delphi-Quellcode:
procedure SetUserAgent(var UserAgent: string);
var
reg: TRegistry;
begin
Reg := TRegistry.Create;
if UserAgent <> EWB_INFO then
UserAgent := UserAgent + EWB_INFO;
with Reg do
begin
RootKey := HKEY_CURRENT_USER;
try
if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings\User Agent\Post Platform', True) then
WriteString(UserAgent, '');
finally
CloseKey;
Free;
end;
end;
end;
Eine andere Möglichkeit von hier:
Zitat:
Du musst zuerst deinen Browser Komponent
erweitern. Hier ist der Code *als Hinweis*. Und DISPID_AMBIENT_USERAGENT
ist in SHDocVW.h (Windows SDK) definiert.
Delphi-Quellcode:
TUserAgentBrowser = class(TWebBrowser, IDispatch)
protected
function GetTypeInfoCount(out Count: Integer): HRESULT; stdcall;
function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo):
HRESULT; stdcall;
function GetIDsOfNames(const IID: TGUID; Names: Pointer; NameCount,
LocaleID: Integer; DispIDs: Pointer): HRESULT; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer):
HRESULT; stdcall;
end;
function TUserAgentBrowser.GetTypeInfoCount(out Count: Integer): HRESULT;
begin
Result := E_NOTIMPL;
Count := 0;
end;
function TUserAgentBrowser.GetTypeInfo(Index, LocaleID: Integer; out
TypeInfo): HRESULT;
begin
Result := E_NOTIMPL;
Pointer(TypeInfo) := nil;
end;
function TUserAgentBrowser.GetIDsOfNames(const IID: TGUID; Names:
Pointer; NameCount, LocaleID: Integer; DispIDs: Pointer): HRESULT;
begin
PDispIDList(DispIDs)[0] := DISPID_UNKNOWN;
Result := DISP_E_UNKNOWNNAME;
end;
function TUserAgentBrowser.Invoke(DispID: Integer; const IID: TGUID;
LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
ArgErr: Pointer): HRESULT;
begin
if (Flags and DISPATCH_PROPERTYGET <> 0) and (VarResult <> nil) then
case DispId of
-5513{DISPID_AMBIENT_USERAGENT}:
begin
POleVariant(VarResult)^ := 'Owner User Agent' + #13#10;
Result := S_OK;
Exit;
end;
end;
Result := inherited Invoke(DispID, IID, LocaleID, Flags, Params,
VarResult, ExcepInfo, ArgErr);
end;
Thomas
|
|
Zitat
|