0

I want to detect when the mouse is pressed on my wallpaper. So I got the wallpaper handle and now I'm trying to add a message loop to it, but its not working for some reason.

Here's my code so far:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow)
{
    HWND hWallPaper = getWallPaperHWND();

    if (hWallPaper != NULL)
    {

        MSG msg;
        while (GetMessage(&msg, hWallPaper, 0, 0))
        {
            MessageBox(NULL, "msg", "got message", MB_OK);
        }


    }
    else
        MessageBox(NULL,"Window wasn't found","window not found",MB_OK);
    return 0;
}

Why isn't it showing a message box when I fire an even on the wallpaper, like when I click on it or even just move the mouse?

  • 1
    Sorry. Fixed it for you :) –  Feb 07 '17 at 21:21
  • 1
    Only the thread that creates the window can retrieve messages for it. Your question title says you want to capture messages for a window you don't own. So you can't use a message loop, you will have to use a hook instead. Look at `SetWindowsHookEx()` or `SetWinEventHook()` for that. – Remy Lebeau Feb 07 '17 at 21:53
  • I will, thanks alot! –  Feb 08 '17 at 07:35

0 Answers0