I am trying to draw sample text in a Picture control in MFC Dialog. Following is the code I am using in order to draw the text, which changes as I change the colour and the text of the font.
Therefore I have written a separate function to draw the text (DrawSampleText()) and OnPaint event calls that function.
} // <- Assert at this point
hFont = CreateFont( 30, 0, 0, 0, FW_NORMAL,
FALSE, FALSE, FALSE, DEFAULT_CHARSET,
CDC* cdc = m_sampleText.GetDC();
cdc->DrawText(FontName, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
When I run the DEBUG version of the program and open the NotesDlg few times, program comes up with the Assert Message:<BR>
Debug Assertion Failed!
I have highlighted above in the code where the Assert fail. It happens when OnPaint is trying to exit the function. Assert fail in the RemoveHandle() function defined in the winhand.cpp file with
if (m_nHandles == 2)
ASSERT(ph == h); //<- This Assert fail (value of ph = NULL, but h != NULL)
I have tried number of different things such as removing the "CPaintDC dc(this)" line from the OnPaint() event, this caused and infinite loop of OnPaint event and eventually crashed the program.
The only solution I could come up with was to turn off assert messages as shown below in the code.
int nPrevMode = _CrtSetReportMode(_CRT_ASSERT,0);
This program occurs on Windows 98 machines with about 128MB or less memory. I was not able to reproduce this in Win2K with 256+MB RAM. Does anybody know why this could be happening or how I could
correct my code to fix this Assert fail.
Btw, I do not have many points and I have allocated all the points I have for this question.