Jump to content
  • Advertisement
Sign in to follow this  
Ixiodor

Draw on HBITMAP

This topic is 2573 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

Hi all guys,
i have this problem,i wanna create a function [ void DrawText(HBITMAP * Source,LPCSTR inText) ] that simply write a text on this HBITMAP...

And i am unable to create!
This is what i have tryed:


RECT rect = { 0,0,0,0};
HFONT NewFont = CreateFont( 25, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, 0, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial" );
HDC TmpDC = CreateCompatibleDC(NULL);
HBITMAP OldBmp = SelectObject(TmpDC , Source);
HFONT OldFont = SelectObject(TmpDC, NewFont);

DrawText(hDC, "Test", 4, &rect, DT_LEFT | DT_WORDBREAK);

SelectObject(TmpDC,OldBmp);
SelectObject(TmpDC,OldFont);

*Source= OldBmp; //??
return;


How to do this correctly?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I'd normally create a DC like this:


HDC screenDc=GetDC(mainWindowHw); // or GetDC(GetDesktopWindow()) if no handy HWND available


then create the bitmap and local DC like this:


HBITMAP bmp=CreateCompatibleBitmap(screenDc,width,height);
HDC dc=CreateCompatibleDC(screenDC);


After that, your code looks good to me. Select bmp into dc and use GDI calls to draw to it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!