Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Windows GUI Main Loop In C#... where is it?

Tags:

c#

.net

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.

like image 805
Orm Avatar asked Sep 01 '09 21:09

Orm


People also ask

What is message loop in windows programming?

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.

What is Win32 C++?

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++.

How do I learn to Win32?

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.


2 Answers

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()); 
like image 133
mmx Avatar answered Oct 25 '22 15:10

mmx


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.

like image 25
Sam Harwell Avatar answered Oct 25 '22 15:10

Sam Harwell