先看消息的定义:
TWMContextMenu = packed record Msg: Cardinal; hWnd: HWND; case Integer of 0: ( XPos: Smallint; YPos: Smallint); 1: ( Pos: TSmallPoint; Result: Longint); end; TWMShowWindow = packed record Msg: Cardinal; Show: BOOL; Status: Longint; Result: Longint; end; TWMSize = packed record Msg: Cardinal; SizeType: Longint; { SIZE_MAXIMIZED, SIZE_MINIMIZED, SIZE_RESTORED, SIZE_MAXHIDE, SIZE_MAXSHOW } Width: Word; Height: Word; Result: Longint; end;
看这个函数,如果Result<>0,就代表处理过了,直接退出:
procedure TControl.WMContextMenu(var Message: TWMContextMenu); var Pt, Temp: TPoint; Handled: Boolean; PopupMenu: TPopupMenu; begin if Message.Result <> 0 then Exit; if csDesigning in ComponentState then begin inherited; Exit; end; Pt := SmallPointToPoint(Message.Pos); if InvalidPoint(Pt) then Temp := Pt else begin Temp := ScreenToClient(Pt); if not PtInRect(ClientRect, Temp) then begin inherited; Exit; end; end; Handled := False; DoContextPopup(Temp, Handled); Message.Result := Ord(Handled); if Handled then Exit; PopupMenu := GetPopupMenu; if (PopupMenu <> nil) and PopupMenu.AutoPopup then begin SendCancelMode(nil); PopupMenu.PopupComponent := Self; if InvalidPoint(Pt) then Pt := ClientToScreen(Point(0, 0)); PopupMenu.Popup(Pt.X, Pt.Y); Message.Result := 1; end; if Message.Result = 0 then inherited; end;
基本上每个消息都有一个Result,代表是否(正确)处理过了
原文:http://www.cnblogs.com/findumars/p/5178665.html