Fog Creek Software
Discussion Board




MFC PreCreateWindow Question

Hey all,

Using Visual C++ .Net, in PreCreateWindow I use the following code to set the size and position of the app, but the code has no effect. 

BOOL CtttMFC_OneView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.cy = 257;
cs.cx = 226;
cs.x = 10;
cs.y = 10;
return CView::PreCreateWindow(cs);
}

Please help

Scott Rogers
Tuesday, October 28, 2003

Well, what happens? :)

I assume you've checked your code is being called, and that you've single-stepped through all the MFC code -- so can you provide more details?

Insert half smiley here.
Tuesday, October 28, 2003

Well, I have single stepped through the code and the CREATESTRUCT is not changed as far as I can tell, though I have not attempted to trace into the portion that does not have C++ source.  When I hit the dissassembler, I stop:)

What I found mere moments after posting the question is that  a better place to put code of this sort is in the MyApp::InitiInstance() method.  That worked like a charm.  Now the main window is sized accordingly on start up.

Thanks for the comment!

Scott Rogers
Tuesday, October 28, 2003

Try calling the parent first:

BOOL CtttMFC_OneView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CView::PreCreateWindow(cs))
return FALSE;
cs.cy = 257;
cs.cx = 226;
cs.x = 10;
cs.y = 10;
return TRUE;
}

Nick
Tuesday, October 28, 2003

Aha!  The parent should be called first?  Excellent advice.

Thanks.

Scott Rogers
Tuesday, October 28, 2003

*  Recent Topics

*  Fog Creek Home