   Win32 - Getting the mouse location in the client area
  I've searched all over this board and have not found this answer, so if this is a double-post, I apologise.The problem is that I have a WS_OVERLAPPEDWINDOW and when I capture the mouse location with WM_MOUSEMOVE, the point I am rendering in the window is slightly behind and above the windows mouse pointer.I know that this is because the window border and title bar are being used somewhere in the capture, causing the offset in position.Both of these code examples cause this issue:case WM_MOUSEMOVE:   POINT p;GetCursorPos(&p);ScreenToClient(hWnd,&p);MyOnScreenCursor->SetPosition(p.x,p.y);break;case WM_MOUSEMOVE:MyOnScreenCursor->SetPosition(LOWORD(lParam),HIWORD(lParam));break;When I change the window style to WS_POPUP, the cursor is render exactly on point, but I don't want a WS_POPUP window.Any suggestions?ThanksPaul   
  Make sure the size of your client area is the resolution that you actually want. So, when you request a 800x600 window and call CreateWindowEx, that's INCLUDING the title bar and border. After the call, use GetClientRect() to find the actual size of your client area compared to what you want. This code will resize your window to give you the true resolution in your client area.// fix the window size for non-fullscreen because original width/height// includes border and titlebarif (!fullscreen) {    RECT windowRect, clientRect;    if (GetClientRect(hWnd, &clientRect) &&   GetWindowRect(hWnd, &windowRect))    {   if (!MoveWindow(hWnd,    windowRect.left,    windowRect.top,    resX + (resX - clientRect.right),    resY + (resY - clientRect.bottom),    TRUE))   {   // handle window resize error here however you want   }    }}Another way to do this (and maybe a better way, but I don't use it), is to use the AdjustWindowRect function. Taken straight from MSDN..."The AdjustWindowRect function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size.";Quote:Original post by jonzy_x86...the point I am rendering in the window is slightly behind and above the windows mouse pointer.Sounds like you didn't use AdjustWindowRectEx to calculate the size to pass to CreateWindowEx. If you're using D3D (I don't know if it's a problem in OGL), that means that your backbuffer is a different size from your client area, which causes issues like this. And if you're using DirectXTutorial.com, this is one of the many reasons not to.   ;  Thanks for the replies!!But, I've used AdjustWindowRect and also the code above, but still offsets.I'm starting to wonder if it is worth just going fullscreen! Problem is that I want to code in a window because I do some programming at my workstation on my lunch, and polygons flying around at fullscreen on a 21" looks a bit strange.Here, take a look...// Set window rect...m_rctWindow.top= 0;m_rctWindow.left = 0;m_rctWindow.bottom = 600;m_rctWindow.right = 800;// Adjust the window to suitAdjustWindowRect(&m_rctWindow, WS_OVERLAPPEDWINDOW, false);hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,0, 0, m_rctWindow.right, m_rctWindow.bottom, NULL, NULL, hInstance, NULL); [Edited by - jonzy_x86 on June 17, 2009 1:47:05 PM];  After the AdjustWindowRect() the upper left corner may not be 0, 0.   ;  Hmmm...I'll give that a shot then, and add it to my code...If it works, I'll post the method here.Thanks!!   ;  That might not be desirable if you're creating at 0, 0 to begin with. You wouldn't want the upper left of the window pushed up and left and off of the screen by AdjustWindowRect. I'm not sure if that function will do that to you, I haven't verified. All I'm saying is you should create at 0, 0 like you're doing (or CW_USEDEFAULT,CW_USEDEFAULT if you want to be a little more "windows friendly") and make sure that your width and height reflect the new size as returned in right-left, bottom-top.   ;  I figured it out!!Here we go...int iWidth = 800;int iHeight = 600;hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,0, 0, iWidth, iHeight, NULL, NULL, hInstance, NULL);// Set window rect...m_rctWindow.top = 0;m_rctWindow.left = 0;m_rctWindow.bottom = iWidth;m_rctWindow.right = iHeight;// Adjust the window to suitAdjustWindowRect(&m_rctWindow, WS_OVERLAPPEDWINDOW, false); MoveWindow(hWnd,0,0,m_rctWindow.right-m_rctWindow.left,m_rctWindow.bottom-m_rctWindow.top,true);...// This now works and renders the cursor on point!case WM_MOUSEMOVE:MyOnScreenCursor->SetPosition(LOWORD(lParam),HIWORD(lParam));break;;  That's a bit of a horrible way to do it. This is the generally accepted way:RECT rcWnd;rcWnd.left = 0;rcWnd.top = 0;rcWnd.right = 800;rcWnd.bottom = 600;AdjustWindowRect(&m_rctWindow, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,  // Note: Not 0 unless you have a good reasonCW_USEDEFAULT,  // Note: Not 0 unless you have a good reasonrcWnd.right-rcWnd.left, rcWnd.bottom-rcWnd.top, NULL, NULL, hInstance, NULL);No need to create then resize the window (Which will be more efficient), and it doesn't force the window to the top left corner of the screen, but lets the window manager decide where to put it.   ;Quote:Original post by Evil SteveThat's a bit of a horrible way to do it. This is the generally accepted way:*** Source Snippet Removed ***No need to create then resize the window (Which will be more efficient), and it doesn't force the window to the top left corner of the screen, but lets the window manager decide where to put it.Thanks Steve. I'll add the CW_USEDEFAULT instead of zero. The MoveWindow function call seems to be essential to making this work though. That was the line I added that made it work.The fact that I'm using OpenGL might be the reason, I don't know.I'm not particularly fussed in this case about the inefficiency, as this is in the initialisation section of the application, and is only run once.   