OnGetMinMaxInfo:
The framework calls this member function whenever Windows needs to know the maximized position or dimensions, or the minimum or maximum tracking size.
框架调用该成员函数,只要Windows需要知道最大化的位置或维度或最小值或最大拖动的范围,
如果没有提供系统将按照默认的方式去处理,要想按照自己的意图去显示,需要在此函数中提供MAXMININFO信息
afx_msg void OnGetMinMaxInfo(
MINMAXINFO* lpMMI
); |
lpMMI
Points to a MINMAXINFO structure that contains information about a window's maximized size and position and its minimum and maximum tracking size. For more about this structure, see the MINMAXINFO structure.
Remarks
The maximized size is the size of the window when its borders are fully extended. The maximum tracking size of the window is the largest window size that can be achieved by using the borders to size the window. The minimum tracking size of the window is the smallest window size that can be achieved by using the borders to size the window.
Windows fills in an array of points specifying default values for the various positions and dimensions. The application may change these values inOnGetMinMaxInfo.
Note: |
---|
This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was rec eived. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function. |
其边框是完全扩展时,该最大化的范围是窗口的大小。 窗口的最大跟踪范围是可以是通过使用边框来调整窗口的最大的窗口大小。 窗口的最小的跟踪范围是可以是通过使用边框来调整窗口的最小窗口大小。Windows加载一个数组点指定默认各种位置和尺寸的。 应用程序可以更改在 OnGetMinMaxInfo的这些值。
MINMAXINFO的结构体:
typedef struct {
POINT ptReserved; //不用
POINT ptMaxSize; //最大范围
POINT ptMaxPosition; //最大的放置点
POINT ptMinTrackSize; //最小拖动范围
POINT ptMaxTrackSize; //最大拖动范围
} MINMAXINFO;
应用实例:
如果想要实现窗口全屏,并且还有状态栏,会出现问题,那就是OnGetMinMaxInfo函数的作用。实现全屏无状态栏也一样。
你可以试一下,如果把这个函数去掉,则当你按下工具栏中的全屏显示按钮时,框架视图确实变大了,但没有想象的那样实现全屏显示,底边留下一个状态栏——一个有些发育不良的全屏显示窗口。为什么会这样呢?经过调试后,发现问题出在WM_GETMINMAXINFO消息的处理上。
在Windows中,无论什么时候以何种方式改变窗口的尺寸或大小,是拖拽窗口边缘也好,或是在代码中调用改变窗口尺寸的函数也好,总之不管你用什么方法,Windows都会首先发送WM_GETMINMAXINFO消息。这个消息的意思是说:“嘿,如果你要强迫我的尺寸变大或变小,就附上详细的MINMAXINFO结构信息,否则我用默认值处理。”大多数应用程序都不用显式处理这个 WM_GETMINMAXINFO消息(也就是说让DefWindowProc窗口过程进行缺省处理),而Windows在进行缺省处理时是不会让一个窗口视图比屏幕还大的,所以我们会碰上前面讲的那个问题。解决的方法是:不要让Windows对WM_GETMINMAXINFO消息进行缺省处理,而是由我们自己处理,方法如下:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpmmi) { CSize sz = FullScreenHandler.GetMaxSize(); lpmmi->ptMaxSize = CPoint(sz); lpmmi->ptMaxTrackSize = CPoint(sz); }
这里CFullScreenHandler.GetMaxSize 返回的最大尺寸要比整个屏幕稍微大一点。
CSize CFullScreenHandler::GetMaxSize() { CRect rc(0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); rc.InflateRect(10,50); return rc.Size(); }
剔除状态栏
// 获取屏幕信息
int nFullWidth = GetSystemMetrics(SM_CXSCREEN);
int nFullHeight = GetSystemMetrics(SM_CYSCREEN);
// 处理全屏显示的区域大小
m_FullScreenRect.left = 0;
m_FullScreenRect.top = 0;
m_FullScreenRect.right = nFullWidth;
m_FullScreenRect.bottom = nFullHeight;
#if 0 // 剔除了控制条的区域
m_FullScreenRect.left=WindowRect.left-ClientRect.left; // ClientRect需要转化成屏幕--ClientToScreen
m_FullScreenRect.top=WindowRect.top-ClientRect.top;
m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth;
m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight;
#endif
void CClockDemoDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
if(m_bFullScreen)
{
lpMMI->ptMaxSize.x = m_FullScreenRect.Width();
lpMMI->ptMaxSize.y = m_FullScreenRect.Height();
lpMMI->ptMaxPosition.x = m_FullScreenRect.Width();
lpMMI->ptMaxPosition.y = m_FullScreenRect.Height();
// 最大的拖动范围
lpMMI->ptMaxTrackSize.x = m_FullScreenRect.Width();
lpMMI->ptMaxTrackSize.y = m_FullScreenRect.Height();
}
CDialog::OnGetMinMaxInfo(lpMMI);
}