-1

i want to have a border and title less window so i do SetWindowLongPtrW( window_handle, GWL_STYLE, 0 );

After that i can't move my Window so in my WndProc i do

if( message == WM_NCHITTEST ) {
        RECT rc;
        GetClientRect( hwnd, &rc );
        MapWindowPoints( hwnd, GetParent( hwnd ), (LPPOINT)&rc, 2 );

        int mouseX = LOWORD( lParam ) - rc.left;
        int mouseY = HIWORD( lParam ) - rc.top;
        POINT p;
        p.x = mouseX;
        p.y = mouseY;

        return PtInRect( &rc, p ) ? HTCAPTION : DefWindowProc( hwnd, message, wParam, lParam );
}

It works, the first time i move the window. After i once stop clicking with the mouse it won't move again :/

  • Compare your code to an [already existing implementation](https://github.com/melak47/BorderlessWindow). – Axalo Sep 12 '17 at 18:29

1 Answers1

1

SetWindowLongPtrW( window_handle, GWL_STYLE, 0 ); will hide the window, assuming it doesn't cause more serious problems. Use GetWindowLongPtr and combine that with valid window styles, or hide the window using ShowWindow

The error you have described is unrelated. You are attempting to find the screen coordinates of the window using GetClientRect and MapWindowPoints. The result will not be exact because the window may have borders and title bar.

Use GetWindowRect instead. This will give you screen coordinates of the window.

You can compare that with the mouse position LOWORD(lParam) and HIWORD(lParam). This is already screen coordinates. This code will move the screen every where the mouse lands in window:

RECT rc;
GetWindowRect(hwnd, &rc);
int mouseX = LOWORD(lparam);
int mouseY = HIWORD(lparam);

Don't subtract rc.left and rc.top from mouse position. That would convert the coordinates in client coordinates (roughly). Your code may work when window is on top-left corner of the screen, but it won't work later when window is moved.

Use ScreenToClient if you wish to work in client window coordinates.

Barmak Shemirani
  • 26,741
  • 4
  • 33
  • 61