开发者

Delphi: Is webbrowser focused / or get the webbrowsers real Handle

开发者 https://www.devze.com 2023-03-25 18:47 出处:网络
I want to disable the F5 on Webbrowser. For this I can use Application.OnMessage. But I want to force this rule when the WB focused.

I want to disable the F5 on Webbrowser. For this I can use Application.OnMessage. But I want to force this rule when the WB focused.

But every kind are failed:

1.) Get the HWN开发者_开发问答D of the WB - to compare the Msg.hwnd

2.) Get the focused state of the WB, or see when it is focused

Thanks for every idea to this problem!

dd


I assume your real goal is disabling a reload or refresh of the currently displayed web page (usually issued by pressing F5). Further assuming you are talking about an embedded Internet Explorer I would suggest using TEmbeddedWB from bsalsa. It has an event OnRefresh which lets you cancel the refresh by setting Cancel:= True. So no need to catch keys manually.

If you don't have the choice to choose TEmbeddedWB and are stuck with TWebBrowser then a look at the implementation of OnRefresh could nevertheless be inspiring.


As I think the best way is to check the ClassName of the hwnd what I got in Application.Onmessage.

This is just like "disable context menu" is based on the "Internet_Explorer_Server" classname.

See the example:

procedure TDDGoogleMapsObject.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
var
    szClassName: array[0..255] of Char;
const
    ie_name = 'Internet Explorer_Server';
begin
    if Msg.message = WM_KEYDOWN then
        if Msg.wParam = VK_F5 then begin
            GetClassName(Msg.HWND, szClassName, SizeOf(szClassName));
            if lstrcmp(@szClassName[0], @ie_name[1]) = 0
                then Handled := True;
            if not Handled
                then beep;
        end;
end;

This can check the source of the VK_F5 key. If it is from IE windows then we disable it. Another case we allow to push it...

Thanks for your help: dd

0

精彩评论

暂无评论...
验证码 换一张
取 消