Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have developed an MFC MDI application targeted for a dual monitor application scenario. Two monitors are connected to my PC through a graphics card and are set in extended mode. Therefore my desktop is occupied in entire area of two monitors. But I opening the application its only displaying in primary monitor window.
I need to occupy my application window on entire screens of both the monitors (to entire desktop area occupied in both monitor screen)on while starting up my application(as well as its maximized condition).
How can I set my maximized application window to display on entire screen.

I tried to change it's size by overriding WM_GETMINMAXINFO message
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// TODO: Add your message handler code here and/or call default


MINMAXINFO lpMMItemp;
lpMMItemp.ptMaxPosition.x = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
lpMMItemp.ptMaxPosition.y = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
lpMMItemp.ptMaxSize.x = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
lpMMItemp.ptMaxSize.y = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
lpMMItemp.ptMaxTrackSize.x = ::GetSystemMetrics(SM_CXMAXTRACK);
lpMMItemp.ptMaxTrackSize.y = ::GetSystemMetrics(SM_CYMAXTRACK);
lpMMItemp.ptMinTrackSize.x = ::GetSystemMetrics(SM_CXMINTRACK);
lpMMItemp.ptMinTrackSize.y = ::GetSystemMetrics(SM_CYMINTRACK);

CMDIFrameWndEx::OnGetMinMaxInfo(&lpMMItemp);
}
but it failed
also tried to set using PrecreateWindow method as follows
CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
cs.x = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
cs.y = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
cs.cx = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
cs.cy = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);

if( !CMDIFrameWndEx::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return TRUE;
}

unfortunately this also not worked.(But while I minimize the application it extending to second window also but not to entire screen area). But while I maximize it again displaying in primary screen area maximize window size.

I checked the results of
cs.cx = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
cs.cy = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
its showing the correct pixel values in case of width & size in pixels ie. primary monitor pixel size + secondary monitor pixel size.
I don't need to resize my window after opening. I only have to show it in full window area.(I could set it by configuring in PreCreateWindow() method)
How can display my application's maximixed window in full screen of dual monitors?

EDIT:
I mofified OnGetMinMaxInfo(MINMAXINFO* lpMMI) & PreCreateWindow(CREATESTRUCT& cs) of CChildFrame also, now the screen in maximixed condition.
But now while on maximized state the application window extending to the second monitor but the part of the application screen in second monitor is not active.
while I debug the program I found that the problem is in "CDC" created by the framework in Maximised state.
ie
while I checking client size its showing extended size of two monitor but while check the clip region of CDC(which is automatically created by the frame work) it showing only the size of primary monitor.

For exmaple in my case the two displays are of resolution 1280 x 1024

BOOL CMainFrame::OnEraseMDIClientBackground(CDC* pDC)
{

CRect client;
GetClientRect(client);
/*
then the client area getting correct size of the extended screen.

rect.top = 0
rect.left = 0
rect.bottom = 890 which is (1024 - area foe menu bar, tool bar etc)
rect. right = 2536 which (1280 x 2) - area for sidebar etc)

but while I check the clip region of CDC ( created by the frame work) in the fuction
*/
CRect tempRect;
pDC->GetClipBox(tempRect);
/*
the results got were
rect.top = 0
rect.left = 0
rect.bottom = 890 which is (1024 - area foe menu bar, tool bar etc)
rect. right = 1268 which (1280) - area for sidebar etc)

At the same time
*/
CRect tempRegion;
HDC testhDc = ::GetDC(NULL);
::GetClipRgn( testhDc , tempRegion );
/*
giving the correct result (ie same result of GetClientRect() )
tempRegion .top = 0
tempRegion .left = 0
tempRegion .bottom = 890
tempRegion . right = 2536

Also
*/
CRect temp2;
pDCw->GetWindow()->GetClientRect(&temp2);
/*
giving correct answer
ie the window associated with the CDC have correct dual monitor dimension but the clip region is only different(only primary monitor size).
*/
}
This results are same not only in case of CMainFrame but also in every classes in the application ie in CChildFrame and CViews .
Another interesting thing is, this is only happening in case maximixed condition. While in minimize condition the full application area is active(the part of the screen in second monitor also) and CDC::GetClipBox and ::GetClientRect showing same results,.. everything fine.
I have read somewhere online that in Maximize condition the Windows applications only consider the size of Primary monitor only.
I can sort the issue by replacing automatically created CDC by Framework to output of ::GetDC(NULL). But I have to do it in everywhere its coming ie in case of CMainFrame, CChildFrame, & all Views. So I think it's not a fair way to do it.

My doubt is on what basis the framework creates the CDC (ie automatically created by framework for function like CView::OnDraw(CDC pDC)) in MFC MDI application?
Can I change the properties (like click) of this CDC manually in one place application settings which will affect in all classes of application?
Posted
Updated 30-Apr-14 23:42pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900