tags:

views:

472

answers:

3

Hi all,

I have an MFC app which I have been working on for a few weeks now, I want to manually set the dimensions of the main frame when it is loaded, can someone give me a hand with this, specifically where to put the code as well?

Thanks!

+1  A: 

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.

IanW
SPI_GETWORKAREA only gets the size of the primary mnonitor. For the entire virtual desktop, use this: int desktopW = GetSystemMetrics(SM_CXVIRTUALSCREEN); int desktopH = GetSystemMetrics(SM_CYVIRTUALSCREEN);
Ben Straub
+2  A: 
Serge
+3  A: 

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.

Roel