Disable right-click context nenu in a HTML dialog based application

Although there are many similar questions asked on EE I have scanned through many of them and haven’t found an answer to my question. I’ve made a dialog based wizard-style application which inherits from CmultiPageDHtmlDialog. I want to prevent the user from displaying the right-click context menu. The main reason is so that they don’t navigate without using by navigation buttons.

Any suggestions? Thanks!
Who is Participating?
Roshan DavisConnect With a Mentor Commented:
And also prevent pressing *BACKSPACE*
For that you can filter these keypresses in the "PreTranslateMessage" function like

BOOL CmultiPageDHtmlDialogEx::PreTranslateMessage(MSG* pMsg)
      if ( pMsg->hwnd == m_hHTMLWnd &&
             pMsg->message == WM_KEYDOWN &&
             pMsg->wParam == VK_BACK )
            return FALSE;

      return CDialog::PreTranslateMessage(pMsg);

Rosh :)
jkrConnect With a Mentor Commented:
You could override the 'OnRButtonDown()'  handler to do nothing...
AndyAinscowFreelance programmer / ConsultantCommented:
I have never used the CmultiPageDHtmlDialog so the following may not work.

In your dlg override the PreTranslateMessage fn.
then add
      if(pMsg->message == WM_RBUTTONDOWN)  //possibly also trap WM_RBUTTONUP
        return TRUE;
returning true tells the app it has been handled - so it is hopefully not passed on and generates the context menu
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Roshan DavisCommented:
Ooops, ite "return TRUE"
Rosj :o)
wjdashwoodAuthor Commented:
Thanks everyone for your contributions! Roshmon’s code worked perfectly except I don’t know what the equivalent of m_hHTMLWnd is in my app. Why do I need this line (pMsg->hwnd == m_hHTMLWnd) and how do I find the correct vairable name in my app?

Hopefully I'll share some points out this evening; I'm on dial-up at moment :(

AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
The m_hHTMLWnd is the HWND of your dialog  (GetSafeHwnd() fn will return it)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.