Click here to Skip to main content
Sign Up to vote bad
good
See more: C++
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
mtitlebar->SetPositionX(0);
mtitlebar->SetPositionY(500);
the widget postion move in y direction but its speed is very fast. please help.
 
Thanks & Regards
Posted 15-Oct-12 20:24pm
Edited 16-Oct-12 2:51am


4 solutions

Add some Sleep()[^] calls.
  Permalink  
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:
 
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);
}
  Permalink  
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!
  Permalink  
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".
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,889
1 Prasad_Kulkarni 3,671
2 OriginalGriff 3,359
3 _Amy 3,312
4 CPallini 2,925


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid