如何为MFC MDI应用程序窗口设置最大大小? [英] How do I set maximise size for MFC MDI application window ?

查看:121
本文介绍了如何为MFC MDI应用程序窗口设置最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个针对双监视器应用场景的MFC MDI应用程序。两台显示器通过显卡连接到我的电脑,并设置为扩展模式。因此我的桌面占据了两个显示器的整个区域。但我打开应用程序只显示在主显示器窗口中。

我需要在启动时占用我的应用程序窗口在两个显示器的整个屏幕上(在两个显示器屏幕上占用的整个桌面区域)我的应用程序(以及它的最大化条件)。

如何设置我的最大化应用程序窗口以在整个屏幕上显示。



I尝试通过覆盖WM_GETMINMAXINFO消息来改变它的大小

void CMainFrame :: OnGetMinMaxInfo(MINMAXINFO * lpMMI)

{

// TODO:添加你的消息处理程序代码在这里和/或默认值





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);

}

但是它失败了

也尝试使用PrecreateWindow方法设置如下

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))

返回FALSE;

// TODO:通过修改
修改Window类或样式
// CREATESTRUCT cs



返回TRUE;

}



不幸的是,这也没有用。(但是当我最小化应用程序时,它也扩展到第二个窗口,但不是整个屏幕区域)。但是当我最大化它再次显示在主屏幕区域最大化窗口大小。



我检查了结果

cs.cx = :: GetSystemMetrics(SM_CXVIRTUALSCREEN);

cs.cy = :: GetSystemMetrics(SM_CYVIRTUALSCREEN);

在宽度和大小的情况下显示正确的像素值,即像素。主监视器像素大小+辅助监视器像素大小。

打开后我不需要调整窗口大小。我只需要在完整的窗口区域显示它。(我可以通过在PreCreateWindow()方法中配置来设置它)

如何在双显示器的全屏显示我的应用程序的最大化窗口?



编辑:

我也修改了CChildFrame的OnGetMinMaxInfo(MINMAXINFO * lpMMI)和PreCreateWindow(CREATESTRUCT& cs),现在屏幕处于最大化状态。

但是现在,在最大化状态下,应用程序窗口扩展到第二个监视器,但第二个监视器中的应用程序屏幕部分未激活。

当我调试程序时,我发现问题出现在最大化状态下框架创建的CDC中。

ie

而我检查客户端大小显示两个显示器的扩展大小,但在检查CDC的剪辑区域(由框架工作自动创建)时,它只显示主显示器的大小。



例如,在我的情况下,两个显示器的分辨率为1280 x 1024



BOOL CMainFrame :: OnEraseMDIClientBackground(CDC * pDC)

{



CRect客户端;

GetClientRect(客户端);

/ *

然后客户区获得扩展屏幕的正确大小。



rect.top = 0

rect.left = 0

rect.bottom = 890这是(1024 - 区域敌人菜单栏,工具栏等)

rect。 right = 2536其中(1280 x 2) - 侧边栏区域等)



但是我在功能中检查CDC的剪辑区域(由框架工作创建)

* /

CRect tempRect;

pDC-> GetClipBox(tempRect);

/ *

rect.top = 0

rect.left = 0

rect.bottom = 890是(1024 - 区域敌人菜单栏,工具栏等)

rect。对= 1268其中(1280) - 侧边栏等区域)



同时

* /

CRect tempRegion;

HDC testhDc = :: GetDC(NULL);

:: GetClipRgn(testhDc,tempRegion);

/ *

给出正确的结果(即GetClientRect()的结果相同)

tempRegion .top = 0

tempRegion .left = 0

tempRegion .bottom = 890

tempRegion。对= 2536



另外

* /

CRect temp2;

pDCw - > GetWindow() - > GetClientRect(&temp2);

/ *

给出正确答案

即与CDC相关的窗口具有正确的双显示器尺寸,但剪辑区域仅相同(仅限主显示器尺寸)。

* /

}

结果相同不仅在CMainFrame的情况下,而且在应用程序的每个类中,即在CChildFrame和CViews中。

另一个有趣的事情是,这只发生在最大化条件的情况下。在最小化条件下,整个应用程序区域处于活动状态(第二个监视器中的屏幕部分也是如此)和CDC :: GetClipBox和:: GetClientRect显示相同的结果,......一切都很好。

我已读过在线的某个地方,在最大化条件下,Windows应用程序只考虑主监视器的大小。

我可以通过将Framework自动创建的CDC替换为:: GetDC(NULL)的输出来排序问题。但是我必须在它即将到来的所有地方都这样做,例如CMainFrame,CChildFrame和所有视图。所以我认为这不是一个公平的方法。



我的怀疑是框架创建CDC的基础(即由CView等功能框架自动创建: :OnDraw(CDC pDC))在MFC MDI应用程序中?

我可以在一个应用程序设置中手动更改此CDC的属性(如单击),这将影响所有类应用程序吗?

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?


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?

推荐答案

这篇关于如何为MFC MDI应用程序窗口设置最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆