关于TControl类的WndProc方法的问题(79分)

  • 主题发起人 主题发起人 tropic
  • 开始时间 开始时间
T

tropic

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TControl.WndProc(var Message: TMessage);
var
Form: TCustomForm;
KeyState: TKeyboardState;
WheelMsg: TCMMouseWheel;
begin
if (csDesigning in ComponentState) then
begin
Form := GetParentForm(Self);
if (Form <> nil) and (Form.Designer <> nil) and
Form.Designer.IsDesignMsg(Self, Message) then Exit
end;
if (Message.Msg >= WM_KEYFIRST) and (Message.Msg <= WM_KEYLAST) then
begin
Form := GetParentForm(Self);
if (Form <> nil) and Form.WantChildKey(Self, Message) then Exit;
end
else if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then
begin
if not (csDoubleClicks in ControlStyle) then
case Message.Msg of
WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:
Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
end;
case Message.Msg of
WM_MOUSEMOVE: Application.HintMouseMessage(Self, Message);
WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
begin
if FDragMode = dmAutomatic then
begin
BeginAutoDrag;
Exit;
end;
Include(FControlState, csLButtonDown);
end;
WM_LBUTTONUP:
Exclude(FControlState, csLButtonDown);
else
with Mouse do
if WheelPresent and (RegWheelMessage <> 0) and
(Message.Msg = RegWheelMessage) then
begin
GetKeyboardState(KeyState);
with WheelMsg do
begin
Msg := Message.Msg;
ShiftState := KeyboardStateToShiftState(KeyState);
WheelDelta := Message.WParam;
Pos := TSmallPoint(Message.LParam);
end;
MouseWheelHandler(TMessage(WheelMsg));
Exit;
end;
end;
end
else if Message.Msg = CM_VISIBLECHANGED then
with Message do
SendDockNotification(Msg, WParam, LParam);
Dispatch(Message);
end;
以上是TControl类的WndProc方法,
请问else if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then
begin
if not (csDoubleClicks in ControlStyle) then
case Message.Msg of
WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:
Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
end;
作何解?特别是Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);有何作用?
本人对VCL了解甚少,又无意发类似VCL该如何学之类的贴子,故copy代码一段,望对此
段代码有过研究的高手不吝发表些脚注和评论,不甚感激.当然,不限此段代码,如自定义
消息的发送等问题也想一并请教



 
这句话的作用是将双击消息转换为单击消息.有一点比较重要的是,tcontrol不能接收windows消息.它的消息是父窗口传过来的.如果第二次单击是在tcontrol上,但每一次是在其他控件上.window发过来的消息是双击,但此时显然在tcontrol中不能作为双击处理.这个话题细谈有点复杂.必须对vcl有深刻的理解才行.如果有问题请和我邮件联系.scxby@163.com
 
else if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then
begin
if not (csDoubleClicks in ControlStyle) then
////请注意这里的if语句,表示这个控件不允许接受鼠标双击消息,但是鼠标消息总是应该响应的
case Message.Msg of
WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:
//所以如果消息是双击消息,应把它转换为单击消息,
Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
//以上三个消息减去2就是对应的单击消息.
end;
 
后退
顶部