Hi,
I'm working on a MFC application with a CScrollView derived view class. Everything is working fine, except that when I use double buffering, the text comes out "blurry". I can't quite explain how it looks, but without double buffering, the text comes out as expected, but using double buffering, it kind of seems like everything is drawn twice, a pixel apart.... (I know it's not much of an explanation, but it's the best I got )
Any ideas's on why this is happening? It's not happening with any other drawing that I'm doing...
Another thing I need some help on is the print preview:
The regular print seems to be working fine, but in the print preview, everything is scaled down, and is displayed basically without margins. This probably has a easy solution, but anyways....
Thanks!
Edit: Forgot that some migth enjoy a bit of source code to go along with my first problem:
<br />
void CITPAXpertView::OnDraw(CDC* pDC)<br />
{<br />
CITPAXpertDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
if (!pDoc)<br />
return;<br />
<br />
int nWidth = GetDocument()->GetDocSize().cx;<br />
int nHeight = GetDocument()->GetDocSize().cy;<br />
Graphics graphics(pDC->m_hDC);<br />
<br />
#ifdef _DEBUG<br />
#undef new<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#define new DEBUG_NEW<br />
#else<br />
Bitmap* bmp = new Bitmap(nWidth,nHeight);<br />
#endif<br />
<br />
Graphics* graph = Graphics::FromImage(bmp);<br />
<br />
CRect area;<br />
area.SetRect( 0, 0, 100, 100); TextPrint(&graphics, 10, 0, area, "Hello!", 1);
area.SetRect( 100, 0, 200, 100); TextPrint(graph, 10, 0, area, "Hello!", 1);
<br />
graphics.DrawImage( bmp, 0, 0, nWidth, nHeight);<br />
delete graph;<br />
delete bmp;<br />
}<br />
The TextPrint is as follows:
<br />
void CITPAXpertView::TextPrint(Graphics* pdc, int height, REAL rotation, CRect area, CString text, int alignment, Color fargen)<br />
{<br />
FontFamily fontFamily(L"Arial");<br />
Font font(&fontFamily, (REAL)height, FontStyleRegular, UnitPixel);<br />
RectF areal( (REAL)area.left, (REAL)area.top, (REAL)(area.right - area.left), (REAL)(area.bottom - area.top));<br />
StringFormat stringFormat;<br />
<br />
SolidBrush solidBrush(fargen);<br />
<br />
if (alignment == 0) { stringFormat.SetAlignment(StringAlignmentNear); }<br />
else if (alignment == 1) { stringFormat.SetAlignment(StringAlignmentCenter); }<br />
else { stringFormat.SetAlignment(StringAlignmentFar); }<br />
<br />
stringFormat.SetLineAlignment(StringAlignmentCenter);<br />
<br />
WCHAR* tekst = new WCHAR[text.GetLength()+1];<br />
mbstowcs(tekst, text, text.GetLength()+1);<br />
<br />
if( rotation != 0 ) {<br />
pdc->TranslateTransform(-areal.X-areal.Width/2, -areal.Y-areal.Height/2, MatrixOrderPrepend);<br />
pdc->RotateTransform(-rotation, MatrixOrderAppend);<br />
pdc->TranslateTransform(areal.X+areal.Width/2, areal.Y+areal.Height/2, MatrixOrderAppend);<br />
pdc->DrawString(tekst, -1, &font, areal, &stringFormat, &solidBrush);<br />
pdc->ResetTransform();<br />
}<br />
else {<br />
pdc->DrawString(tekst, -1, &font, areal, &stringFormat, &solidBrush);<br />
}<br />
<br />
delete tekst;<br />
}<br />
I hope this helps, and maybe, just maybe, someone can help me out...
|