Click to See Complete Forum and Search --> : Problem with TextOut


-AdyOS-
November 18th, 2005, 03:28 AM
Hi all!!! Need your help people. I need to change font to pairs of words. I do it like this:

//in WndProc
....
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
RECT rt;
view.WriteFormattedText(hdc, rt);
EndPaint(hWnd, &ps);
ReleaseDC(hWnd, hdc);
}
break;
.....
//in function view.WriteFormattedText(hdc, rt)
while((nLine < m_stView.m_nMaxLinesOnPage/* + m_stView.m_nCurrTopLine*/)
&& (nLine + m_stView.m_nCurrTopLine < m_stView.m_nTotalLines))
{
strLine = m_vecLines[m_stView.m_nCurrTopLine + nLine];
// TextOut(hDC, 0, nLineHeight * nLine, strLine.c_str(), strLine.length());
nRet = PrintText(strLine, hDC, nLineHeight * nLine, nRet, bFlag);
nLine++;
}

//function PrintText(strLine, hDC, nLineHeight * nLine, nRet, bFlag)
int CMyView::PrintText(string strLine, HDC hDC, int nLine, int nLastCount, BOOL& bFlag)
{
int nBreaks = 0;//nLastCount;
int nPos = 0;
BOOL bSmall = bFlag;

string tmp, str;
char * chToken;

char chDel[] = " ";

if(strLine.empty())
return 0;

chToken = strtok((char *)strLine.c_str(), chDel);
if(strcmp(chToken, strLine.c_str()))
{
while(NULL != chToken)
{
nBreaks++;
str += chToken;
str += ' ';

if(nBreaks == 2)
{

HFONT hCurFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT);

if(hCurFont == stFont.m_hBigFont )
SelectFont(hDC, m_stFont.m_hSmallFont);
else
SelectFont(hDC, m_stFont.m_hBigFont);

TextOut(hDC, 0, nLine, str.c_str(), str.length());


nBreaks = 0;
str = "";
}
chToken = strtok(NULL, chDel);
}
}
else// (nBreaks >= 0 && nBreaks < 2)
{
HFONT hCurFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT);

if(hCurFont == stFont.m_hBigFont )
SelectFont(hDC, m_stFont.m_hSmallFont);
else
SelectFont(hDC, m_stFont.m_hBigFont);
TextOut(hDC, 0, nLine, strLine.c_str(), strLine.length());

}

return 0; // - all is OK
}


But font is not always change...It can be all line with small font or with big. In debug window I check word pairs to TextOut, but on device its became wrong font.

golanshahar
November 18th, 2005, 03:50 AM
one thing you may wanna try is intead of using GetCurrentObject(..) (that returns the current selected font) simply use ::CreateFont(..) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8fp0.asp) with all the params that you want...

Cheers

-AdyOS-
November 18th, 2005, 04:13 AM
No, problem isn't with GetCurrentObject(...). I check it, and fonts are already sucessfully created. Only TextOut is wrong.

golanshahar
November 18th, 2005, 04:29 AM
But font is not always change...It can be all line with small font or with big. In debug window I check word pairs to TextOut, but on device its became wrong font.

here you said that the font is all wrong...:confused:

why do you think ::TextOut(..) is not ok? if the text is drawn that means that ::TextOut(..) did the job. :confused:

Cheers