Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Tn11111.1K
Edited 16-Oct-12 2:51am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Add some Sleep()[^] calls.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
0 Sergey Alexandrovich Kryukov 494
1 CHill60 405
2 OriginalGriff 345
3 PIEBALDconsult 285
4 BillWoodruff 213


Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100