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 :/
SetWindowLongPtrW( window_handle, GWL_STYLE, 0 );
will hide the window, assuming it doesn't cause more serious problems. UseGetWindowLongPtr
and combine that with valid window styles, or hide the window usingShowWindow
The error you have described is unrelated. You are attempting to find the screen coordinates of the window using
GetClientRect
andMapWindowPoints
. 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)
andHIWORD(lParam)
. This is already screen coordinates. This code will move the screen every where the mouse lands in window:Don't subtract
rc.left
andrc.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.