I have a Windows Form app in C# and am trying to figure out where I would implement the CLI app equivalent of the primary while loop in main(). I am using Visual C#'s gui designer.
EDIT: Problem solved with an instance of Timer.
The message loop is an obligatory section of code in every program that uses a graphical user interface under Microsoft Windows. Windows programs that have a GUI are event-driven. Windows maintains an individual message queue for each thread that has created a window. Usually only the first thread creates windows.
Win32++ is a C++ library used to build windows applications. Win32++ is a free alternative to MFC. It has the added advantage of being able to run on a wide range of free compilers, including Visual Studio Community, Clang, and the MinGW compiler provided with CodeBlocks and Dev-C++.
But you can use C/C++ to access the Win32 API just as you do to access standard C/C++ library functions. If you are to learn it, the best way is to find a compiler with Win32 SDK libraries, then write your C/C++ code using the tools. If you like, Visual Studio (community version) is a good choice for learning.
It's inside the Application.Run
method. You shouldn't call GetMessage
API function directly:
// MyForm is derived from `System.Windows.Forms.Form` class
Application.Run(new MyForm());
It's entered from Application.Run(Form)
. You don't enter any logic in that loop. If you need to respond to input, add event handlers to the particular events to the controls on your form. If you need to run logic periodically, use one of the Timer
classes.
The primary outcome of logic in the message pump in C++ is excess/unnecessary usage of the battery on laptops. You should definitely start rethinking the actual code requirements for meeting your target goal, and they shouldn't include constantly running logic in a spin loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With