WM_NCHITTEST消息

以SDK为例:

        case WM_LBUTTONDOWN :
            pt.x = LOWORD(lParam);
            pt.y = HIWORD(lParam);
            wsprintf(mess,”pt.x=%d,pt.y=%d”,pt.x,pt.y);
            MessageBox(hwnd,mess,”调试”,MB_OK);

            /ScreenToClient(hwnd,&pt);/
            if (PtInRect(&rcClose, pt))
            {
                MessageBox(hwnd,”点击了关闭按钮”,”调试”,MB_OK);
                SendMessage(hwnd,WM_SYSCOMMAND,(WPARAM)SC_CLOSE,(LPARAM)MAKELPARAM(pt.x, pt.y));
            }
            if (PtInRect(&rcMin, pt))
            {
               SendMessage(hwnd,WM_SYSCOMMAND,(WPARAM)SC_MINIMIZE,(LPARAM)MAKELPARAM(pt.x, pt.y));
            }
            break;

        case WM_NCHITTEST:
            pt.x = LOWORD(lParam);
            pt.y = HIWORD(lParam);
            ScreenToClient(hwnd,&pt);
            if(!PtInRect(&rcClose,pt) && !PtInRect(&rcMin,pt))
                return HTCAPTION;
            else
                return HTCLIENT;

当你在消息函数中截获此消息时,你可以选择直接返回相应的值比如HTCAPTION给OS,这时经过我的测试发现OS就不会给你发送WM_LBUTTONDOWN消息了,而如上所示我需要响应WM_LBUTTONDOWN怎么办呢?这时可以通过判断相应点是否在某个区域内返回相应的值,经过测试可以运行。