<p>I would like to send some keystrokes from a C++ program into another window.</p>

<p>For that reason I would like to have the user select the target window similar to how it is done in the Spy++ utility that comes with Visual Studio (drag a crosshair cursor over target window and have target window highlighted by a frame).</p>

<p>How is this dragging and selecting done in Windows? I am completely lost as to where I might start to look for a mechanism to implement this feature.</p>

Here's how it's usually done:
Capture the mouse using
SetCapture
. This will cause all mouse messages to be routed toward your app's window.
Handle the
WM_MOUSEMOVE
message. In your handler code, grab the window underneath the mouse using
WindowFromPoint
. That will get you the HWND of the window the mouse is currently over.
Now that you've got the window, you need a device context (HDC). You can get one using
GetWindowDC
for the specified window.
Now you can draw into the DC using typical GDI functions.
There are some things you have to look out for - cleanly erasing the selection rectangle and so forth, but that's one way to do it.
You could also draw into a screen DC to do this, but in any case you'll need the window handle in order to get the window rect.
If you Google around Spy++ source code you'll see a few examples of this technique.