#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
$Form1 = GUICreate("Form1")
$Button = GUICtrlCreateButton('Exit', 100, 50, 100, 22)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button
_ScreenCapture_CaptureWnd (@ScriptDir & "\Screenshot.jpg", $Form1, 0, 0, -1, -1, False)
Exit
EndSwitch
WEnd