jdl
jdl

Reputation: 6323

CDC::DrawText doesn't work?

I get an error: Debug Assertion Failed at my myDC.DrawText? If I remove that line, the graphics work fine.

CPaintDC dc(this);

CBitmap myBmp;
CDC myDc;

HANDLE h = ::LoadImage(NULL,"C:\\lady.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
myBmp.Attach(h);

myDc.DrawText("Hello",CRect(10,10,100,30),DT_CENTER);  // Debug Assertion Failed


myDc.CreateCompatibleDC(&dc);
myDc.SelectObject(&myBmp);
dc.BitBlt(20,10,436,363,&myDc,0,0,SRCCOPY);

Upvotes: 0

Views: 2114

Answers (1)

jlew
jlew

Reputation: 10591

You're drawing the text before actually creating the DC. Move the DrawText line below the CreateCompatibleDB line.

Upvotes: 3

Related Questions