Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Comments
Nelek 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

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!
....
 
Share this answer
 
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.
 
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