You will be doing it via Win32 API. Although it may seem rather unrelated at first have a look at Win32-Screenshot which provides a whole lot of window handling methods like:
WindowFromPoint
GetForegroundWindow
GetDesktopWindow
GetActiveWindow
GetWindow
FindWindow
ShowWindow
GetCursorPos
SetCursorPos
GetClientRect
GetWindowRect
BringWindowToTop
GetWindowText
IsVisible
GetTopWindow
Minimize
Restore
ScrollWindow. The XS part just calls the native Win32 API calls. As you can see the Perl wrapper code is very simple.