Hang time ... delayed program response

Started by
8 comments, last by Mattman57 21 years, 10 months ago
Okay, so I just barely started coding a graphical little nothing using the windows API (eg: BitBlt and such), and I have the little app blit an image from memDC #1 to memDC #2, then I have a rect placed at the mouse''s position on memDC #2 as well. I blit memDC #2 to the window''s DC, but for some reason, all the interactions are delayed by about 4-5 seconds... for example, I move the mouse, and the rect doesn''t move the way the mouse moved for about 4-5 seconds... I have no clue why this would be. I''m not sure if it''s something that others have run into in the past or if it''s something code-specific. If it may be code-specific, I''ll gladly post the code I have, but I figured I''d wait to post the code unless you all think it''s code-specific. Thanks
Advertisement
After you blit the bitmap do you invalidate the rect so that WM_PAINT is called?


I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
dont forget get also to call UpdateWindow(), though NEVER EVER call those in WM_PAINT, or you will create some massive cpu usage problems.
Should UpdateWindow() be called in my main loop or what?

Yes, it should. Also you should probably be using the PeekMessage() function rather than GetMessage(). Just put the PeekMessage() inside your main loop.
If you wanted, instead of using a loop you could put a test in your callback processing function for the WM_MOUSEMOVE message, and just update the rect and call UpdateWindow() from there.

Twilight Dragon
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
I wouldn''t put it in your main loop but rather after you''ve updated the positions and are ready to draw.

ie. The mouse moves and now you''ve updated the rect''s values and you want the screen to change, that is when you call UpdateWindow().

As a person said, call the function when you are ready to draw the screen, not right after you have (do not use this function in the WM_PAINT message)


I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
Excuse me? Um, last I heard, checking the messages, updating the positions, and drawing are all part of the main loop!!! Here is what a main loop generally looks like for the wapi:

while(!exit)
{
GetInput();
UpdatePositions();
DrawEverything();
PeekMessage(parameters);
}

Invader X: Perhaps you're confusing the whole main loop with the updating functions, a part of the main loop. In other words, if Mattman57 didn't put his draw functions in the main loop, the drawing would only happen once at the start of the program. Savvy?

Twilight Dragon
www.freewebz.com/j-world

[edited by - TDragon on June 5, 2002 12:00:15 AM]
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
Update functions dont HAVE to be in the main loop. He described his app as a "graphical little nothing" and so I did not assume he has a loop as you have

while(!exit)
{
GetInput();
UpdatePositions();
DrawEverything();
PeekMessage(...);
}

Perhaps he is using WinProc as the loop, instead of PeekMessage() maybe he is using GetMessage()

while (GetMessage(...))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}


I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm
Okay, I guess I misunderstood you. If you read my earlier posting, you would have seen that I had said
"If you wanted, instead of using a loop you could put a test in your callback processing function for the WM_MOUSEMOVE message, and just update the rect and call UpdateWindow() from there."
And yes, that GetMessage() loop is the standard method for Win32 programs (it''s the one I use when I make a non-real-time program); since Mattman57 asked a question about the main loop, I guessed that he meant a main loop other than what you mentioned. My apologies.

Twilight Dragon
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
That''s ok. I noticed when you said you could use UpdateWindow() in WM_MOUSEMOVE and my post was just expanding on that.


I will not make a list of links... I will not make a list of links... I will not make a list of links...
Invader''s Realm

This topic is closed to new replies.

Advertisement