HandleMessage:

    HandleMessage中断应用程序的执行,以便Windows可以在将控制权返回给应用程序之前处理来自Windows消息队列的单个消息。

如果消息队列为空,则HandleMessage生成OnIdle事件并启动更新应用程序中的操作的过程。

    注意:如果应用程序空闲,HandleMessage可能需要很长时间才能返回。

    因此,在等待基于消息的事务时,不要在处理优先级操作时调用HandleMessage。 相反,在处理的不仅仅是消息时调用ProcessMessages。

ProcessMessage:

         ProcessMessages不允许应用程序空闲,而HandleMessage则允许。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure MyIdleHandler(Sender: TObject; var Done: Boolean);
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} var
{ Global variables to show the order of events }
XPos, YPos, Delta: integer; procedure StatusMsg(
MyForm : TForm1; Canvas : TCanvas; Message : string; Bkg : Boolean);
begin
if not bkg then
Canvas.Font.Style := [fsBold]; {Foreground messages are in bold type. }
Canvas.TextOut(XPos, YPos, Message);
if not bkg then
Canvas.Font.Style := [];
{ Change Xpos and YPos to prepare for the next message. }
Ypos := Ypos + Delta;
if YPos >= MyForm.ClientHeight - 10 then
begin
YPos := 10;
Xpos := Xpos + 180;
end;
if (Xpos >= MyForm.ClientWidth - 100) then
begin
if (Canvas.Font.Color = clRed) then
Canvas.Font.Color := clBlack
else
Canvas.Font.Color := clRed;
Xpos := 10;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := 'Do not yield';
Button2.Caption := 'Handle Message';
Application.OnIdle:= MyIdleHandler;
XPos := 10;
YPos := 10;
Delta := Abs(Canvas.Font.Height) + 1;
end; procedure TForm1.Button1Click(Sender: TObject);
var
I, J, X, Y: Word;
begin
StatusMsg(
Form1, Canvas, 'The synchronous handler is starting', False);
I := 0;
J := 0;
while I < 10 do
begin
Randomize;
while J < 10 do
begin
Y := Random(J);
Inc(J);
end;
X := Random(I);
Inc(I);
end;
StatusMsg(
Form1, Canvas, 'The synchronous handler is done', False); end; procedure TForm1.Button2Click(Sender: TObject);
var
I, J, X, Y: Word;
begin
//同时执行onIdle事件和当前任务
StatusMsg(
Form1, Canvas, 'The asynchronous handler is starting', False);
I := 0;
J := 0;
while I < 100 do
begin
Randomize;
while J < 10 do
begin
Y := Random(J);
Inc(J);
end;
X := Random(I);
Inc(I);
{ yield to OnIdle or other messages }
// PostMessage(Handle,WM_PAINT,0,0); 假如消息队列不是空,则不会生成onIdle事件
Application.HandleMessage;
end;
StatusMsg(
Form1, Canvas, 'The asynchronous handler is done', False); end; procedure TForm1.FormShow(Sender: TObject);
begin end; { TForm1 } procedure TForm1.MyIdleHandler(Sender: TObject; var Done: Boolean);
begin
StatusMsg(
Form1, Canvas, 'This represents a background process.', True);
end; end.

Application.HandleMessage与Application.ProcessMessage的更多相关文章

  1. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  2. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  3. application/json和application/x-www-form-urlencoded使用选择

    一.参考资料 选application/x-www-form-urlencoded还是application/json? @RequestBody应用 二.理解 1.@RequestBody的作用 注 ...

  4. SpringBoot application.properties (application.yml)优先级从高到低

    SpringBoot application.properties(application.yml) 优先级从高到低 SpringBoot配置文件优先级从高到低 =================== ...

  5. jdb--gdb---java 远程调试(java application与web application)

    命令比较     gdb              jdb     bt             where     del           clear     stop         brea ...

  6. Ajax的text/plain、application/x-www-form-urlencoded和application/json

    Ajax的text/plain.application/x-www-form-urlencoded和application/json HTTP请求中,如果是get请求,那么表单参数以name=valu ...

  7. application/json和application/x-www-form-urlencoded区别

    application/json和application/x-www-form-urlencoded都是表单数据发送时的编码类型. EncType: enctype 属性规定在发送到服务器之前应该如何 ...

  8. Application Architecture Determines Application Performance

     Application Architecture Determines Application Performance Randy Stafford AppliCATion ARCHiTECTuR ...

  9. 应用程序池和应用程序域的区别(Difference between application pool and application domain)

    来自StackOverFlow:  http://stackoverflow.com/questions/8486335/difference-between-an-application-domai ...

  10. spring学习十二 application/x-www-form-urlencoded还是application/json

    application/x-www-form-urlencoded还是application/json get. POST 用哪种格式? 后台如何得到这些值? 如何用ajax  或者是 postman ...

随机推荐

  1. php 常用助手函数

    1 <?php 2 3 if (!function_exists('bcSum')) { 4 function bcSum($scale, ...$args): string 5 { 6 $re ...

  2. OS-lab5

    OS-lab5 磁盘管理 完成文件系统的第一步就是要能够处理磁盘等外设的信息. lib/syscall_all.c 处理磁盘的信息,最基本的就是对磁盘进行读写操作. sys_write_dev函数用于 ...

  3. Pytorch实战学习(三):多维输入

    <PyTorch深度学习实践>完结合集_哔哩哔哩_bilibili Multiple Dimension Imput 1.糖尿病预测案例 2.输入8个特征变量 3.Mini-batch N ...

  4. 微信小程序图片和签名

    图片上传功能 chooseImage(e) { wx.chooseImage({ sizeType: ['original', 'compressed'], //可选择原图或压缩后的图片 source ...

  5. 用 go 实现多线程下载器

    本篇文章我们用Go实现一个简单的多线程下载器. 1.多线程下载原理 通过判断下载文件链接返回头信息中的 Accept-Ranges 字段,如果为 bytes 则表示支持断点续传. 然后在请求头中设置 ...

  6. MyBatis_07(动态SQL)

    动态SQL: Mybatis框架的动态SQL技术是一种根据特定条件动态拼装SQL语句的功能, 它存在的意义是:"为了解决拼接SQL语句字符串时的痛点问题". 一.If if标签可通 ...

  7. JAVA常用类(一)Syatem类

    System类:系统类,主要用于获取系统的属性和方法,没有构造方法,其属性都是静态属性,方法都是静态方法 .System类是jdk提供的一个工具类,有final修饰,不可继承,由名字可以看出来,其中的 ...

  8. C++ 用同一个raw pointer传入shared_ptr构造函数生成两个智能指针有什么问题?

    Effective Modern C++ Item 19: use std::shared_ptr for shared-ownership resource Now, the constructor ...

  9. Java常用数据结构

    1.数组 数组(Array) 是一种很常见的数据结构.它由相同类型的元素(element)组成,并且是使用一块连续的内存来存储. 我们直接可以利用元素的索引(index)可以计算出该元素对应的存储地址 ...

  10. [*]Quadratic Residual Networks: A New Class of Neural Networks for Solving Forward and Inverse Problems in Physics Involving PDEs

    Accepted by SIAM International Conference on Data Mining (SDM21) 本文提出了二次残差网络,通过在应用激活函数之前,添加二次残差项到输入的 ...