Sign in to follow this  
Ixiodor

Draw on HBITMAP

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:

[code]
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;
[/code]

How to do this correctly?

Thanks.

Share this post


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

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

then create the bitmap and local DC like this:

[code]
HBITMAP bmp=CreateCompatibleBitmap(screenDc,width,height);
HDC dc=CreateCompatibleDC(screenDC);
[/code]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this