GetMessage函数怎么用?最好有例子。
比如我现在有一个很长的循环
repeat
//这里执行一些程序
inc(i);
until i<10000;
如果程序执行到这里,就会在这里一直循环,如果执行程序较慢,
则可能导致系统假死状态,我想在repeat...until里面用
GetMessage来维持系统消息,请问应该怎么写?
你灭有必要使用这个API。
VCL已经帮你封装好了消息机制,你最好不要使用这些。以免破坏掉VCL的消息机制。
使用Application.ProcessMessage来代替
repeat
if PeekMessage(Msg,0,0,0,PM_REMOVE) then
begin
if (Msg.message = CM_MSG_CLOSE) then
Break
else begin
Handled := False;
if Assigned(Application.OnMessage) then
Application.OnMessage(Msg,Handled);
TranslateMessage(Msg);
DispatchMessage(Msg);
end
////////这里执行一些程序
end
else
WaitMessage;
inc(i);
until i<10000;
//修改测试一下就能用了