Archived

This topic is now archived and is closed to further replies.

JIMbond21

What's wrong with this?

Recommended Posts

I made this function to draw text a memory dc and then draw that memory dc to the window dc, but it shows nothing at all. I want to make this function work for future use in a class im making fo drawing bitmaps and text to a buffer and then to the window, any suggestions on how to fix this or do it differently but still having a memory dc of some kind. void drawtext( HDC hdc, RECT* prc ) { HFONT hf; HDC hdcMem = CreateCompatibleDC(hdc); FillRect(hdcMem, prc, (HBRUSH)GetStockObject(WHITE_BRUSH)); HDC hdc2; long lfHeight; hdc2 = GetDC(NULL); lfHeight = -MulDiv(20, GetDeviceCaps(hdc2, LOGPIXELSY), 72); ReleaseDC(NULL, hdc2); hf = CreateFont(lfHeight, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Times New Roman"); char szSize[] = "Hello all."; HFONT hfOld = (HFONT)SelectObject(hdcMem, hf); SetBkColor(hdcMem, RGB(255,255,255)); SetTextColor(hdcMem, RGB(255,0,0)); SetBkMode(hdcMem, TRANSPARENT); DrawText(hdcMem, szSize, -1, prc, DT_SINGLELINE); BitBlt(hdc, 0, 0, prc->right, prc->bottom, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hfOld); DeleteObject(hf); Help me. THX, JAP

Share this post


Link to post
Share on other sites
D''OH!
I hate debugin Win32 code.. it''s too fucking messy! :-(

But I can''t really find anything that are wrong when just looking at it.. Try to put some breakpoints to see if some values are fucked up... like that lfHeight variable (check that it''s not 0).

Also, make sure that the hdc thing is correct (if called from a paint function or something)..


----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. The ones that understand binary and the ones that does not"

Share this post


Link to post
Share on other sites