C++ (CLR) mouse click inside a minimized window

Alexandru Teodor 91 Reputation points
2022-06-14T09:30:37.793+00:00

In a windows C++ CLR project I am trying to build a function that can send a mouse click to absolute x, y coords in a out of focus / minimized / hidden window.

The function is controlled by pressing a button on the app GUI.

Doing some research on google I put together the code below.

The above code does send a click to the minimized window, but not at specified coords.

The click is sent to the minimized window at the coords of the mouse pressing button on the GUI.

So whereever the GUI is located on the desktop, when I press the button that runs the function, the click is sent to the minimized window at the GUI's button coords.

If I set focus to the window (SetForegroundWindow) sleep a few seconds then perform the code above, it still does not work and the click is sent to the GUI's button coordinates. So i figure there is a problem with the code... as it should have sent the click correctly on the focused window...

Any ideeas on how I can make this code work as intended?

Thanks

211293-cpp.png

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,541 questions
{count} votes