How to make a text scrooling - Text ticker
- 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
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)- Marked As Answer byZHE ZHAOMSFT, ModeratorThursday, September 17, 2009 1:55 AM
- Proposed As Answer byAfriza N. Arief Tuesday, September 15, 2009 7:02 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)- Marked As Answer byZHE ZHAOMSFT, ModeratorThursday, September 17, 2009 1:55 AM
- Proposed As Answer byAfriza N. Arief Tuesday, September 15, 2009 7:02 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 case WM_CREATE:
SetTimer(hWnd,ID_TICK1,150,NULL);
break;
casebreak;
caseWM_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;
}
- You can find an implementation of a text ticker here .
João Paulo Figueira (Device Application Development MVP)


