Click here to Skip to main content
15,902,845 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The windows forms application code automatically generated by Visual studio c++ looks very different from those for dialog or MFC applications.

How can I add message handling to Windows forms applications? I would like to start another thread, listen for message that the thread is finished, then do something. I'm not sure how to get started from the code like:

C#
Application::Run(gcnew Form1());


which does not tell me about the message handling mechanism.

What I have tried:

searched online for example code. MSDN documentation on windows forms points to .net framework. Don't know whether I need to jump into reading extensive information about.net framework for what I need to do.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Feb-16 21:28pm    
What do you mean by "message"? A regular Windows messages? They are already encapsulated into System::Windows::Forms; you don't need to use them directly. And how about reading original MSDN documentation? It looks like you are trying to get all by guess, using some Quick Help. Better don't waste your and our time; first learn essential background, then ask your questions.
—SA
Philippe Mori 13-Feb-16 22:07pm    
In .NET, you rarely need to directly use Windows messages or interact with the message loop. Common messages already have event handler for them. You just have to attach a function to the event handler for whatever event you want to respond.

Usually, you don't uses Windows message directly to communicate with a thread. In .NET, you have a background work, Thread class and async programming amoung other and thus, it is preferable to use them properly.

MFC is an old technology. .NET is far more easier to use. As such, for common things like multithreading or message handling, better to use what .NET offer and only rely on low-level stuff if you really need.

Message handling in .net is done primarily by registering a message function with the control. The mechanism used for that is called "delegates". In comparison with the old MFC message maps this is very elegant.

To get a start on this, just download one of the many examples of a small GUI program in C++/CLI or C# and you will quickly see how it is done.
 
Share this answer
 
There is no message that says "a thread is finished". The thread either dies quietly when its work is done or the thread is responsible for signalling other code that cares. There are quite a number of ways to do this, but listening to the message pump is not one of them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900