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

How To Use ProcessMessages Method In Windows Applications

In this post, you’ll learn how to use the ProcessMessages method, What about if I have a 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?
By learning how to use ProcessMessage Method in Windows applications, it will help you to easily build C++ applications using the C++ IDE.

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.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?