-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.
//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.