Of course, Windows never let you do this, what if you are trying to steal a user password? you are not allowed to receive input until you have focus!
But you can do some tricks here: you have to write a hook function for the mouse or keyboard, and this function should be implemented in a DLL (and not on your EXE). SetWindowsHookEx to install it, and then use the IPC mechanism in your DLL to send mouse and / or keyboard messages to your main EXE.
But apart from this: while he usually works with the line
HWND handle = FindWindow(NULL,CStringW("Untitled - Notepad"));
make no sense, windows should have a version of most functions that receive at least one string argument: one for ANSI, that its name is terminated with A and one for wide (UTF-16), which is terminated with W MSVC has an additional layer over this design called TCHAR and with define map all such functions can be used with ANSI or Wide, so if you use this version of the API, it is impractical to directly use CStringW , which generate wide strings. And since the Windows API works with char* and wchar_t* , why do you convert a string literal to a CString and then pass it to a function? You must use one of the following values:
// This also work with CStringA HWND handleA = FindWindowA(NULL, "Untitled - Notepad"); // This also work with CStringW HWND handleW = FindWindowW(NULL, L"Untitled - Notepad"); // This also work with CString HWND handleT = FindWindow(NULL, _T("Untitled - Notepad") );
source share