tags:

views:

70

answers:

1

What can or cannot you do in ::OnInitDialog() Visual Studio 2008 C++

I would like to write out some text on the dialog at the dialog startup. If I put the same code in a PUSH-BUTTON OnBnClicked it works. If I put it in the OnInit, it does not give me the text on the screen. I'm assuming at the OnInit, my dialog box is not completely up, so I cannot write on it?

CRect  drawRect;    
drawRect.left   = 00;       //  Shifts text to right
drawRect.right  = 300;
drawRect.top    = 00;       // How Far Down
drawRect.bottom = 300;  

// Clear out any previous name
CString strBlank = "Book Name";
SSTextOut(this->GetDC(), strBlank, &drawRect, DT_LEFT);

The function I am writing to is described in http://www.codeproject.com/KB/GDI/SSTextOut.aspx

A: 

You can't use the function SSTextOut() in OnInitDialog(). OnInitDialog() is called before your dialog is displayed, so you can't get a valid CDC inside of it (because the dialog hasn't been drawn yet).

From the looks of it, SSTextOut() is meant to be called from an OnPaint() override.

adam
Is there another function that I can use to put up text in the OnInit where I can control font size etc?Thanks for the reply, I've sweated many hours over this!
@flirishman You can set the font size of most controls in OnInitDialog(), however it would be better to do it via the resource editor. You can't draw anything in OnInitDialog(), which is what SSTextOut() is trying to do.
adam