Menu

Running_the_application's_message_loop

Application message handling

After your application is initialized, the application object's MessageLoop starts running. MessageLoop is responsible for processing incoming messages from Windows. There are two ways you can refine message processing in an ObjectWindows application:

Extra message processing

TApplication has member functions that provide the message-handling functionality for any ObjectWindows application. These functions are TApplication::MessageLoop(), TApplication::IdleAction(), TApplication::PreProcessMenu(), and TApplication::ProcessAppMsg().

Idle processing

Idle processing lets your application take advantage of the idle time when there are no messages waiting (including user input). If there are no waiting messages, MessageLoop calls IdleAction.

To perform idle processing, override IdleAction to perform the actual idle processing. Since idle processing takes place while the user isn't doing anything, it should last only a short while. If you need to do anything that takes longer than a few tenths of a second, you should split it into several processes.

IdleAction's parameter idleCount is a long specifying the number of times IdleAction was called between messages. You can use idleCount to choose between low-priority and high-priority idle processing. If idleCount reaches a high value, you know that a long period without user input has passed, so it's safe to perform low-priority idle processing.

Return true from IdleAction to call IdleAction back sooner.

You should always call the base class IdleAction function in addition to performing your own processing. If you are writing applications for Windows NT, you can also use multiple threads for background processing.


Related

Wiki: Application_and_module_objects

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.