1

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 HWND 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

durumdara
  • 3,411
  • 4
  • 43
  • 71
  • A TWebBrowser (Internet Explorer) in your application or an external browser? – Heinrich Ulbricht Aug 03 '11 at 12:04
  • You don't need to "disable F5 when the browser is focused", rather you need to intercept the F5 window message. You don't control the keyboard in windows. You receive messages, which you can intercept and then "mark as handled". This works out the same, but if you understand what it is you're doing, you'll be able to figure it out better. You don't need to hook F5 globally, and in fact doing so is problematic. – Warren P Aug 03 '11 at 14:23
  • I've solved similar question with @RRUZ help. http://stackoverflow.com/questions/5796029/a-way-to-redirect-keypresses-from-twebbrowser-to-the-parentform – EMBarbosa Aug 03 '11 at 21:01

2 Answers2

1

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.

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
  • Beside it looks a very good component, seems it is not being updated for the IE9... take a look at his forum and test it yourself before. – EMBarbosa Aug 03 '11 at 21:00
-2

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

durumdara
  • 3,411
  • 4
  • 43
  • 71