none
How to make a text scrooling - Text ticker

    Question

  • Hi All,
    I have  written this piece of code.

    HWND hTaskBar = FindWindow(TEXT(

    "HHTaskBar"),NULL);

    RECT rect;

     

     

    //Retrieve the client area coordinates...

    GetWindowRect(hWnd,&rect);

     

    HDC hWndDC = GetWindowDC(hWnd);

     

    HDC hMemDc = CreateCompatibleDC(hWndDC);

    HBITMAP hBitMap = CreateCompatibleBitmap(hWndDC,rect.right,rect.bottom - rect.top);

     

    HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDc,hBitMap);

    PatBlt(hMemDc,rect.left,rect.top,rect.right,rect.bottom,WHITENESS);

     

    DrawText(hMemDc,TEXT(

    "Phone Incoming Call"),19,&rect,DT_RIGHT|DT_SINGLELINE);

     

    BitBlt(hWndDC,rect.left,rect.top,rect.right,rect.bottom,hMemDc,0,0,SRCCOPY);

     

     

     

    DeleteObject(SelectObject(hMemDc,hOldBitmap));

    DeleteDC(hMemDc);

    ReleaseDC(hWnd,hWndDC);

    The above code will display a bitmap on the title bar of the homescreen with the text "Phone Incoming Call"
    How do i make it scrolling from right to left like a text ticker...Give me any code ...


    Thanks,
    Chakri

    Friday, September 11, 2009 4:15 AM

Answers

  • To create a scrolling "text ticker" you must set up a timer that will fire your paint routine. Every time you paint, the code must shift the text RECT left coordinate by subtracting a fixed value (say 4). The code must also consider the full string width in pixels (you can use DT_CALCRECT on the DrawText call) so that it paints a second string to the right whenever the first starts displaying its right edge, so you get the following effect:

    Incoming phone call...   Incom ing phone call...

    Bold is visible.

    João Paulo Figueira (Device Application Development MVP)
    • Proposed as answer by Afriza N. Arief Tuesday, September 15, 2009 7:02 AM
    • Marked as answer by ZHE ZHAO Thursday, September 17, 2009 1:55 AM
    Friday, September 11, 2009 8:51 AM

All replies

  • To create a scrolling "text ticker" you must set up a timer that will fire your paint routine. Every time you paint, the code must shift the text RECT left coordinate by subtracting a fixed value (say 4). The code must also consider the full string width in pixels (you can use DT_CALCRECT on the DrawText call) so that it paints a second string to the right whenever the first starts displaying its right edge, so you get the following effect:

    Incoming phone call...   Incom ing phone call...

    Bold is visible.

    João Paulo Figueira (Device Application Development MVP)
    • Proposed as answer by Afriza N. Arief Tuesday, September 15, 2009 7:02 AM
    • Marked as answer by ZHE ZHAO Thursday, September 17, 2009 1:55 AM
    Friday, September 11, 2009 8:51 AM
  • Hello João Paulo Figueira ,

    I am begineer to windows programming. I am working on text ticker application on win CE platform. Can you post some sample code for scrolling text like a ticker without flickering. Thank you.

    Regards
    Kalyani
    Thursday, October 22, 2009 9:20 AM
  •  

    case WM_CREATE:

    SetTimer(hWnd,ID_TICK1,150,NULL);

     

    break;

    case

    break;

    case

     

    WM_PAINT:

    {

    hdc = BeginPaint(hWnd, &ps);

     

    // TODO: Add any drawing code here...

     

    //Move the window to the upper of the client area..

     

    HWND hTaskBar = FindWindow(TEXT(

    "HHTaskBar"),NULL);

    RECT rect;

     

     

    //Retrieve the client area coordinates...

    GetWindowRect(hWnd,&rect);

     

    HDC hWndDC = GetWindowDC(hWnd);

     

    HDC hMemDc = CreateCompatibleDC(hWndDC);

    HBITMAP hBitMap = CreateCompatibleBitmap(hWndDC,rect.right,rect.bottom - rect.top);

     

    HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDc,hBitMap);

    PatBlt(hMemDc,rect.left,rect.top,rect.right,rect.bottom,WHITENESS);

    SetBkMode( hMemDc , TRANSPARENT );

     

     

    rect.left = GetTickerPosition(hdc);

     

    DrawText(hMemDc,szText,-1,&rect,DT_LEFT);

     

    BitBlt(hWndDC,rect.left,rect.top,rect.right,rect.bottom,hMemDc,0,0,SRCCOPY);

     

     

     

    DeleteObject(SelectObject(hMemDc,hOldBitmap));

    DeleteDC(hMemDc);

    ReleaseDC(hWnd,hWndDC);

     

    EndPaint(hWnd, &ps);

    }

     

    break;

     

    case WM_TIMER:

    {

     

    if(wParam == ID_TICK1)

    {

    RECT rect;

     

    //Retrieve the client area coordinates...

    GetClientRect(hWnd,&rect);

    InvalidateRect(hWnd,&rect,TRUE);

    }

    }

     

    break;


    int

     

    GetTickerPosition(HDC hdc)

    {

    iPos = iPos - 3;

     

    SIZE size;

    GetTextExtentExPoint(hdc,szText,_tcslen(szText),NULL,NULL,NULL,&size);

     

    if(iPos < -62)

    iPos = GetSystemMetrics(SM_CXSCREEN) - size.cx;

     

    return iPos;

     

    }

    Friday, October 23, 2009 7:01 AM
  • You can find an implementation of a text ticker here .
    João Paulo Figueira (Device Application Development MVP)
    Monday, October 26, 2009 10:59 PM
  • Hi
    You can get the code for scrollig the text here

    http://youngindia99.com/stock_ticker_PocketPC.aspx.


    Hope that would be helpful to you.
    Wednesday, March 10, 2010 5:40 AM