MFC OnGetMinMaxInfo、WM_MINMAXINFO

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

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


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值