.NET Framework - Question about WebBrowser

Asked By Adam
01-Nov-07 02:06 PM
Hello,

I want to disable context menu on WebBrowser component.

Is possible to catch mouse clik on WebBrowser component? To catch key
events I have to set KeyPreview to true. OK, but what with mouse click.

Or maybe some special html tag? I tried with JavaScrip scripts to disable
right click but they works only on Internet Explorer (full IE, like in XP
windows etc...)

How disable context menu on WebBrowser in mobile device?
MessageWindow.SendMessage
(1)
OpenNETCF
(1)
WebBrowser
(1)
DllImport
(1)
WndProc
(1)
IntPtr
(1)
XP
(1)
Message.Create
(1)
  Adam replied...
01-Nov-07 05:54 PM
Dnia Thu, 1 Nov 2007 19:06:40 +0100, Adam napisa³(a):

[cut]

I found something like this:
http://tinyurl.com/38f4vc
It works but
--
//instead of the normal Application.Run(new Form1); we must manually
display
the form
Form1 formInstance = new Form1();
formInstance.Visible = true;

PeekMsg msg = new PeekMsg();
while (1 == 1)
{
PeekMessage(out msg, formInstance.Handle, 0, 0, WM_REMOVE);
--

is crazy. Never ending loop on windows mobile?
What about battery life?

Is there any PROPER WAY?
Is possible to set Hook on mouse? How can I do this?
  Jin Chang replied...
03-Nov-07 12:25 AM
Two quick comments about this.

First, I also found the context menu to be an issue and looked for
ways to disable/prevent it.  Based on the answers I found, there is
simply no "proper" way of doing this.  The next release may address
this oversight and provide a way to disable it.  On a similar note,
the progress-bar that appear when the WebBrowser control content is
loaded may also become optional.

Second, what you've found may not be a bad solution.  Your concern
about the battery life being depleted by the loop shouldn't be of
concern because that's what Windows CE/Mobile does anyway -- the
message loop.

- Jin
  Peter Foot [MVP] replied...
05-Nov-07 09:01 AM
You need to send a DTM_ENABLECONTEXTMENU  message to the control handle
(WM_USER + 110). Set the LPARAM to 0 to disable, 1 to enable.

Peter

--
Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility
  Adam replied...
05-Nov-07 10:28 AM
Dnia Mon, 5 Nov 2007 15:01:16 +0100, Peter Foot [MVP] napisa³(a):


I have a problem with this.
I simply put a WebBrowser and button component on a form and add this code
to Button onClick event:

IntPtr handle = webbrowser1.Handle;
const int WM_CLOSE = 0x10;
const int WM_USER = 0x0400;
const int DTM_ENABLECONTEXTMENU = WM_USER + 110;

1.//Message msg = Message.Create(handle, DTM_ENABLECONTEXTMENU,
IntPtr.Zero, (IntPtr) 1);
1.//MessageWindow.SendMessage(ref msg);


2.SendMessage(handle, DTM_ENABLECONTEXTMENU, 0, 0);

and
[DllImport("coredll.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int
lParam);

If I use 1 (Message etc..) with WM_CLOSE, webbrowser1 dissapear.
If I use 2 (with native SendMessage) with WM_CLOSE, webbrowser1 dissapear.

If I use 1 or 2 with DTM_ENABLECONTEXTMENU nothing change and webbrowser
still have a context menu.

What am I doing wrong and what is the correct way of doing it?
  Adam replied...
05-Nov-07 10:40 AM
Dnia Mon, 5 Nov 2007 15:01:16 +0100, Peter Foot [MVP] napisa³(a):


I have a problem with this.
I simply put a WebBrowser and button component on a form and add this code
to Button onClick event:

IntPtr handle = webbrowser1.Handle;
const int WM_CLOSE = 0x10;
const int WM_USER = 0x0400;
const int DTM_ENABLECONTEXTMENU = WM_USER + 110;

1.//Message msg = Message.Create(handle, DTM_ENABLECONTEXTMENU,
IntPtr.Zero, (IntPtr) 0);
1.//MessageWindow.SendMessage(ref msg);


2.SendMessage(handle, DTM_ENABLECONTEXTMENU, 0, 0);

and
[DllImport("coredll.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int
lParam);

If I use 1 (Message etc..) with WM_CLOSE, webbrowser1 dissapear.
If I use 2 (with native SendMessage) with WM_CLOSE, webbrowser1 dissapear.

If I use 1 or 2 with DTM_ENABLECONTEXTMENU nothing change and webbrowser
still have a context menu.

What am I doing wrong and what is the correct way of doing it?
  Adam replied...
06-Nov-07 01:37 PM
Dnia Mon, 5 Nov 2007 15:01:16 +0100, Peter Foot [MVP] napisa³(a):


Ok, I use Windows CE Remote Spy and i see that WebBrowser on my Form look
like this:

Form1 (my application with embedded webbrowser)
- <no name> #NETCF_AGL_CONTAINER
- <no name> (IExplore)
-<no name> (MSPIE Status)
-<no name> (PIEHTML)
of course with different window handle. I try to send message
In Windows CE Remote Spy I see that event like tap, tap&hold etc.. are
catched only by PIEHTML.

What am I doing wrong and what is the correct way of doing it?
  carnivore replied...
07-Nov-07 09:02 AM
Peter Foot [MVP] pisze:

Nevermind, I do this with override my form WndProc.

Thanks.
  RDub replied...
04-Dec-07 04:29 PM
I also was not able to get the code  you posted to disable the context menu
in a Flash ActiveX hosted by a (OpenNETCF 1.4) web browser control.  I
wanted to stop the Flash Settings menu from appearing.  If you hit the
allow the user to break out of my Kiosk mode type application.

What I finally wound up doing was to add a timer to the form that fired
every couple seconds.  In the timer tick event I enumerate all of the
running processes looking for the one that opened the balloon.  When it
finds the process (remnet.exe), it simply Kills it.  Kind'a  brutal way to
deal with this, but it seems to be working OK.

If anyone is able to get the Context Menu from displaying in the first pace,
I'd love to know how you made it happen.  Please post back here.

Ron W
Create New Account
help
function "?? _ _Elogger@@YAXXZ" (??_ _Elogger@@YAXXZ) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: long _ _thiscall uima::CAS::reset(void)" (_ _imp_?reset@CAS@uima@@QAEJXZ) referenced in function function _ _ehhandler$?initLogger@DaManagerImp@@AAEXXZ dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: void _ _thiscall uima::SofaFS::setRemoteSofaURI(char const *)" (_ _imp_? setRemoteSofaURI@SofaFS@uima@@QAEXPBD@Z) referenced processURI@DaSessionImp@@EAEPAUFilteredDocument@@PBD@Z) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: _ _thiscall uima::SofaFS::SofaFS(void)" (_ _imp_??0SofaFS@uima@@QAE@XZ) referenced in function "private const *, . . .)" (?info@Category@log4cpp@@QAAXPBDZZ) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: virtual _ _thiscall icu_3_0::UnicodeString::~UnicodeString(void)" (_ _imp_?? 1UnicodeString@icu_3_0@@UAE@XZ) referenced in function createSourceSofa@DaSessionImp@@IAEXAAVSofaFS@uima@@@Z) dasdk.lib(DaManagerImp.obj) : error LNK2001: unresolved external symbol "_ _declspec(dllimport) public: virtual _ _thiscall icu_3_0::UnicodeString::~UnicodeString(void)" (_ _imp_?? 1UnicodeString@icu_3_0@@UAE@XZ) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: class uima::SofaFS _ _thiscall uima::CAS::createSofa(class uima::SofaID const &, char const *)" (_ _imp_ createSourceSofa@DaSessionImp@@IAEXAAVSofaFS@uima@@@Z) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: class uima::SofaID const & _ _thiscall uima::AnnotatorContext::mapToSofaID(class icu_3_0::UnicodeString const &)" (_ _imp_? mapToSofaID createSourceSofa@DaSessionImp@@IAEXAAVSofaFS@uima@@@Z) dasdk.lib(DaSessionImp.obj) : error LNK2019: unresolved external symbol "_ _declspec(dllimport) public: class uima::AnnotatorContext * _ _thiscall uima::AnnotatorContext::getDelegate(class icu_3_0::UnicodeString const &)const " (_ _imp_? getDelegate
Control.CreateControl() vid System.Windows.Forms.Control.WmShowWindow(Message& m) vid System.Windows.Forms.Control.WndProc(Message& m) vid System.Windows.Forms.ScrollableControl.WndProc(Message& m) vid System.Windows.Forms.ContainerControl.WndProc(Message& m) vid System.Windows.Forms.Form.WmShowWindow(Message& m) vid System.Windows.Forms.Form WndProc(Message& m) vid = System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) vid System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& = m) vid System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 = msg, IntPtr wparam, IntPtr 20 System.Windows.Forms.Control.WmShowWindow(Message& = m)<BR> vid = 20 System.Windows.Forms.Control.WndProc(Message& m)<BR> vid = System.Windows.Forms.ScrollableControl.WndProc(Message& = m)<BR> = 20 vid System.Windows.Forms.ContainerControl.WndProc(Message& = 20 m)<BR> vid = System.Windows.Forms.Form.WmShowWindow(Message& = 20 m)<BR> vid
dwSize; public IntPtr hrasconn; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int) (RasFieldSizeConstants.RAS_MaxEntryName + 1))] public string szEntryName; } [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasEnumEntries( string reserved, / / reserved, must be occurred uint dwExtendedError / / extended error information for some errors ); public partial class RASWrapper { protected RASWrapper() { } [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasDial( [In]RASDIALEXTENSIONS lpRasDialExtensions, / / pointer to a handler for RasDial events ref IntPtr lphRasConn / / pointer to variable to receive / / connection handle ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasHangUp( IntPtr hrasconn / / handle to the RAS connection to hang up ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasGetErrorString( uint uErrorValue, / / error to get StringBuilder lpszErrorString, / / buffer to hold error string [In]int cBufSize / / size, in characters, of buffer ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasEnumConnections( [In, Out]RASCONN[] lprasconn, / / buffer lpcb, / / size in bytes of buffer out int lpcConnections / / number of connections written to buffer ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasEnumDevices( [In, Out]RASDEVINFO[] lpRasDevInfo, / / buffer of the buffer out int lpcDevices / / receives the number of / / entries written to the buffer ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasGetConnectStatus( IntPtr hrasconn, / / handle to RAS connection of interest [In, Out]RASCONNSTATUS lprasconnstatus / / buffer to receive status data ); [DllImport("coredll.dll", CharSet = CharSet.Auto)] public extern static uint RasConnectionNotification( IntPtr hrasconn, / / handle to a