Scalabium Software |
|
| Knowledge for your independence'. | |
#135: How can I filter a mouse and keyboard? |
|
Every developer during programming solved such task: you have some longtime data processing when user must see a progress but can do nothing. By default (without any additional steps) during data processing your application will be frozen. The easiest way to solve it is to send Application.ProcessMessages from own loop but in this case the user could click some controls (by mouse or keyboard). The method below will show how you can disable any mouse/keyboard actions: you may assign a handler to Application.OnMessage: Application.OnMessage := yourOnMessageHandler where procedure TForm1.yourOnMessageHandler(var Msg: TMsg; var Handled: Boolean);
begin
case Msg.Message of
WM_KEYFIRST..WM_KEYLAST, WM_MOUSEFIRST, WM_MOUSELAST:
Handled := True
end;
end;
Very important: you must remove a handler when your data processing is completed (or in OnDestroy event of main form) A basic scheme of data processing: begin
Application.OnMessage := yourOnMessageHandler;
<your long calculation>
while <...> do
begin
<your calculations>
<update a progressbar/statistic>;
Application.ProcessMessages
end;
Application.OnMessage := nil;
end;
Of course, you can filter a mouse and/or keyboard by some own conditions - just expand a body of yourOnMessageHandler procedure...
|
|
Copyright© 1998-2025, Scalabium
Software. All rights reserved. |