CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2003
    Location
    Pakistan
    Posts
    223

    news Ticker probelm

    Hi now a days i am developing a news ticker , just like one we could see on news channels at bottom a strip in which Text and logos scrolls from right to left.

    i have succeeded in scrolling the text , but i am feeling difficulty in scrolling logos or image alongwith text.

    so can anybody give some hint how to do it , or article abut such news ticker.

    even i dont mind to buy some news ticker component or stuff but i am not able to find one.
    Unmanaged in a .NET world

  2. #2
    Join Date
    Apr 2003
    Posts
    93
    Well, lets think about it.

    You might have a string that contains...

    Code:
    char *strTicker = "This is my ticker, here is an image!";
    And, according to that string, there is supposed to be an image at the end of it.
    Obviously there isnt, so when we scroll this is will just be a string of text, like it is with yours now i assume.

    To place the Image at the right place, you firstly need to find out where it needs to be!

    If your doing a predefined string, then it's not a problem, you could put '[image]' in your string so you could place it there.

    Code:
    char *strTicker = "This is my ticker, here is an image![image]";
    Like that!

    Then, every frame you need to check your string, and get it's X position, because it could be halfway off the screen, and if were still drawing onto the end of where the string USED to be, we'll just have a static image!!

    So we get the X position of the string, now we have to get the strings length in pixels...i know DirectX has a function for this in the API, i don't know what your using though...

    So now, we have the X position of the Ticker, and the String Pixel length.

    Code:
    int iXPos, iTickerStrLen;
    char *strTicker = "This is my ticker, here is an image![image]";
    
    //Here's the loop
    while ( looping )
    {
          //Get the X position of the string...probably held in a RECT or similar.
    
          //Get the length of the string in pixels, it'll be part of the FONT class you'll use probably.
          //Now we have the length of the string in pixels, held in iTickerStrLen
          //and we have the position of the scrolling text held in iXPos.
    
          //We now know that if we do a sum....
    
          int iImagePos = ( iXPos + iTickerStrLen );
    
          //We have the position of where the [image] should be.
          //Of course, this code only lets you add ONE image, and thats
          //at the end, so you'll need to add some string searching code in!!
          //But now we have the position....you can run a function that will
          //draw your image, at the end of the string, constantly.
          //hope this helps...
    
    
    }

    That should be enough to get you off your feet

    Have fun!!


    Dean.
    OutputDebugString(...); Is your friend!
    http://www.spikedsoftware.co.uk

  3. #3
    Join Date
    Apr 2003
    Posts
    93
    All this talk of News Tickers has spured me on to make my own one, hehe.

    I started one a while ago, but got bored of it.

    I think i'll start again, i'm sure i'll be able to help you more then

    Good luck!
    OutputDebugString(...); Is your friend!
    http://www.spikedsoftware.co.uk

  4. #4
    Join Date
    May 2003
    Location
    Pakistan
    Posts
    223
    Quote Originally Posted by japanfred
    Well, lets think about it.

    You might have a string that contains...

    Code:
    char *strTicker = "This is my ticker, here is an image!";
    And, according to that string, there is supposed to be an image at the end of it.
    Obviously there isnt, so when we scroll this is will just be a string of text, like it is with yours now i assume.

    To place the Image at the right place, you firstly need to find out where it needs to be!

    If your doing a predefined string, then it's not a problem, you could put '[image]' in your string so you could place it there.

    Code:
    char *strTicker = "This is my ticker, here is an image![image]";
    Like that!

    Then, every frame you need to check your string, and get it's X position, because it could be halfway off the screen, and if were still drawing onto the end of where the string USED to be, we'll just have a static image!!

    So we get the X position of the string, now we have to get the strings length in pixels...i know DirectX has a function for this in the API, i don't know what your using though...

    So now, we have the X position of the Ticker, and the String Pixel length.

    Code:
    int iXPos, iTickerStrLen;
    char *strTicker = "This is my ticker, here is an image![image]";
    
    //Here's the loop
    while ( looping )
    {
          //Get the X position of the string...probably held in a RECT or similar.
    
          //Get the length of the string in pixels, it'll be part of the FONT class you'll use probably.
          //Now we have the length of the string in pixels, held in iTickerStrLen
          //and we have the position of the scrolling text held in iXPos.
    
          //We now know that if we do a sum....
    
          int iImagePos = ( iXPos + iTickerStrLen );
    
          //We have the position of where the [image] should be.
          //Of course, this code only lets you add ONE image, and thats
          //at the end, so you'll need to add some string searching code in!!
          //But now we have the position....you can run a function that will
          //draw your image, at the end of the string, constantly.
          //hope this helps...
    
    
    }

    That should be enough to get you off your feet

    Have fun!!


    Dean.

    Thanx a lot , enough for getting started.
    Unmanaged in a .NET world

  5. #5
    Join Date
    May 2003
    Location
    Pakistan
    Posts
    223
    Quote Originally Posted by japanfred
    All this talk of News Tickers has spured me on to make my own one, hehe.

    I started one a while ago, but got bored of it.

    I think i'll start again, i'm sure i'll be able to help you more then

    Good luck!
    My pleasure.
    Unmanaged in a .NET world

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured