您的位置:首页 > 其它

基本上每个消息都有一个Result,代表是否(正确)处理过了(但是是否继续传递,还得研究)

2016-02-02 22:35 288 查看
先看消息的定义:

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: