Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable right click on SHDocVw.WebBrowser?
#1
Is it possible to disable (catch) right click on a SHDocVw.WebBrowser control?
I want to disable the right click menu which shows: Back, Forward....Properties

Function shdoc_rclick_disable
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 ActiveX 0x54030000 0x0 10 9 200 101 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#2
just need to subclass the control and catch the right click event
 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 ActiveX 0x54030000 0x0 10 9 200 101 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,;SHDocVw.WebBrowser we3
,;we3._getcontrol(id(3 hDlg))
,SetTimer hDlg 1 100 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 3 0)
,,KillTimer hDlg wParam    
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_RBUTTONDOWN
,out "right click disabled"
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,
,;case ...

ret R
#3
Thanks!

EDIT:
Noticed when rapid right clicking the menu would sometimes show.
But it seems to work well when changing in case WM_RBUTTONDOWN to case [WM_RBUTTONDOWN,WM_RBUTTONUP] 
(Probably the right mouse up get's detected and let through)
Thanks again!
#4
I forgot about the apps key (next to the windows key, VK_APPS).
I could not disable (catch) the VK_APPS key, it would still render the right click menu.
I looked at the message and I found that using WM_CONTEXTMENU works to catch all context menu's.

I would still like to know if catching (disabling) the VK_APPS key is possible?
(with disabling I mean: not rendering the right click menu specifically when the VK_APPS key is send)

Function shdoc_rclick_disable
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 ActiveX 0x54030000 0x0 10 9 200 101 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,;SHDocVw.WebBrowser we3
,;we3._getcontrol(id(3 hDlg))
,SetTimer hDlg 1 100 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 3 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_CONTEXTMENU
,out "right click disabled"
,ret
,case [WM_KEYDOWN,WM_KEYUP] ;; This does not work, disable above 'case WM_CONTEXTMENU' part to test this
,sel(wParam)
,,case VK_APPS
,,out "apps key disabled"
,,ret


;WM_LBUTTONUP 0(0x0) 4980783(0x4c002f)
;WM_NCHITTEST 0(0x0) 33555286(0x2000356)
;WM_TIMER 4096(0x1000) 0(0x0)
;WM_NCHITTEST 0(0x0) 33555286(0x2000356)
;WM_GETDLGCODE 93(0x5d) 56424912(0x35cf9d0) <================
;WM_KEYDOWN 93(0x5d) 22872065(0x15d0001) <================
;apps key disabled
;WM_TIMER 4096(0x1000) 0(0x0)
;WM_KEYUP 93(0x5d) -1050869759(0xc15d0001) <================
;apps key disabled
;WM_CONTEXTMENU 525630(0x8053e) -1(0xffffffff) <================
;WM_NCHITTEST 0(0x0) 28705577(0x1b60329)


int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,
,;case ...

ret R
#5
msdn says this 

The WM_CONTEXTMENU message is also generated when the user presses and releases the VK_APPS key. 

Handling the WM_CONTEXTMENU message is all you need. don't need to handle any other messages. covers all (right click and menu key and shift+F10) etc. for the context menu.
If you wanted you could also replace it with your own menu.
 
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;3 ActiveX 0x54030000 0x0 10 9 200 101 "SHDocVw.WebBrowser"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,;SHDocVw.WebBrowser we3
,;we3._getcontrol(id(3 hDlg))
,SetTimer hDlg 1 100 0
,case WM_TIMER
,sel wParam
,,case 1
,,int wies=child("" "Internet Explorer_Server" id(3 hDlg)); if(wies=0) ret
,,SetWindowSubclass(wies &sub.WndProc_Subclass 3 0)
,,KillTimer hDlg wParam
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WndProc_Subclass
function# hwnd message wParam lParam uIdSubclass dwRefData

;OutWinMsg message wParam lParam ;;uncomment to see received messages

sel message
,case WM_CONTEXTMENU
,out "right click disabled"
,ret

int R=DefSubclassProc(hwnd message wParam lParam)

sel message
,case WM_NCDESTROY
,RemoveWindowSubclass(hwnd &sub.WndProc_Subclass uIdSubclass)
,
,;case ...

ret R
#6
Thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)