I would like to change the font in a static text box. But I want it to be that size until I change it again. I put the following code in the OnInitDialog() function:
CWnd* pWndControl = GetDlgItem(IDC_PROGRESS_INDICATOR);
pWndControl->MoveWindow(((MyRect.right - MyRect.left)/2) - 100/2,
MyRect.top + 100/2,
100,
100,
TRUE);
CFont* pFont;
pFont->CreatePointFont(360, "Arial", pWndControl->GetWindowDC());
pWndControl->SetFont(pFont);
This will build fine. However, I get the following error:
The instruction at "0x5f440a1d" referenced memory at 0xccccccd0". The memory could not be "read".
Click on OK to terminate the program
Click on CANCEL to debug the program
I can put the same three lines of code elsewhere with differing results.
If I put it in a BN_CLICDED() then it will only change the font one time. But I get no errors or warnings at build time and no errors at run time. But, the next time I write to the static control it reverts back to the smaller font.
If I put it in the OnTimer() at build time I get this warning:
warning C4700: local variable 'MyFont' used without having been initialized
And I get the same error as before at run time.
I thought putting it in the OnInitDialog() would set the font for all time or until it was explicitly changed.