Check in documentation for class UIScreem, UIScreenMode and UIWindow.
In UIScreen is an array with all attached screens; index 0 is the main screen. External screen on index 1.
You can control the screen resolution with UIScreenMode.
Finally you need to create a new UIWindow and attach it to the external screen instance. Fill the content with UIKit or CALayers or other functions.
Debugging with the VGA cable is not possible as it can not pass through the debugger while connected. The new HDMI cable I think allow that, but not sure.
IOS Simulator can help with the first steps; you can simulate external monitors.
UPDATE: you can also register some notification to get informed when a screen got attached or detached.