Of course Windows never let you do that, what if you try to steal password of the user?? you are not allowed to receive input while you don't have the focus!!
But you may do some tricks here: you should write a hook function for mouse or keyboard and this function should implemented in a DLL(not your EXE) use SetWindowsHookEx to install it and then use an IPC mechanism in your DLL to send mouse and/or keyboard messages to your main EXE.
But beside that: while it usually work the line
HWND handle = FindWindow(NULL,CStringW("Untitled - Notepad"));
foes not make any sense, windows have to version of most of functions that get at least one string argument: one for ANSI that its name terminated with A
and one for wide(UTF-16) characters that terminated with W
. MSVC have an extra layer over this design called TCHAR
and by using define map all such functions to eith ANSI or Wide, so if you are using that version of API it is not wise to directly use CStringW
that generate wide strings. And since Windows API work with char*
and wchar_t*
why you convert your string literal to CString
and then pass it to the function? you should use one of this:
// 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") );