[HELP]problem with TWebBrowser and keyboard shortcut/popup menu

Hi everyone,

i have a major problem with the TWebBrowser component.

i need to create my own Webbrowser in order to prevent anyone to enter a http address. i'm using the TWebbrowser (Delphi 7, BTW). Everything seems fine except that using the keyboard Shortcut Ctrl+N, i can open a completely new IE window with the address bar.
Any one has a solution to prevent those shortcut to be enabled ?

and also, if anyone has a solution to prevent the popup menu from right click ?

as this is quite urgent (but i don't know about the difficulty), i'll put the recommended 250 points for that question.
and if possible a sample would be helpful !

thanks in advance for any help !

Guillaume
fsurferAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russell LibbySoftware Engineer, Advisory Commented:

Not sure if there is a better way to hook the web browser control, but this is one way of doing it.

1.) Drop a TApplicationEvents component on your form, or create a method to handle the Application.OnMessage yourself (take your pick)

2.) Add the following code to handle the messages at the application level, before they reach the webbrowser control.

// This was coded using the TApplicationEvents.OnMessage method
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
var  lpClass:    Array [0..1024] of Char;
begin

  // Attempt to get the class name
  if (GetClassName(Msg.hwnd, lpClass, 1024) > 0) then
  begin
     // Check the class against known IE class name
     if (StrIComp(@lpClass, 'Internet Explorer_Server') = 0) then
     begin
        // Message directed to web browse control
        case Msg.message of
           // Eat the message if CTRL-N
           WM_KEYDOWN        :  Handled:=(Msg.wParam = Ord('N')) and (GetKeyState(VK_CONTROL) shr 15 = 1);
           // Eat the right mouse button
           WM_RBUTTONDOWN    :  Handled:=True;
           WM_RBUTTONDBLCLK  :  Handled:=True;
        else
           // Let IE handle it
           Handled:=False;
        end;
     end
     else
        // Not handling the message here
        Handled:=False;
  end
  else
     // Not handling the message here
     Handled:=False;

end;

---

The only caveat I found to doing it this way is that the Cut/Copy/Paste menu for the psuedo "edit" controls in the web page never gets displayed (because the code eats the right mouse button events). I did try catching the WM_INITMENUPOPUP, but the code never fired, most likely because its going to IE's message queue, and not your application. But, it does keep IE's menu from displaying....

Hope this helps some,
Russell


0
ginsonicCommented:
For the right click problem use:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, OleCtrls, SHDocVw_TLB;


type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure MessageLoop(var Msg:TMsg;var Handled:Boolean);
procedure FormCreate(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.MessageLoop(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP) then
handled:=True
else Handled := False
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := MessageLoop;
end;
end.
0
ginsonicCommented:
Use the OnNewWindow2 event. If you want to block all new windows, always set Cancel := True.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

fsurferAuthor Commented:
hi,

thanx for your both answers, but i've found myself the solution, found at this page : http://www.euromind.com/iedelphi/embeddedwb.htm . It comes with examples about preventing shortcut keys, popup menu, ...

the advantage of this component is that you can control the component more accurately and it's free :)

if you agree, i'll refund and close the question.

best regards,

Guillaume
0
ginsonicCommented:
I use this component ( EmbeddedWB ) and I'm not sure that you can do all these jobs without using my code :)

My comments are exactly what you ask for ( the codes are snaped from my browser that use the EmbeddedWB component ) .
0
ginsonicCommented:
... and if you will use the EmbeddedWB will need additional codes to use TAB and ENTER keys in web pages, to modify before use XP themes ... Trust me, I'm an experts :P on this component.
But as a general conclusion ... is a great component !
0
Russell LibbySoftware Engineer, Advisory Commented:

Nick,

My comments are also exactly what was asked for... ;-)

Your code for menu blocking is very close to what I already suggested first, but I opted to block the right mouse down for just the web browser window, and not all child windows. I also found that a right mouse dblclick could be used to get the menu to appear, thus the reason for the WM_RBUTTONDBLCLK check.

In regards to the new window blocking, I opted for catching/tossing the CTRL-N key combination, because I found that the OnNewWindow2(...) event was NOT getting fired (at least on my system).

Best Regards,
Russell
0
fsurferAuthor Commented:
hi both,

First, ginsonic, with this control, i've been able to prevent just the keyboard shortcuts involving the Ctrl key. All others are allowed (especially TAB or ENTER). Now i may not know all the keyboard shortcuts used in IE :)

(tip : in the OnTranslateAccelerator event, put this code, and everything goes fine :
function TNewNav.EmbeddedWB1TranslateAccelerator(const lpMsg: PMsg;
  const pguidCmdGroup: PGUID; const nCmdID: Cardinal): HRESULT;
begin
     if (getkeystate(VK_CONTROL) < 0) then
        result := S_OK
     else
         result := S_FALSE;
end;

Ok, i know that this code prevent copy/paste... but... :)
)

Both of you gave a correct answer to the question. As i've found my self the solution - unfortunately for me - before i read your answers, i read the FAQ & Help of EE site and found something "when i answer my self a question".

But i will consider the fact that you have both answered correctly the question.
So i will split the points between you two, if you find it convenient ?

best regards,

Guillaume
0
Russell LibbySoftware Engineer, Advisory Commented:

As far as I'm concerned, keep the points if you found the answer yourself (I'm assuming you found another way to circumvent the popup menu as well?).

Regards,
Russell
0
fsurferAuthor Commented:
Russel,

True. With this component, you have an event OnShowContextMenu.
To prevent it to open, just one line of code :

function TNewNav.EmbeddedWB1ShowContextMenu(const dwID: Cardinal;
  const ppt: PPoint; const pcmdtReserved: IInterface;
  const pdispReserved: IDispatch): HRESULT;
begin
     result := S_OK;
end;

for the question points, you'll have them also... just waiting for ginsonic answer.

best regards,

Guillaume
0
ginsonicCommented:
For me the points aren't important, too. I have more than 100.000 points ;P

I wished to say that you must add couple features (codes) to can use it . Go to Google and input in search box couple words. After that press Enter key. How you will see this action don't have any result.

In same time try to visit a webpage that use XP style. Compare IE with your browser.

Nick

P.S. Whay you wish to block a new browser session ? When you try to create a new browser windows you can force the application to create a new own browser windows and not IE. Couple lines to do that.
0
fsurferAuthor Commented:
hi Nick,

i'm working in a cybercafe. i have an application to manage the cybercafe and secure the computers. But i want  for some special cases the user to be able to see some special websites without being able to surf on any other website.

So, the thing is quite simple : i want to create a browser that cannot browse on any other website than the one i have selected by a mean of mine. if i can't disable the keyboard shortcut, i can't prevent a user from opening a new browser with Ctrl+N. if i can't prevent the popup menu to open, i can't prevent the user from opening a new browser also. That's why i wanted to block the shortcut and menu.

just using the EmbeddedWB (meaning with no address bar nor other toolbar) isn't enough for me. i want to have my own browser where i disable almost everything except to see the content of a selected website.

i don't care it doesn't look like IE. i just want a window with a frame where i can display almost every html pages ;)

thanks for your interest :)

as you wish, guys, for the points.

best regards,

Guillaume
0
ginsonicCommented:
I understand now :)
Good luck !
0
fsurferAuthor Commented:
Thanks again for your answers guys !

such help is very much appreciated, and it's always a pleasure to learn workarounds or other way to do things ! :)

so if you don't mind, i'll refund and close the question :)

(i have another question in my bag ;)

best regards,

Guillaume
0
Russell LibbySoftware Engineer, Advisory Commented:
No problem here.

Regards,
Russell
0
moduloCommented:
PAQ-ing this question and refunding the 250 points by CS request.

modulo

Community Support Moderator
Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
-Karamja-Commented:
Topic handled but not PAQ?
I will leave a message in CleanUp to get this topic PAQ-ing,
Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Karamja (Alan)
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.