Jump to content
  • Advertisement

Archived

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

JIMbond21

What's wrong with this?

This topic is 5540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
you first need to create a bitmap (with CreateCompatibleBitmap) and select it into the memory dc before you can draw to the dc


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!