关于TWebBrowser的右键菜单的处理。(200分)

  • 主题发起人 主题发起人 kkkchenA
  • 开始时间 开始时间
K

kkkchenA

Unregistered / Unconfirmed
GUEST, unregistred user!
我用Webbrowser做了一个IE内核的浏览器,想对它的右键菜单做一些处理。
例如我想把默认菜单的“查看源文件”选项去掉。
在张硕的文章中,有一个处理的方式,但是是VC的,我对VC的了解很少。
有朋友能把它翻译为Delphi代码的么?
文章连接:http://blog.csdn.net/cathyeagle/archive/2004/09/19/109873.aspx

HRESULT CBrowserHost::ShowContextMenu(DWORD dwID, POINT *ppt,IUnknown *pcmdTarget,IDispatch *pdispObject)
{
#define IDR_BROWSE_CONTEXT_MENU 24641
#define IDR_FORM_CONTEXT_MENU 24640
#define SHDVID_GETMIMECSETMENU 27
#define SHDVID_ADDMENUEXTENSIONS 53

HRESULT hr;
HINSTANCE hinstSHDOCLC;
HWND hwnd;
HMENU hMenu;

CComPtr spCT;
CComPtr spWnd;

MENUITEMINFO mii = {0};
CComVariant var, var1, var2;
hr = pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&spCT);
hr = pcmdTarget->QueryInterface(IID_IOleWindow, (void**)&spWnd);
hr = spWnd->GetWindow(&hwnd);//取得浏览器窗口句柄
hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
if (hinstSHDOCLC == NULL)
{
// Error loading module -- fail as securely as possible
return;
}
hMenu = LoadMenu(hinstSHDOCLC, MAKEINTRESOURCE(IDR_BROWSE_CONTEXT_MENU));
hMenu = GetSubMenu(hMenu, dwID);
// Get the language submenu
hr = spCT->Exec(&CGID_ShellDocView, SHDVID_GETMIMECSETMENU, 0, NULL, &var);
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_SUBMENU;
mii.hSubMenu = (HMENU) var.byref;
// Add language submenu to Encoding context item
SetMenuItemInfo(hMenu, IDM_LANGUAGE, FALSE, &mii);
// Insert Shortcut Menu Extensions from registry
V_VT(&var1) = VT_INT_PTR;
V_BYREF(&var1) = hMenu;
V_VT(&var2) = VT_I4;
V_I4(&var2) = dwID;
hr = spCT->Exec(&CGID_ShellDocView, SHDVID_ADDMENUEXTENSIONS, 0, &var1, &var2);
// Remove View Source
DeleteMenu(hMenu, IDM_VIEWSOURCE, MF_BYCOMMAND);//删除“查看源文件”菜单项
// Show shortcut menu
int iSelection = ::TrackPopupMenu(hMenu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,//返回用户选择的菜单命令ID
ppt->x,
ppt->y,
0,
hwnd,
(RECT*)NULL);
// Send selected shortcut menu item command to shell
LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL);//发送到Internet Explorer_Server进行内部处理。
FreeLibrary(hinstSHDOCLC);
return S_OK;
}
 
這麼簡單的問題,搞這麼復雜!
在你的網頁中加入JS代碼即可!
代碼可以去搜索:

关于网页源代码屏蔽

2006-02-07 17:40更新 来源:转载文章 第1页/共5页 << 上一页 | 下一页 >>

很早就想写一篇关于网页源代码屏蔽的文章。是因为经常编出些JS脚本的之后,在沾沾自喜的同时,也在担心源代码会被人家看到,盗用我的脚本。所以一直以来,我都在尽力维护我的网页源代码的安全。虽然目前还没有找到完全安全的屏蔽方法(也就是说,这些方法在我想出来的同时,自己已经知道其弱点和破解方法了),但是,我这里有很多屏蔽的思路,来总结一下。


  众所周知,要保护一个页面,最基础的就是要屏蔽右键。而现在网 今日焦点:

• 北京消协开征手机资费意见 四大问题受关注
• “胡戈”馒头名字被抢注成商标 本人称并不介意
• 新联想发力美国 将在纽约推低端PC和笔记本电脑

广告


· 阳萎早泄----最新发现 · 90天让男人更强更自信!

· 7 天重现少女状态(图) · 让你找回新婚的感觉!


页上用得最多的是function click(),即下面这段代码:


〈script〉

function click(){

if(event.button==2){

alert( /'本网站欢迎您 !!/')/;

}

}

document.onmousedown=click

〈/script〉


  但是这种屏蔽方法的破解方法也是众所周知的。那就是连续单击鼠标左键和右键便又可以看到右键菜单了。但是,我见过一种很好的屏蔽右键的方法。它的原理和上面所说的不同。它并不是用JS来编写的脚本,而是利用定义网页属性来起到限制的作用。而且,在屏蔽中应该尽量的避开使用JS脚本。因为只要浏览者把IE 里的javascript脚本禁用了。那么一切屏蔽都白费。


  那么继续说那种通过修改网页属性的屏蔽右键的方法。这种方法利用了HTML里的〈body〉来作修改,它只有以下短短的一行代码:


〈body oncontextmenu=self.event.returnValue=false〉


  这里,定义了oncontextmenu。使得右键的值为false,起到了屏蔽右键的效果。现在,再试试看刚才的破解方法,已经不行了。左右键连击已经不能再打开右键菜单。不但是这个,再试试看其他的方法。无论你怎样的乱点,右键都没有用。因为在这个网页里,右键已经不存在了。对于一个不存在的功能键,你又能做什么呢?

  但是,屏蔽了右键还不能解决问题。如果我要复制一段文字,或是一张图片。那么,把它选中后用ctrl+C 再用 ctrl+V不就可以复制粘贴了嘛。对了,接下来要讲的




http://cn.tech.yahoo.com/060207/55/27rs4_1.html


剩下的自已去看吧!
思路開闊,比編程功能深厚更重要!
記得給分啊 :>)
 
修改网页的工作量太大了。加密密码验证之类的东西都做在浏览器上了。
 
完全屏蔽右键菜单很简单了,我只要在接口里面直接返回一个s_ok就可以了,但是右键菜单里面有一些功能也不能完全去掉,例如“另存为”,所以只能是修改那个菜单了。
有这方面经验的朋友介绍一下。
 
http://www.codeproject.com/miscctrl/WBCArticle.asp
找了点资料,放着先吧。
 
http://groups.yahoo.com/group/delphi-webbrowser 上找到的代码
PS: the code belowe uses (among others) the following units:
OleCtrls, EmbeddedWB, ActiveX, ieconst, shlobj,SHDocVw_TLB

-------------------------------Begining of CODE ---------------
function TForm1.EmbeddedWB1ShowContextMenu(const dwID: Cardinal;
const ppt: PPoint; const pcmdtReserved: IInterface;
const pdispReserved: IDispatch): HRESULT;
const
CContextMenuID = 24641;
CGetMimeSubMenuCommandID = 27;
CAddMenuExtensionsCommandID = 53;
var
syf : HRESULT;
ShDocLcHandle: THandle;
MustFreeLibrary: Boolean;
OleCommandTarget: IOleCommandTarget;
OleWindow: IOleWindow;
WindowHandle: HWND;
ParentMenu: HMENU;
ChildMenu: HMENU;
EncodingSubMenu: OleVariant;
ChildMenuItemInfo: MENUITEMINFO;
InParam, OutParam: OleVariant;
PopupResult: LongBool;
I, MenuItemCount: LongInt;
MenuState: LongWord;
begin
MustFreeLibrary := false;
ShDocLcHandle := GetModuleHandle('SHDOCLC.DLL');
if ShDocLcHandle = 0 then begin
ShDocLcHandle := LoadLibrary('SHDOCLC.DLL');
MustFreeLibrary := ShDocLcHandle <> 0;
end;
OleCommandTarget := pcmdtReserved as IOleCommandTarget;
OleWindow := pcmdtReserved as IOleWindow;
WindowHandle := 0;
if SUCCEEDED(OleWindow.GetWindow(WindowHandle)) then begin
ParentMenu := LoadMenu(ShDocLcHandle, MAKEINTRESOURCE
(CContextMenuID));
if ParentMenu <> 0 then begin
ChildMenu := GetSubMenu(ParentMenu, dwID);
{
This block (until DeleteMenus) should be commented-out due to some
bug occuring while the function
is finalized (probably when EncodingSubMenu is freed).
The content of EncodingSubMenu is somehow modified on the low level
by windows and is not later recognized by delphi which causes
Variant BadValue exception. The EncodingSubMenu variable cannot be
even
modified.
The block ends with two end's below that have to be commented-out
too if neccessary.
}
if SUCCEEDED(OleCommandTarget.Exec(@CGID_ShellDocView,
CGetMimeSubMenuCommandID,
OLECMDEXECOPT_DODEFAULT, Null, EncodingSubMenu)) then
begin
FillChar(ChildMenuItemInfo, SizeOf(ChildMenuItemInfo), 0);
ChildMenuItemInfo.cbSize := sizeof(MENUITEMINFO);
ChildMenuItemInfo.fMask := MIIM_SUBMENU;
ChildMenuItemInfo.hSubMenu := HMENU(@EncodingSubMenu);
SetMenuItemInfo(ChildMenu, IDM_LANGUAGE, FALSE,
ChildMenuItemInfo);
InParam := ChildMenu;
OutParam := dwID;
if (SUCCEEDED(OleCommandTarget.Exec(@CGID_ShellDocView,
CAddMenuExtensionsCommandID,
OLECMDEXECOPT_DODEFAULT, InParam, OutParam))) then begin
DeleteMenu(ChildMenu, IDM_PROPERTIES, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_VIEWSOURCE, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_COPYFORMAT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_COPYSHORTCUT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_COPYBACKGROUND, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_COPYCONTENT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_COPY, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_CUT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PASTEINSERT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PASTEFORMAT, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PASTESPECIAL, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PASTE, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SELECTALL, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVEBACKGROUND,
MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVETARGET, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVEPICTURE, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVE, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVEAS, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SAVECOPYAS, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_ADDFAVORITES, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SETWALLPAPER, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_CREATESHORTCUT,
MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_CREATELINK, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_SETDESKTOPITEM,
MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_FOLLOWLINKN, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PRINTTARGET, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PRINTQUERYJOBSPENDING,
MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PRINTPREVIEW, MF_BYCOMMAND);
DeleteMenu(ChildMenu, IDM_PRINT, MF_BYCOMMAND);
MenuItemCount := GetMenuItemCount(ChildMenu);
I := 0;
while MenuItemCount > 0 do begin
MenuState := GetMenuState(ChildMenu, I, MF_BYPOSITION);
if MenuState <> $FFFFFFFF then begin
if (MenuState and MF_SEPARATOR) = MF_SEPARATOR then
begin
DeleteMenu(ChildMenu, I, MF_BYPOSITION);
end else begin
I := I + 1;
end;
end else begin
I := I + 1;
end;
Dec(MenuItemCount);
end;
// *** END modifications in the menu
PopupResult := TrackPopupMenuEx(ChildMenu, TPM_LEFTALIGN
or
TPM_TOPALIGN or TPM_RETURNCMD or TPM_RIGHTBUTTON or
TPM_HORPOSANIMATION or TPM_VERPOSANIMATION,
ppt^.x, ppt^.y, WindowHandle, nil);
if PopupResult then
SendMessage(WindowHandle, WM_COMMAND, MAKEWPARAM(LOWORD
(PopupResult), 0), 0);
end;
end;
DestroyMenu( ParentMenu );
end;
end;
OleWindow := nil;
OleCommandTarget := nil;
if MustFreeLibrary and (ShDocLcHandle <> 0) then
FreeLibrary(ShDocLcHandle);
Result := S_OK;
end;
-------------------------------End of CODE ---------------
 
接受答案了.
 
后退
顶部