C++Introduction to C++Language FeatureLearn C++

How To Use ProcessMessages Method In Windows Applications

How can I use ProcessMessages method? What about if I have loop and the app’s GUI becomes unresponsive at runtime while the loop is running? How can I receive clicks on the components when I have a loop? How can I receive user inputs during code with heavy iterations? Let’s answer these questions.

What is the ProcessMessages Method?

ProcessMessages Method (Vcl::Forms::TApplication::ProcessMessages) is a VCLmethod that Interrupts the execution of an application so that it can process the message queue. In other words ProcessMessages can be used to receive and process form and application events. This is very useful when you have heavy calculations since you can let the user perform processes on the screen.

Call ProcessMessages to permit the application to, as the name implies, process messages that are currently waiting in the message queue. ProcessMessages cycles the Windows message loop until it is empty and then returns control to the application. Note that neglecting message processing affects only the application calling ProcessMessages, not other applications. In lengthy operations, calling ProcessMessages periodically allows the application to respond to paint and other messages. ProcessMessages does not allow the application to go idle, whereas HandleMessage does.

What is the syntax of the ProcessMessages Method?

Here is the syntax of the ProcessMessages method,

What is a simple example of using the C++ ProcessMessages Method?

Here is the full example of using the C++ ProcessMessages Method

In these kind of heavy calculations maybe you can do hundred or thousand iterations before you check the queue with this method which may speedup your calculations. If you want to draw or print results in any step of a long-time iterations, you can use this ProcesMessages method to process all pending operations on the form’s visuals.

Another method to do heavy calculations is to perform calculations in a IdleLoop that means you can handle messages without calling ProcessMessages You can also use TTask and other multi-processing methods to reduce time and to make your application much more fluent.

Note that there are HandleMessage method that interrupts the execution of an application while Windows processes a message in the Windows message queue, and OnMessage event that occurs when the application receives a Windows message.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++ComponentsDatabaseIntroduction to C++Language FeatureLearn C++

Get To Know The Powerful C++ Data Bindings In Windows Apps

C++Introduction to C++Language FeatureLearn C++

How to Create a New Windows FMX Static Library In C++

C++C++11C++14C++17Introduction to C++Learn C++

How To Use C++ front() And back() Methods Of Vectors

C++Generic ProgrammingIntroduction to C++Language FeatureLearn C++

5 Things You Need To Know About Optimization In C++ Builder