在Delphi中,大多数情况下Windows的消息被封装在VCL的事件中,我们只需处理相应的VCL事件就可以了,但如果我们需要编写自己的控件、截获或过滤消息就必须深入研究Win32的消息处理机制。前面我们提到的消息都是标准的Windows消息(WM_X),除此之外还有VCL内部消息、通知消息和用户自定义消息。用户也可以自己定义消息、给自己发送消息和编写消息处理过程。VCL消息处理机制。这样在Windows本身对消息处理之前,就会响应OnMessage事件的处理过程,它优于任何消息处理,而且只接收登记的消息,即前面所述的由PostMessage发送的消息。
永远记住,无论你是用 SDK 还是借用 VCL 来创建窗口,都要遵循 Windows 的游戏规则,即先注册窗口类,然后再创建窗口实例,在消息循环中写实现代码。但 CreateHandle 只是个包装函数,它首先调用 TWinControl.CreateWnd 来创建窗口,CreateWnd 是一个重要的过程,它先调用 TWinControl.CreateParams 设置创建窗口的参数,通过这些参数调用 RegisterClass API 注册窗口类,CreateWnd 然后调用 TWinControl.CreateWindowHandle,CreateWindowHandle 才是真正调用 CreateWindowEx API 创建窗口实例的函数。
PostMessage不等待,直接把消息发出去 SendMessage发送并等待对方处理消息 TranslateMessage把虚拟艰消息翻译成字符消息 DispatchMessage派发消息 Tmessage---异步方式发送消息,不判断消息是否执行或被丢弃 Sendmessage---同步方式发送消息,等待消息被消息接收端接受后返回。
永远记住,无论你是用 SDK 还是借用 VCL 来创建窗口,都要遵循 Windows 的游戏规则,即先注册窗口类,然后再创建窗口实例,在消息循环中写实现代码。但 CreateHandle 只是个包装函数,它首先调用 TWinControl.CreateWnd 来创建窗口,CreateWnd 是一个重要的过程,它先调用 TWinControl.CreateParams 设置创建窗口的参数,通过这些参数调用 RegisterClass API 注册窗口类,CreateWnd 然后调用 TWinControl.CreateWindowHandle,CreateWindowHandle 才是真正调用 CreateWindowEx API 创建窗口实例的函数。
PostMessage不等待,直接把消息发出去 SendMessage发送并等待对方处理消息 TranslateMessage把虚拟艰消息翻译成字符消息 DispatchMessage派发消息 Tmessage---异步方式发送消息,不判断消息是否执行或被丢弃 Sendmessage---同步方式发送消息,等待消息被消息接收端接受后返回。