Win32 SDK程序中拖动Thin边框窗口来改变窗口大小

主要需要添加处理WM_NCHITTEST,WM_SETCURSOR和WM_NCLBUTTONDOWN消息
case WM_NCHITTEST:
            POINT point;
            point.x = LOWORD(lParam);
            point.y = HIWORD(lParam);
            RECT rect;        
            GetWindowRect(hWnd,&rect);
            if(point.x <= rect.left+5)
            {
                 return HTLEFT;
            }
            else if(point.x >= rect.right-5)
            {
                return HTRIGHT;
            }
            else if(point.y <= rect.top+5)
            {    
                return HTTOP;
            }
            else if(point.y >= rect.bottom-5)
            {
                return HTBOTTOM;
            }
            else if(point.x <= rect.left+10 && point.y <= rect.top+10)
            {
                return HTTOPLEFT;
            }
            else if(point.x >= rect.right-10 && point.y <= rect.top+10)
            {
                return HTTOPRIGHT;
            }
            else if(point.x <= rect.left+10 && point.y >= rect.bottom-10)
            {
                return HTBOTTOMLEFT;
            }
            else if(point.x >= rect.right-10 && point.y >= rect.bottom-10)
            {
                return HTBOTTOMRIGHT;
            }
            return ::DefWindowProc(hWnd, message, wParam, lParam);

        case WM_SETCURSOR:
            {
                UINT nHitTest = LOWORD(lParam);
                switch(nHitTest)
                {
                case HTTOP:
                case HTBOTTOM:
                    SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
                    break;
                case HTLEFT:
                case HTRIGHT:
                    SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
                    break;
                case HTTOPLEFT:
                case HTBOTTOMRIGHT:
                    SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
                    break;
                case HTTOPRIGHT:
                case HTBOTTOMLEFT:
                    SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
                    break;
                case HTCAPTION:
                case HTSYSMENU:
                case HTMENU:
                case HTCLIENT:
                default:
                    SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
                    break;
                }
            }
            return TRUE;

        case WM_NCLBUTTONDOWN:
            switch(wParam)
            {
            case HTTOP:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, lParam);
                break;
            case HTBOTTOM:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, lParam);
                break;
            case HTLEFT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, lParam);
                break;
            case HTRIGHT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, lParam);
                break;
            case HTTOPLEFT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, lParam);
                break;
            case HTTOPRIGHT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, lParam);
                break;
            case HTBOTTOMLEFT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, lParam);
                break;
            case HTBOTTOMRIGHT:
                SendMessage(hWnd, WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, lParam);
                break;
            default:
                break;
            }
            return DefWindowProc(hWnd, message, wParam, lParam);


你可能感兴趣的:(null)