when a window is not active (eg it is minimized, hidden, or under other windows) it does not receive mouse click messages.
I am going to write a program that produces a few circular waves around mouse pointer whenever the user clicks. my program is always hidden & so it is not active.
my question is how can my program receive mouse messages while it is hidden?
my program is not going to do anything else, it only produces waves after clicks.
:)

Dani AI

Generated

Short answer and context for : the XP “rings on Ctrl” (pointer-sonar) is a built-in accessibility visual and not something you can reuse to receive mouse clicks for a hidden process; SetCapture exists, but it will not solve “receive clicks while hidden”. (tomsguide.com)

SetCapture is only for the calling thread/window and only while that window can legitimately capture (foreground, or while a button is down). It cannot be used to make a hidden/background program suddenly receive normal click messages destined for other apps. (learn.microsoft.com)

Recommended approach — detect clicks system-wide, then draw a nonblocking overlay:

  • Use a low-level global mouse hook (WH_MOUSE_LL via SetWindowsHookEx) to get every click anywhere; the low-level hook runs in the installing thread (so that thread must run a message loop) and the hook callback receives MSLLHOOKSTRUCT with screen coordinates. Post those coordinates to your animation/overlay window and return quickly from the hook. Example skeleton:
HHOOK g_hHook = NULL;
HWND  g_hOverlay = /* overlay HWND */;

LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
  if (nCode >= 0) {
    auto p = (MSLLHOOKSTRUCT*)lParam;
    if (wParam == WM_LBUTTONDOWN) {
      PostMessage(g_hOverlay, WM_APP+1, (WPARAM)p->pt.x, (LPARAM)p->pt.y);
    }
  }
  return CallNextHookEx(NULL, nCode, wParam, lParam);
}

// install: g_hHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, GetModuleHandle(NULL), 0);

Low-level hooks and their threading requirements are documented here. (learn.microsoft.com)

Alternative: Raw Input with RIDEV_INPUTSINK (RegisterRawInputDevices) lets a window receive WM_INPUT even when not foreground; useful if you prefer WM_INPUT semantics and device-level info. Example flag: set RAWINPUTDEVICE.dwFlags = RIDEV_INPUTSINK and hwndTarget = your HWND. (learn.microsoft.com)

Rendering the waves: create a topmost layered window (WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST) and draw with UpdateLayeredWindow or SetLayeredWindowAttributes so the animation is visible but click-through; layered-window docs explain alpha/hit-testing rules. Unhook on exit, keep hook callbacks fast, and run on the interactive desktop. (learn.microsoft.com)

This gives a robust, system-wide way to detect clicks while hidden and paint ripples without stealing input from other apps.

there is a feature in Windows XP that produces the waves when the user presses Ctrl Key.
Can I use this feature?

I found the API SetCapture . I think it helps writing such a program. SetCapture says to Windows to send more mouse notifications to the window.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.