CFormView框架上位机禁止拖动缩放窗口全屏去除最大最小框
基于CFormView的程序,想想自己DIY界面,还真有点麻烦
这里分享DIY界面的几个功能
1.窗口全屏
窗口全屏的尺寸可以通过
GetSystemMetrics(SM_CXSCREEN);
GetSystemMetrics(SM_CYSCREEN);
获得其长宽,但会 复盖 工具条
还可改变其参数,获得工作区域尺寸
GetSystemMetrics(SM_CXFULLSCREEN);
GetSystemMetrics(SM_CYFULLSCREEN);
这两代码都在CMainFrame的消息WM_GETMINMAXINFO响应函数中添加
会发现效果不是太好,没有填充整个桌面工作区,
于是乎进行折中
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { int cx = (GetSystemMetrics(SM_CXFULLSCREEN)+16)&~7;//GetSystemMetrics(SM_CXFULLSCREEN); int cy = (GetSystemMetrics(SM_CYFULLSCREEN)+16)&~7;//GetSystemMetrics(SM_CYFULLSCREEN); lpMMI->ptMinTrackSize.x= cx; lpMMI->ptMaxTrackSize.x = cx; lpMMI->ptMaxTrackSize.y = cy; lpMMI->ptMinTrackSize.y = cy; CFrameWnd::OnGetMinMaxInfo(lpMMI);}
2.窗口去除最大最小化框,可以在CMainFrame的PreCreateWindow函数中修改结构体实现
BOOL CMainFrame:reCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd:reCreateWindow(cs) )
return FALSE;
// cs.style &=~WS_MAXIMIZEBOX;//去除最大框
// cs.style &=~WS_MINIMIZEBOX;
cs.style &= ~WS_THICKFRAME;//去除调节窗口大小
cs.x=0;//窗口初始显示左上角位置设置
cs.y=0;
return TRUE;
}
3.禁止通过鼠标调节窗口大小
在上面代码可以看到cs.style &= ~WS_THICKFRAME;就实现了去除调节窗口大小 功能;
cs.x=0;
cs.y=0;
可以设置窗口初始显示的位置
4.禁止用鼠标在标题栏拖动窗口
用鼠标拖动标题栏会触发鼠标在标题栏点击消息WM_NCLBUTTONDOWN
我们只要在此处理函数中添加如下代码就可
void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
// if (HTCAPTION == nHitTest) { return; }
CFrameWnd::OnNcLButtonDown(nHitTest, point);
}
HTCAPTION具体的介绍,可以查阅MSDN 关于函数OnNcLButtonDown说明
- Mouse Enumerated Values
- HTBORDER In the border of a window that does not have a sizing border.
- HTBOTTOM In the lower horizontal border of the window.
- HTBOTTOMLEFT In the lower-left corner of the window border.
- HTBOTTOMRIGHT In the lower-right corner of the window border.
- HTCAPTION In a title-bar area.
- HTCLIENT In a client area.
- HTERROR On the screen background or on a dividing line between windows (same as HTNOWHERE except that the DefWndProc Windows function produces a system beep to indicate an error).
- HTGROWBOX In a size box.
- HTHSCROLL In the horizontal scroll bar.
- HTLEFT In the left border of the window.
- HTMAXBUTTON In a Maximize button.
- HTMENU In a menu area.
- HTMINBUTTON In a Minimize button.
- HTNOWHERE On the screen background or on a dividing line between windows.
- HTREDUCE In a Minimize button.
- HTRIGHT In the right border of the window.
- HTSIZE In a size box (same as HTGROWBOX).
- HTSYSMENU In a Control menu or in a Close button in a child window.
- HTTOP In the upper horizontal border of the window.
- HTTOPLEFT In the upper-left corner of the window border.
- HTTOPRIGHT In the upper-right corner of the window border.
- HTTRANSPARENT In a window currently covered by another window.
- HTVSCROLL In the vertical scroll bar.
- HTZOOM In a Maximize button.
复制代码
|