Click to See Complete Forum and Search --> : how to create CDC dc; - I am just plain confused


Erich Ruth
September 25th, 1999, 10:36 AM
I took a function from codeguru. I want to call this function shown below in OnInitialUpdate.

void DrawBitmap( HDC hdc, ....)

I tried just typing:

OnInitialUpdate()
{
CDC dc;
DrawBitmap(dc.m_hDC, ....);
}



but in the function DrawBitmap(), I get a debug assertion error at the line:

ASSERT( hdc != NULL );

I don't understand how to construct or create the variable CDC dc;.

I have read through MSDN and am still stuck. Please, any response any one can give me to get past this debug assertion error will be greatly appreciated.

Sincerely,
Erich J. Ruth

N Tufarelli
September 25th, 1999, 11:52 AM
Usually in MFC the default constructor does nothing; so in your code you have a CDC variable that is not initialised.
Try this code:

OnInitialUpdate()
{
CDC* pDc = GetDC();
if (pDc != NULL)
{
DrawBitmap(pDc->m_hDC, ....);
ReleaseDC(pDc);
}
}