没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|其它|编辑:郝浩|2004-03-02 10:16:00.000|阅读 1620 次
概述:
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
{ TObject.Dispatch accepts any data type as its Message parameter.
The
first 2 bytes of the data are taken as the message id to search for
in
the object's message methods. TDispatchMessage is an example of
such a
structure with a word field for the message id.
}
TDispatchMessage =
record
MsgID: Word;
end;
类的继承关系如下:
TObject->TPersistent->TComponent->TControl
TControl是所以可视化组件的父类,TControl提供了一个新的方法,WndProc:
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);//如果是鼠标移动的消息,则出现hint窗口
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); //将256虚拟键的状态拷贝到缓存中去
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;
但是只有TWinControl可以获得焦点:
procedure
TWinControl.WndProc(var Message: TMessage);
var
Form:
TCustomForm;
begin
case Message.Msg of
WM_SETFOCUS:
//设置控件的焦点
begin
Form := GetParentForm(Self);
if (Form <> nil) and
not Form.SetFocusedControl(Self) then Exit;
end;
WM_KILLFOCUS:
if
csFocusing in ControlState then
Exit;
//当鼠标有活动的时候发出该消息,如果鼠标没有被捕捉到,则消息发往鼠标下面的那个窗口,否则消息将发往捕捉到鼠标的那个窗口。
WM_NCHITTEST:
begin
inherited
WndProc(Message); //调用父类的处理方法
//如果窗体被挡住并且在指定的点没有控件,则返回结果为在client区。
if
(Message.Result = HTTRANSPARENT) and
(ControlAtPos(ScreenToClient(
SmallPointToPoint(TWMNCHitTest(Message).Pos)),
False) <> nil) then
Message.Result :=
HTCLIENT;
Exit;
end;
WM_MOUSEFIRST..WM_MOUSELAST:
if
IsControlMouseMsg(TWMMouse(Message)) then //鼠标消息是否直接发往组件的窗体子组件
begin
{
Check HandleAllocated because IsControlMouseMsg might have freed the
window
if user code executed something like Parent := nil. }
if (Message.Result = 0)
and HandleAllocated then
DefWindowProc(Handle, Message.Msg, Message.wParam,
Message.lParam);//调用默认的的消息处理方法对该消息进行默认处理。
Exit;
end;
WM_KEYFIRST..WM_KEYLAST:
if
Dragging then Exit;
WM_CANCELMODE:
if (GetCapture = Handle) and
(CaptureControl <> nil) and
(CaptureControl.Parent = Self)
then
CaptureControl.Perform(WM_CANCELMODE, 0, 0);
end;
inherited
WndProc(Message);
end;
TApplication在程序中发挥着重要的作用:
Application.Run;
procedure TApplication.Run;
begin
FRunning :=
True;
try
AddExitProc(DoneApplication);
if FMainForm <> nil
then
begin
case CmdShow of
SW_SHOWMINNOACTIVE: FMainForm.FWindowState
:= wsMinimized;
SW_SHOWMAXIMIZED: MainForm.WindowState :=
wsMaximized;
end;
if FShowMainForm then
if FMainForm.FWindowState =
wsMinimized then
Minimize else
FMainForm.Visible :=
True;
//一个消息循环直到Terminated为True时才退出。
repeat
try
HandleMessage;
except
HandleException(Self);
end;
until
Terminated;
end;
finally
FRunning := False;
end;
end;
procedure TApplication.HandleMessage;
var
Msg: TMsg;
begin
if not
ProcessMessage(Msg) then Idle(Msg);
end;
function TApplication.ProcessMessage(var Msg: TMsg):
Boolean;
var
Handled: Boolean;
begin
Result := False;
if
PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
//从现成的消息循环中取出消息并放入指定的消息结构中。
begin
Result := True;
if Msg.Message
<> WM_QUIT then //如果不是退出消息则进行相应的处理
begin
Handled := False;
if
Assigned(FOnMessage) then FOnMessage(Msg, Handled);
if not IsHintMsg(Msg) and
not Handled and not IsMDIMsg(Msg) and
not IsKeyMsg(Msg) and not IsDlgMsg(Msg)
then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end
else
FTerminate
:= True;
end;
end;
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号