   Windows Message that detects the Mouse outside Client area
  HelloI am making an application in Win32 that can display the mouse x,y coordinates whereever the mouse is, whether in the client window or outside it.What windows message is sent the Windows Proceedure function when the mouse is outside the client area of an application. I thought it was WM_NCMOUSEMOVEI have my application below that shows the mouse screen coordinates when the mouse is within the client area but not when its outside the client area. How can I detect & display the mouse coords when outside the client area#include <windows.h>#include <iostream>#include <string>#include <Windowsx.h>#include <stdio.h>using namespace std;const char g_szClassName[] = "myWindowClass";static HINSTANCE gInstance;static int scale = 4; // Scale down screen dimension by 5static int screenW = GetSystemMetrics(SM_CXSCREEN); // Get screen widthstatic int screenH = GetSystemMetrics(SM_CYSCREEN);int mX, mY;char mouseX[32];char mouseY[32];// Functions List //LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){    WNDCLASSEX wc;    HWND hwnd;    MSG Msg;    //Step 1: Registering the Window Class    wc.cbSize   = sizeof(WNDCLASSEX);    wc.style    = 0;    wc.lpfnWndProc   = WndProc;    wc.cbClsExtra    = 0;    wc.cbWndExtra    = 0;    wc.hInstance= hInstance;    wc.hIcon    = LoadIcon(NULL, IDI_APPLICATION);    wc.hCursor  = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)(DKGRAY_BRUSH);    wc.lpszMenuName  = NULL;    wc.lpszClassName = g_szClassName;    wc.hIconSm  = LoadIcon(NULL, IDI_APPLICATION);    // if registration of main class fails    if(!RegisterClassEx(&wc))    {   MessageBox(NULL, "Window Registration Failed!", "Error!",  MB_ICONEXCLAMATION | MB_OK);   return 0;    }    // Step 2: Creating the Window    hwnd = CreateWindowEx(   WS_EX_CLIENTEDGE,   g_szClassName,   "Show mouse position on screen",   WS_OVERLAPPEDWINDOW,   CW_USEDEFAULT, CW_USEDEFAULT,200,200,   NULL, NULL, hInstance, NULL);    if(hwnd == NULL)    {   MessageBox(NULL, "Window Creation Failed!", "Error!",  MB_ICONEXCLAMATION | MB_OK);   return 0;    }    ShowWindow(hwnd, nCmdShow);    UpdateWindow(hwnd);    // Step 3: The Message Loop    while(GetMessage(&Msg, NULL, 0, 0) > 0)    {   TranslateMessage(&Msg);   DispatchMessage(&Msg);    }    return Msg.wParam;}// Step 4: the Window ProcedureLRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){    switch(msg)    {   case WM_CREATE:   {    RECT rScreen;   HWND screenHwnd = GetDesktopWindow();   GetWindowRect(screenHwnd,&rScreen);   SetWindowPos(hwnd,NULL,rScreen.right-((rScreen.right/scale)+10),rScreen.top+10, rScreen.right/scale,rScreen.bottom/scale,SWP_NOZORDER);   }   case WM_MOUSEMOVE:   case WM_NCMOUSEMOVE: // detect movements of mouse in NonClient area   {   // 2 ways to get mouse Position   // 1st way:    POINT pt;   GetCursorPos(&pt);   mX = pt.x; mY = pt.y;   //mX = GET_X_LPARAM(lParam);   //mY = GET_Y_LPARAM(lParam);   itoa(mX,mouseX,10);   itoa(mY,mouseY,10);   InvalidateRect(hwnd,NULL,true);   }  break;   case WM_MOUSELEAVE: // if mouse leaves client area/window   { }   break;   case WM_PAINT:   {   HDC hdc;   PAINTSTRUCT ps; int xScaled = mX/scale;   int yScaled = mY/scale;   hdc = BeginPaint(hwnd,&ps);   //HPEN hPen = CreatePen(PS_SOLID,1,RGB(200,50,50));   HBRUSH hBrush = CreateSolidBrush(RGB(200,200,50));   HRGN hReg = CreateEllipticRgn(xScaled-10,yScaled-10,xScaled+10,yScaled+10); //SelectObject(hdc,hPen);   //Ellipse(hdc,mX-10,mY-10,mX+10,mY+10);   FillRgn(hdc,hReg,hBrush); SetBkMode(hdc,TRANSPARENT);   TextOut(hdc,10,10,mouseX,4);   TextOut(hdc,10,30,mouseY,4); EndPaint(hwnd,&ps);   }  break;   case WM_CLOSE:  DestroyWindow(hwnd);   break;   case WM_DESTROY:  PostQuitMessage(0);   break;   default:  return DefWindowProc(hwnd, msg, wParam, lParam);    }    return 0;}
  ::SetCapture().Make sure you ::ReleaseCapture() when you are done tracking the Mouse, otherwise none of your other Child Windows will receive any Mouse Messages.;  NCMOUSEMOVE will tell you if the mouse is moving inside the window but outside the client area. Messages aren't normally sent if the mouse is outside the window entirely.You can use SetCapture() to direct all mouse messages to the window regardless of whether the mouse is in the window. Normally you'd call this after the user clicked one of the mouse buttons and started dragging. This allows them to select things without worrying about the mouse leaving the window.If SetCapture() can't solve your problem, you can use hooks to redirect mouse messages to your program. The main function is SetWindowsHookEx, and messages are directed to a HookProc, and handled in a similar way as WinProc messages.   ;  Thanks for the replies, I have tried SetCapture() but it still wont work for when the mouse moving(not clicked) and is entirely outside the window/application. Is there anyway to send a message to my windows proceedure to say, "I'm the mouse, I'm moving and I am outside the window" :P I hope?   ;  taz0010 already mentioned SetWindowsHookEx, which is what you should be using (along with WH_MOUSE_LL).Note that the WH_MOUSE_LL hook has performance implications when it's installed, so make sure you only do very minimal work in the callback function (in particular, don't update your UI directly from the callback function. You probably should store the new mouse X/Y coordinates and post a message to your window that says "coordinates updated" or something).   ;  Or you could just create a timer and poll the mouse position...Why exactly do you want to do get continuous mouse updates when the mouse is outside your window?  Maybe there's a better way.   