QQ登录

只需一步,快速开始

CFormView框架上位机禁止拖动缩放窗口全屏去除最大最小框

[ 复制链接 ]
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说明
  1. Mouse Enumerated Values
  2. HTBORDER   In the border of a window that does not have a sizing border.


  3. HTBOTTOM   In the lower horizontal border of the window.


  4. HTBOTTOMLEFT   In the lower-left corner of the window border.


  5. HTBOTTOMRIGHT   In the lower-right corner of the window border.


  6. HTCAPTION   In a title-bar area.


  7. HTCLIENT   In a client area.


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


  9. HTGROWBOX   In a size box.


  10. HTHSCROLL   In the horizontal scroll bar.


  11. HTLEFT   In the left border of the window.


  12. HTMAXBUTTON   In a Maximize button.


  13. HTMENU   In a menu area.


  14. HTMINBUTTON   In a Minimize button.


  15. HTNOWHERE   On the screen background or on a dividing line between windows.


  16. HTREDUCE   In a Minimize button.


  17. HTRIGHT   In the right border of the window.


  18. HTSIZE   In a size box (same as HTGROWBOX).


  19. HTSYSMENU   In a Control menu or in a Close button in a child window.


  20. HTTOP   In the upper horizontal border of the window.


  21. HTTOPLEFT   In the upper-left corner of the window border.


  22. HTTOPRIGHT   In the upper-right corner of the window border.


  23. HTTRANSPARENT   In a window currently covered by another window.


  24. HTVSCROLL   In the vertical scroll bar.


  25. HTZOOM   In a Maximize button.
复制代码


回复

使用道具 举报

大神点评(1)

快速回复 返回列表 客服中心 搜索