Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI GDI+ VC
Hi friends,
 
I have some critical work regarding to gdi. My requirement is I want to move a text from right to left continuously and show this as output as we see in the news. A small strip at the bottom of the screen continuously move from right to left. Can anybody tell me how I achieve this? My till now work is the text which I want to shows is ready and I am showing it properly but I am stuck for the movement of the text. Please tell me that how can I achieve this or suggest some sites for refer.
 
Thanks
Posted 25-Jun-13 23:24pm
Comments
Nelek at 26-Jun-13 4:39am
   
Do you need to move the text?
Or would it be enough moving the textbox? I mean, if you have your text being displayed in a control, you can move the control with SetWindowPos or similar functions, once is done you move it back to the original position, change the text inside and start over again
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You may achieve such kind of 'movement' by re-drawing continuosly (you might, for instance use a timer) at the same position, a different portion of your string.
Suppose you have the string "hello world!", you may go on as follows:
 
TimeString at X position
0hello world!
1ello world!
2llo world!
....
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I would place an owner draw static control in your dialog or your main window. In the DrawItem function I would draw the text with a calculated starting point.
 
At first the x-component of the starting point is the right border of your client area. As time progresses you would move the x-component more and more to the left so that the text appears and moves to the left. The x-component will eventually get negative and that means that the beginning of your text is no longer visible. I would stop that process when x has become smaller than the negative amount of the text extent (which you can calculate GetTextExtent of your drawing context. That means you stop displaying when the text has completely left the window. At this time you might want to start all over again and move x to the right border again.
 
For the calculation of the x-component I would use the current time in form GetTickCount. Store the initial tick count in your CStatic derived class. Then in DrawItem calculate the time difference and make the x-shift proportional to that time difference.
 
The final thing you need to do is generate a timer event which regularly invalidates you CStatic-derived control, so that DrawItem will be called.
 
This technique was geared towards MFC. But the same approach can be used in C++/CLI applications also.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 105
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 26 Jun 2013
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