Seems to me like you provided the answers to your own question above...
HWND pTargetWindowHandle = FindWindow("Notepad", char());...ShowWindow(pTargetWindowHandle, SW_RESTORE);SetForegroundWindow(pTargetWindowHandle);
If the window is minimized ShowWindow will bring it back up, and the next call will give it focus.
If the window is at the bottom of the z-order, GetForegroundWindow will bring it back to the top, and give you focus...
Also, keep in mind that SetFocus doesn't work because your window isn't attached to your thread's message queue.
Hope that helps...
P.S.
Also, if you want to send characters to a specific window, for example, notepad, which has an "Edit" control, you can send it the WM_SETTEXT message, that way you won't need to worry about window focus, and key states.
Or if you'd like to append a character you could send WM_CHAR.
For example,
HWND pTargetWindowHandle = FindWindowEx(FindWindow("Notepad", char()), HWND(), "Edit", char());std::string pString("abc");...SendMessage(pTargetWindowHandle, WM_SETTEXT, WPARAM(), reinterpret_cast <LPARAM> (pString.c_str())); for(std::string::iterator iIndex = pString.begin() ; iIndex < pString.end() ; iIndex ++) SendMessage(pTargetWindowHandle, WM_CHAR, * iIndex, LPARAM());