有时侯为了界面的简洁好看还有程序的安全性,我们都希望WebBrowser这个控件可以实现去除滚动条,边框,右键,下面这两个方法可以充分满足我们的需求:

//去除边框,滚动条

 

1 procedure WB_Set3DBorderStyle(Sender: TObject; bValue: Boolean);
2  var
3 Document : IHTMLDocument2;
4 Element : IHTMLElement;
5 StrBorderStyle: string;
6  begin
7
8  try
9 Document := TWebBrowser(Sender).Document as IHTMLDocument2;
10 TWebBrowser(Sender).OleObject.Document.Body.Scroll := 'no';//去除滚动条
11 if Assigned(Document) then
12 begin
13 Element := Document.Body;
14 if Element <> nil then
15 begin
16 case BValue of
17 False: StrBorderStyle := 'none';
18 True: StrBorderStyle := '';
19 end;
20 Element.Style.BorderStyle := StrBorderStyle;
21 end;
22 end;
23 except
24 end;
25 end;
26
27 在窗体的DocumentComplete事件中使用
28
29 去除右键:
30
31 //禁止右键
32 function MouseProc(nCode: Integer; wParam, lParam: Longint): Longint; stdcall;
33 var
34 szClassName: array[0..255] of Char;
35 const
36 ie_name = 'Internet Explorer_Server';
37 begin
38 case nCode < 0 of
39 True:
40 Result := CallNextHookEx(HookID, nCode, wParam, lParam)
41 else
42 case wParam of
43 WM_RBUTTONDOWN,
44 WM_RBUTTONUP:
45 begin
46 GetClassName(PMOUSEHOOKSTRUCT(lParam)^.HWND, szClassName, SizeOf(szClassName));
47 if lstrcmp(@szClassName[0], @ie_name[1]) = 0 then
48 Result := HC_SKIP
49 else
50 Result := CallNextHookEx(HookID, nCode, wParam, lParam);
51 end
52 else
53 Result := CallNextHookEx(HookID, nCode, wParam, lParam);
54 end;
55 end;
56 end;
57

 

 

 

在窗体的Create事件中加入
HookID := SetWindowsHookEx(WH_MOUSE, MouseProc, 0, GetCurrentThreadId());

做完上面这几步,打开一个网页看看,再右键看看,是不是这种效果很满意呢?

';

 

posted on 2011-01-11 21:21  东睿软件工作室  阅读(3336)  评论(0编辑  收藏  举报