WM_NCHTTEST消息的疑问-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

WM_NCHTTEST消息的疑问

a123456678 2016-06-12 11:09:39 1433

刚学到windows程序设计这部分的内容,以下语句

case WM_NCHITTEST:
        return (LRESULT)HTNOWHERE;
我是这样理解的:不管鼠标点在屏幕的什么地方,windows都认为鼠标点在了HTNOWHERE部分,也就是屏幕背景或窗口的分隔线上。也就是说,我如果点在窗口的关闭按钮或最大化最小化按钮或拖动窗口标题栏这些操作都应该是失效的,而如果我拖动窗口边框来调整窗口大小应该是有效的。

但实际情况正好和我上面说的相反,也就是标题栏上的所有操作有效,其余操作无效。不知是不是我理解的不对?完整代码如下:

#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT("Connect");
    HWND         hwnd;
    MSG          msg;
    WNDCLASS     wndclass;

    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WndProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = szAppName;

    if (!RegisterClass(&wndclass))
    {
        MessageBox(NULL, TEXT("Program requires Windows NT!"),
            szAppName, MB_ICONERROR);
        return 0;
    }

    hwnd = CreateWindow(szAppName, TEXT("Connect-the-Points Mouse Demo"),
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT,
        NULL, NULL, hInstance, NULL);

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    
    case WM_NCHITTEST:
        return (LRESULT)HTNOWHERE;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}
test消息
分享到
取消 提交回答
全部回答(1)
  • a123456678
    2019-07-17 19:33:31
    WM_NCHITTEST页面下面有一段:
    
    Windows Vista: When creating custom frames that include the standard
    caption buttons, this message should first be passed to the
    DwmDefWindowProc function. This enables the Desktop Window Manager
    (DWM) to provide hit-testing for the captions buttons. If
    DwmDefWindowProc does not handle the message, further processing of
    WM_NCHITTEST may be needed.

    从Vista开始,非客户区的hittest由DWM管理了。所以标题栏那一块不由你控制了。

    0 0
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

相似问题
最新问题