Click here to Skip to main content
12,943,701 members (58,493 online)
Rate this:
Please Sign up or sign in to vote.
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

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

Thanks & Regards
Posted 15-Oct-12 20:24pm
Updated 16-Oct-12 2:51am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Add some Sleep()[^] calls.
Rate this: bad
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++ ) {
Rate this: bad
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:[^].

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!
Rate this: bad
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".

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,643
CHill60 2,970
Maciej Los 2,348
Jochen Arndt 1,900
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2017
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