Sizing an MFC Window

I think you're looking for PreCreateWindow and that your app isn't dialog based.

It's a virtual member function of CWnd class and it's called by framework just before a window is created. So it's a right place to place your changes.

You should write something like this:

BOOL CMyWindow::PreCreateWindow(CREATESTRUCT& cs)
{
   cs.cy = 640; // width
   cs.cx = 480; // height
   cs.y = 0; // top position
   cs.x = 0; // left position
   // don't forget to call base class version, suppose you derived you window from CWnd
   return CWnd::PreCreateWindow(cs);
}

Find your screen size with ..

CRect rect;
SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
screen_x_size=rect.Width();  
screen_y_size=rect.Height();

use these values to calculate the X and Y size of your window then ..

::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,main_x_size,main_y_size,SWP_NOZORDER); 

Where main_x_size and main_y_size are your sizes.


You can also set the size (with SetWindowPos()) from within CMainFrame::OnCreate(), or in the CWinApp-derived class' InitInstance. Look for the line that says pMainFrame->ShowWindow(), and call pMainFrame->SetWindowPos() before that line. That's where I always do it.

Tags:

C++

Mfc