zoukankan      html  css  js  c++  java
  • 对话框拖动及其禁止方法

    禁止拖动对话框方法:

    在WM_HITTEST对应的消息处理函数OnNcHitTest中直接返回TRUE, 或者当指向对话框标题栏时,返回客户区的值HTCLIENT

    例子:

    UINT CWelcomeDlg::OnNcHitTest(CPoint point)
    {
        // TODO: Add your message handler code here and/or call default
       
        return HTCLIENT;
    }

    拖动对话框方法:

    在WM_HITTEST对应的消息处理函数OnNcHitTest中, 当指向对话框客户区时,返回标题区的值HTCAPTION

    例子:

    UINT CDlg::OnNcHitTest(CPoint point)
    {
        // TODO: Add your message handler code here and/or call default
        ScreenToClient(&point);

        if (point.y >= 0 && point.y <= DLGCAPHIGHT)
        {
            return HTCAPTION;
        }
       
        return CDialog::OnNcHitTest(point);
    }

    参考资料:

    WM_NCHITTEST

    The WM_NCHITTEST message is sent to a window when the cursor moves, or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

    A window receives this message through its WindowProc function.

    LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window
     UINT uMsg, // WM_NCHITTEST
     WPARAM wParam, // not used
     LPARAM lParam    // horizontal and vertical position
    );

    Parameters

    wParam
    This parameter is not used.
    lParam
    The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

    The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the screen.

    Return Values

    The return value of the DefWindowProc function is one of the following values, indicating the position of the cursor hot spot.

    ValueLocation of hot spot
    HTBORDER In the border of a window that does not have a sizing border.
    HTBOTTOM In the lower-horizontal border of a resizable window (the user can click the mouse to resize the window vertically).
    HTBOTTOMLEFT In the lower-left corner of a border of a resizable window (the user can click the mouse to resize the window diagonally).
    HTBOTTOMRIGHT In the lower-right corner of a border of a resizable window (the user can click the mouse to resize the window diagonally).
    HTCAPTION In a title bar.
    HTCLIENT In a client area.
    HTCLOSE In a Close button.
    HTERROR On the screen background or on a dividing line between windows (same as HTNOWHERE, except that the DefWindowProc function produces a system beep to indicate an error).
    HTGROWBOX In a size box (same as HTSIZE).
    HTHELP In a Help button.
    HTHSCROLL In a horizontal scroll bar.
    HTLEFT In the left border of a resizable window (the user can click the mouse to resize the window horizontally).
    HTMENU In a menu.
    HTMAXBUTTON In a Maximize button.
    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 a resizable window (the user can click the mouse to resize the window horizontally).
    HTSIZE In a size box (same as HTGROWBOX).
    HTSYSMENU In a window menu or in a Close button in a child window.
    HTTOP In the upper-horizontal border of a window.
    HTTOPLEFT In the upper-left corner of a window border.
    HTTOPRIGHT In the upper-right corner of a window border.
    HTTRANSPARENT In a window currently covered by another window in the same thread (the message will be sent to underlying windows in the same thread until one of them returns a code that is not HTTRANSPARENT).
    HTVSCROLL In the vertical scroll bar.
    HTZOOM In a Maximize button.


    CWnd::OnNcHitTest

    afx_msg UINT OnNcHitTest( CPoint point );

    Return Value

    One of the mouse hit-test enumerated values listed below.

    Parameters

    point

    Contains the x- and y-coordinates of the cursor. These coordinates are always screen coordinates.

    Remarks

    The framework calls this member function for the CWnd object that contains the cursor (or the CWnd object that used the SetCapture member function to capture the mouse input) every time the mouse is moved.

    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 received. 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.

    See Also   CWnd::GetCapture, WM_NCHITTEST

    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。

    转自:CSDN

    作者:BuildNewApp
    出处:http://syxchina.cnblogs.comBuildNewApp.com
    本文版权归作者、博客园和百度空间共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则作者会诅咒你的。
    如果您阅读了我的文章并觉得有价值请点击此处,谢谢您的肯定1。
  • 相关阅读:
    任意用户密码重置漏洞
    0基础入门学习Python(第4章)
    dpwwn:2 Vulnhub Walkthrough
    The Library:2 Vulnhub Walkthrough
    WestWild: 1.1: Vulnhub Walkthorugh
    Canvas---折线图---绘制网格
    Canvas---绘制一个由黑到白渐变的矩形
    Canvas---绘制虚线
    Canvas---和线相关的属性和方法
    Canvas---绘制一个镂空正方形
  • 原文地址:https://www.cnblogs.com/syxchina/p/2197690.html
Copyright © 2011-2022 走看看