Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am working a c++ project,i have a code for set the position of widget in y direction my code is compiling and run also,and the position change in y direction. My problem is that its speed is very fast,my requirement is move slow the widget in y direction. Please help me.

my code is
C++
mtitlebar->SetPositionX(0);
mtitlebar->SetPositionY(500);

the widget postion move in y direction but its speed is very fast. please help.

Thanks & Regards
Posted
Updated 16-Oct-12 2:51am
v2

Add some Sleep()[^] calls.
 
Share this answer
 
Well, that widget may not transferred as you would think. It may simply redrawn in the new position. To make an object looks like it is moving, you need to make a loop that looks like something like this:

C++
movement_speed = 10; // in milliseconds
old_y_position = 0;
new_y_position = 200;

for( ; old_y_position <= new_y_position ; old_y_position++ ) {
    Sleep(movement_speed);
    mtitlebar->SetPositionY(old_y_position);
}
 
Share this answer
 
v3
For a correct single threaded solution you should use SetTimer()[^], KillTimer()[^], and WM_TIMER[^]. Here is an example on how to do that: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644901%28v=vs.85%29.aspx#creating_timer[^].

About WM_TIMER in a few words: You set up a timer for your window and then you will receive WM_TIMER messages periodially so you can update your animation lets say "10" or whatever times in a second without freezing your gui. Note that you shouldn't expect better then 10ms granularity from WM_TIMER (at most 100 ticks a second) but this is true for a lot of other windows functions too (like the famouse GetTickCount()) and 10ms (and even less) should be quite enough for a smooth animation.

EDIT: Don't use blocking calls like Sleep() on your gui thread because that makes your whole gui unresponsive!
 
Share this answer
 
v2
You need to create a new thread to change the y direction. Call Sleep() in main thread is not effective.
I want to give you an eg.. But I do not know the type of the "mtitlebar".
 
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