1 uses MSHtml;
2
3
4
5 //在控件标签additional中找到TApplicationEvents控件,拖到窗体上.在TApplicationEvents的OnMessage事件中加入以下代码:
6
7 //替换右键菜单
8
9
10
11 procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
12
13 var
14
15 mPoint: TPoint;
16
17 begin
18
19 if IsChild(WebBrowser.Handle, Msg.Hwnd) and
20
21 ((Msg.Message = WM_RBUTTONDOWN) or (Msg.Message = WM_RBUTTONUP)) then
22
23 begin
24
25 GetCursorPos(mPoint); //得到光标位置
26
27 pm5.Popup(mPoint.X, mPoint.Y); //弹出popupmenu1的菜单
28
29 Handled := True;
30
31 end;
32
33 end;
34
35
36
37 或者
38
39 //屏蔽右键菜单
40
41
42
43 procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
44
45 begin
46
47 with Msg do
48
49 begin
50
51 if not IsChild(WebBrowser1.Handle, hWnd) Exit;
52
53 Handled := (message = WM_RBUTTONDOWN) or (message = WM_RBUTTONUP) or (message = WM_CONTEXTMENU);
54
55 end;
56
57 end;