#NoTrayIcon #CS ==================================================================================================== #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=Monitor32.exe #AutoIt3Wrapper_Outfile_x64=Monitor64.exe #AutoIt3Wrapper_UseUpx=Y #AutoIt3Wrapper_Compile_Both=Y #AutoIt3Wrapper_UseX64=Y #AutoIt3Wrapper_Change2CUI=Y #AutoIt3Wrapper_Res_Comment=Monitor On/Off #AutoIt3Wrapper_Res_Description=Monitor On/Off #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_ProductVersion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Wayne Tan #AutoIt3Wrapper_Res_Field=ProductName|Monitor.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** If $CMDLINE[0] < 1 Then _Enum() Exit 0 Else Switch $CMDLINE[1] Case "/RES" _ChgRes() Case "/ON" _Monitor_ON() Exit 0 Case "/OFF" _Monitor_OFF() Exit 0 Case "/?" _Usage() Exit 0 Case Else _Usage() Exit 0 EndSwitch EndIf Exit 0 #CE ==================================================================================================== #Include #Include #Include #Include #Include Global Const $lciWM_SYSCommand = 274 Global Const $lciSC_MonitorPower = 61808 Global Const $lciPower_Off = 2 Global Const $lciPower_On = -1 Global $MonitorIsOff = False Func _MonitorOnOff() Local $Tips = @CRLF & "CMD:" & @TAB & "/MON ON|OFF" & @CRLF _ & "Usage:" & @TAB & "Turn on/off the display monitor." & @CRLF _ & "Parameters:" & @CRLF _ & "ON:" & @TAB & "Turn on the monitor." & @CRLF _ & "OFF:" & @TAB & "Turn off the monitor." & @CRLF If $CMDLINE[0] < 2 Then ConsoleWrite($Tips) Exit 0 EndIf Local $SW = $CMDLINE[2] Switch $SW Case "ON" _Monitor_ON() Exit Case "OFF" _Monitor_OFF() Exit Case Else ConsoleWrite($Tips) Exit 0 EndSwitch Exit 0 EndFunc Func _Monitor_ON() $MonitorIsOff = False Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]') DllCall('user32.dll', 'int', 'SendMessage', _ 'hwnd', $Progman_hwnd, _ 'int', $lciWM_SYSCommand, _ 'int', $lciSC_MonitorPower, _ 'int', $lciPower_On) Send("{Capslock}") EndFunc Func _Monitor_OFF() $MonitorIsOff = True Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]') ;While $MonitorIsOff = True DllCall('user32.dll', 'int', 'SendMessage', _ 'hwnd', $Progman_hwnd, _ 'int', $lciWM_SYSCommand, _ 'int', $lciSC_MonitorPower, _ 'int', $lciPower_Off) ;_IdleWaitCommit(0) ;Sleep(20) ;WEnd EndFunc Func _IdleWaitCommit($idlesec) Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword") DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo)) DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo)) Do $iSave = DllStructGetData ($LastInputInfo, 2) Sleep(60) DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo)) Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec or $MonitorIsOff = False Return DllStructGetData ($LastInputInfo, 2)-$iSave EndFunc Func _Enum() Local $Data, $i = 0 ConsoleWrite(@CRLF & "--- Desktop Monitor Information ---" & @CRLF) ConsoleWrite(@CRLF & "Supported Modes:" & @CRLF) While 1 $Data = _WinAPI_EnumDisplaySettings('', $i) If IsArray($Data) Then ConsoleWrite($Data[0] & " X " & $Data[1] & @TAB & $Data[2] & 'Bit' & @TAB & $Data[3] & "Hz" & @TAB & "Mode:" & $Data[4] & @CRLF) Else ExitLoop EndIf $i += 3 WEnd $Current = _WinAPI_EnumDisplaySettings('',$ENUM_CURRENT_SETTINGS) ;_ArrayUnique($Current) Local $CurrInfo = @CRLF & 'Current Settings: ' & @CRLF _ & 'Resolution:' & @TAB & $Current[0] & ' X ' & $Current[1] & @CRLF _ & 'Deepth:' & @TAB & @TAB & $Current[2] & 'Bit' & @CRLF _ & 'Frequency:' & @TAB & $Current[3] & 'HZ' & @CRLF _ & 'Mode:' & @TAB & @TAB & $Current[4] & @CRLF ConsoleWrite($CurrInfo) Exit 0 EndFunc Func _ChgRes() Switch $CMDLINE[0] Case 1 $i_Width = @DesktopWidth $i_Height = @DesktopHeight $i_BitsPP = @DesktopDepth $i_RefreshRate = @DesktopRefresh Case 2 $i_Width = $CMDLINE[2] $i_Height = @DesktopHeight $i_BitsPP = @DesktopDepth $i_RefreshRate = @DesktopRefresh Case 3 $i_Width = $CMDLINE[2] $i_Height = $CMDLINE[3] $i_BitsPP = @DesktopDepth $i_RefreshRate = @DesktopRefresh Case 4 $i_Width = $CMDLINE[2] $i_Height = $CMDLINE[3] $i_BitsPP = $CMDLINE[4] $i_RefreshRate = @DesktopRefresh Case 5 $i_Width = $CMDLINE[2] $i_Height = $CMDLINE[3] $i_BitsPP = $CMDLINE[4] $i_RefreshRate = $CMDLINE[5] Case Else $i_Width = $CMDLINE[2] $i_Height = $CMDLINE[3] $i_BitsPP = $CMDLINE[4] $i_RefreshRate = $CMDLINE[5] EndSwitch If $CMDLINE[0] >= 2 Then If $CMDLINE[2] = "/?" Then ConsoleWrite(@CRLF & "CMD:" & @TAB & "/RES [Width] [Height] [ColorDeepth] [RefreshRate]" & @CRLF) Exit 0 EndIf EndIf Local $RET = _ChangeScreenRes($i_Width, $i_Height, $i_BitsPP, $i_RefreshRate) If @Error = 0 Then ConsoleWrite("Return Code: " & @Error & @CRLF & "Set Screen Resolution Successed." & @CRLF) Exit 0 Else ConsoleWrite("Return Code: " & @Error & @CRLF & "Set Screen Resolution Failed." & @CRLF) Exit 1 EndIf Exit EndFunc #CS ==================================================================================================== Func _Usage() Local $MSG = @CRLF & "Monitor.exe V1.0 Build 20160614" & @CRLF & @CRLF _ & "Usage:" & @TAB & "Set Screren Resoluton / Turn Monitor On/Off." & @CRLF & @CRLF _ & "Command:" & @CRLF _ & "Monitor.exe /ON " & @TAB & "Turn on the monitor." & @CRLF _ & "Monitor.exe /OFF " & @TAB & "Turn off the monitor." & @CRLF _ & "Monitor.exe /RES [Width] [Height] [ColorDeepth] [RefreshRate]" & @CRLF & @CRLF ConsoleWrite($MSG) Exit 0 EndFunc #CE ==================================================================================================== Func _Quit() _Monitor_ON() Exit EndFunc