Drawing text issue
-
Hi all. I got a huge problem while trying to draw a text with MFC. So, i got my custom class which extends CStatic. In OnPaint:
CPaintDC dc(this);
Gdiplus::Graphics * gfx = Gdiplus::Graphics::FromHDC(dc.GetSafeHdc());// then there a couple of things ... and then i am drawing a text like that (in another function which takes as IN parameter Gdiplus::Graphics, created in OnPaint):
CDC * pDC = CDC::FromHandle(gfx->GetHDC());
pDC->TextOut(0, 0, "my text");
gfx->ReleaseHDC(pDC->GetSafeHdc());Simple. But every time OnPaint gets called - new text is drawn over old one, so it is getting bolder and bolder. And, it is not like the old one never erased, but it is erased only when there are about 5 same texts drawn over each one. Another thing, i've tried not to use Gdiplus at all - do everything only with CDC thing - same effect. Have used DrawText - same effect. Only with Gdiplus DrawString text is drawn correctly. But i need to draw it with Gdi32. Thanks.
011011010110000101100011011010000110100101101110 0110010101110011
-
Hi all. I got a huge problem while trying to draw a text with MFC. So, i got my custom class which extends CStatic. In OnPaint:
CPaintDC dc(this);
Gdiplus::Graphics * gfx = Gdiplus::Graphics::FromHDC(dc.GetSafeHdc());// then there a couple of things ... and then i am drawing a text like that (in another function which takes as IN parameter Gdiplus::Graphics, created in OnPaint):
CDC * pDC = CDC::FromHandle(gfx->GetHDC());
pDC->TextOut(0, 0, "my text");
gfx->ReleaseHDC(pDC->GetSafeHdc());Simple. But every time OnPaint gets called - new text is drawn over old one, so it is getting bolder and bolder. And, it is not like the old one never erased, but it is erased only when there are about 5 same texts drawn over each one. Another thing, i've tried not to use Gdiplus at all - do everything only with CDC thing - same effect. Have used DrawText - same effect. Only with Gdiplus DrawString text is drawn correctly. But i need to draw it with Gdi32. Thanks.
011011010110000101100011011010000110100101101110 0110010101110011
You can try using Graphics object gfx only for drawing. No need to mix GDI and GDI+. Instead of TextOut(), use Graphics::DrawString()
-
Hi all. I got a huge problem while trying to draw a text with MFC. So, i got my custom class which extends CStatic. In OnPaint:
CPaintDC dc(this);
Gdiplus::Graphics * gfx = Gdiplus::Graphics::FromHDC(dc.GetSafeHdc());// then there a couple of things ... and then i am drawing a text like that (in another function which takes as IN parameter Gdiplus::Graphics, created in OnPaint):
CDC * pDC = CDC::FromHandle(gfx->GetHDC());
pDC->TextOut(0, 0, "my text");
gfx->ReleaseHDC(pDC->GetSafeHdc());Simple. But every time OnPaint gets called - new text is drawn over old one, so it is getting bolder and bolder. And, it is not like the old one never erased, but it is erased only when there are about 5 same texts drawn over each one. Another thing, i've tried not to use Gdiplus at all - do everything only with CDC thing - same effect. Have used DrawText - same effect. Only with Gdiplus DrawString text is drawn correctly. But i need to draw it with Gdi32. Thanks.
011011010110000101100011011010000110100101101110 0110010101110011
-
You can try using Graphics object gfx only for drawing. No need to mix GDI and GDI+. Instead of TextOut(), use Graphics::DrawString()
The problem is i cannot use Gdiplus for drawing a string because my requirement is to draw the string with exact same font which windows OS uses. Gdiplus produce different font even if you do:
HFONT hFOnt = ::GetStockObject(DEFAULT_GUI_FONT);
and then create Gdiplus::Font from hFont. In theory you should have default font and maybe you do have, but DrawString draws text with a different font, not system default.
011011010110000101100011011010000110100101101110 0110010101110011
-
Use TextOut() or DrawText() function of CDC. Clear the earlier text with null string and then use drawing function.
Ahh, it was all about this MFC thing - sometimes you have to override some methods you got no idea about to make your control draw itself correctly. In this case it was:
OnWindowPosChanged
And just do nothing inside - static draws perfectly.
011011010110000101100011011010000110100101101110 0110010101110011