Undo Method for blocking the right-click menu of chtmlview/cwebbrower2

Source: Internet
Author: User
Undo Method for blocking the right-click menu of chtmlview/cwebbrower2


Source code: http://msdn.microsoft.com/msdnmag/issues/01/09/code/CQA0109.exe

Before reading this article, you should first understand the IE control and chtmlview.
The chtmlctrl class of Bao Luo is derived from chtmlview. It uses the loadfromresource function of chtmlview to open the webpage from the resource.

Question 1: I like your chtmlctrl class, which is exactly what I need to do. But I want to know, can I disable the pop-up menu when right-clicking a webpage? I don't want users to see my HTML source files. I have reloaded the wm_contextmenu message ing of chtmlctrl, and the result is useless.

Question 2: I want to disable chtmlview or cwebbroser2 from the context menu. I have reloaded the message ing function wm_rbuttondown, but it does not work. Please help!

A: I'm glad you liked my chtmlctrl class. At that time, I didn't consider this unpopular right-click menu. Now I can point out a simple way to disable the right-click menu:


You only need a line ---- write the body in your HTML.
<Body oncontextmenu = "Return false">

It will tell the browser: Hey, don't show the annoying right-click menu!

You can construct your own menu as follows:

Oncontextmenu = "showmymenu (); Return false"

Showmymenu can be a piece of JavaScript used to create your own personalized menu.


But here we are talking about C ++, which is not suitable for Javascript, so ------ let me use C ++ to implement this, the official method is to use the idochostuihandler interface (there is an example of using the idochostuihandler to disable the right-click menu of the chtmlview in the http://www.codeguru.com), but it is too troublesome to do so, this is a tough experience for programmers who do not understand com!

Your idea is to overload the message ing of wm_contextmenu or wm_rbuttondown. Indeed, most of the windows are them. But not here.
The reason is: chtmlview and cwebbrowser2 are not real input windows, which have many invisible windows. In order to see these windows, we open the window tool spy ++ of VC ++.

Afxframeorview42d // chtmlctrl
Shell embedding
Shell docobject View
Internet assumer_server

In the browser window, there are three parent/child windows on the real input window. Can the wm_contextmenu and wm_rbuttondown messages be obtained by the input window?

The Internet assumer_server window receives the input, which means that you must use subclass to process the message in wm_contextmenu.
Therefore, we must know the handle of Internet assumer_server.

There are many ways to obtain the handle of the Internet assumer_server. findwindow does not work, because it can only find the top-level window (111222 Note: I did not think of findjavaswex, and any window can be found through the ex function ). The following is the function I wrote to obtain the window.
Static hwnd getlastchild (hwnd hwndparent)
Hwnd = hwndparent;
While (true ){
Hwnd hwndchild =: getwindow (hwnd, gw_child );
If (hwndchild = NULL)
Return hwnd;
Hwnd = hwndchild;
Return NULL;

Because Internet assumer_server is the only sub-window of the IE control and chtmlview, the handle we found using getlastchild is accurate.

Next we will reload the message ing of wm_contextmenu:

Class cmyiewnd: Public cwnd {
Afx_msg void oncontextmenu (cwnd * pwnd, cpoint POS ){}
Declare_message_map ();

The message of the wm_contextmenu does not film anything. The oncontextmenu is an empty function and will not display the menu.
Next we will apply this cmyiewnd. I will add it as a member variable to cmyhtmlctrl:

Class cmyhtmlctrl: Public chtmlctrl {
Cmyiewnd m_myiewnd;

All the above operations must be effective only after the window of the Internet assumer_server is retrieved through subclass. So where can we do it?
You can do whatever you want. The following is the right-click menu prohibited after the web page is browsed.

Void cmyhtmlctrl: onnavigatecomplete2 (lpctstr strurl)
If (! M_myiewnd.m_hwnd ){
Hwnd = getlastchild (m_hwnd );
M_myiewnd.subclasswindow (hwnd );

OK ~~ All the work has been completed. Next I will explain the actual process: when the user opens the dialog box, this dialog box creates the chtmlctrl window to open the HTML document. After the document is opened, it will be sent, which will touch onnavigatecomplete2, cmyhtmlctrl: onnavigatecomplete2. At this time, the Internet assumer_server will be found, and some messages will be processed by subclasswindow in cmyiewnd, the wm_contextmenu of cmyiewnd is useless at this time, and the right-click menu disappears.

It must be noted that the handle of the Internet assumer_server window is changed frequently, so we must do more for displaying the HTML dialog box.
You must use unsubclass and resubclass effectively.
Now, we have completed the introduction of how to disable the right-click menu of the cwebbrowser control/chtmlview by Using unofficial methods.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.