Jump to content
  • Advertisement
Sign in to follow this  
dman1027

how does the C# message/App loop compare to c++ win32 message loop

This topic is 5133 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

could someone explain how the c# application.run() message loop compares with the c++ WinMain / WinProc message loop style? with c# it seems like i have to deal with a lot less setup code..but will the message loop use PeekMessage like a good c++ WinMain / WinProc message loop? is my control over messages limited in c#? Does the application loop pass the necessary messages to my code and handle the extras? how are the messages sent in c#? do i have access to them? or would i just create code for events tha are triggered through the message loop?

Share this post


Link to post
Share on other sites
Advertisement
Windows Forms essentially just wraps the regular Windows message pump, dispatching the various messages as events to your controls as needed. IOW, when one of your controls get a WM_PAINT, the Paint event is raised.

There is a slight overhead here, since the event dispatch code has to create a PaintEventArgs object. Fortunately, small, short-lived objects are *extremely* cheap in the .NET runtime.

If you want more control over the Windows message pump, you can override the WndProc method in your control class.

Share this post


Link to post
Share on other sites
ok...so:

what makes one of my controls "get a WM_PAINT message" aside from resizing or minimizing...

if i had a d3ddevice object, or d3dhost control... or really any control...how often does a WM_PAINT message occur? or must i force those messages? or i 'can' force those messages, but don't have to?

Share this post


Link to post
Share on other sites
Quote:
Original post by dman1027
what makes one of my controls "get a WM_PAINT message" aside from resizing or minimizing...

If it's uncovered by a window previously being on top of it(this makes debugging Paint event handlers a regular barrel of laughs).

Quote:

if i had a d3ddevice object, or d3dhost control... or really any control...how often does a WM_PAINT message occur?

Only in the circumstances mentioned.
Quote:

or must i force those messages? or i 'can' force those messages, but don't have to?

You can force them by calling Invalidate() on your control. This will eventually end up calling your Paint(or the protected OnPaint method, which is preferred if you're handling an event for a control you've subclassed).

A Managed DX book by Tom Miller had a render loop which looked like this:
[source lang="c#">
protected override void OnPaint( PaintEventArgs args )
{
// rendering code
this.Invalidate();
}
[/quote]

Share this post


Link to post
Share on other sites
ahhh, so does this add up....

i have frames that need to be rendered, i perform the necessary work and call invalidate (or similar call to raise OnPaint event), it paints my frame, then the message loop starts to gather input and /or other AI related info, after which i use the data to render the next frame and then at the end of my work i end with a call to raise the OnPaint event??

BTW, thanks soo much Arild for all your help

Share this post


Link to post
Share on other sites
The framework in the latest release of the DX SDK uses the Win32 API to setup a message loop as you would in C++.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!