Advertisement
SharkyEXE

Untitled

Jul 7th, 2022
607
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #PHYSICAL_MONITOR_DESCRIPTION_SIZE = 128
  2.  
  3. Structure PHYSICAL_MONITOR
  4.   hPhysicalMonitor.i
  5.   szPhysicalMonitorDescription.u[#PHYSICAL_MONITOR_DESCRIPTION_SIZE]
  6. EndStructure
  7.  
  8. Prototype.l GetNumberOfPhysicalMonitorsFromHMONITOR_(hMonitor.i, *pdwNumberOfPhysicalMonitors.Long)
  9. Prototype.l GetPhysicalMonitorsFromHMONITOR_(hMonitor.i, dwPhysicalMonitorArraySize.l, *pPhysicalMonitorArray.PHYSICAL_MONITOR)
  10. Prototype.l DestroyPhysicalMonitors_(dwPhysicalMonitorArraySize.l, *pPhysicalMonitorArray.PHYSICAL_MONITOR)
  11. Prototype.l SetVCPFeature_( hMonitor.i, bVCPCode.a, dwNewValue.i)
  12.  
  13.  
  14. Global GetNumberOfPhysicalMonitorsFromHMONITOR_.GetNumberOfPhysicalMonitorsFromHMONITOR_
  15. Global GetPhysicalMonitorsFromHMONITOR_.GetPhysicalMonitorsFromHMONITOR_
  16. Global DestroyPhysicalMonitors_.DestroyPhysicalMonitors_
  17. Global SetVCPFeature_.SetVCPFeature_
  18.  
  19. Global hMonitor.i
  20. Global PhysicalMonitorArrayIndex.l
  21. Global PhysicalMonitorArraySize.l
  22. Global Dim PhysicalMonitorArray.PHYSICAL_MONITOR(0)
  23. Global MonitorCapabilities.l
  24. OpenLibrary(0, "Dxva2.dll")
  25.   GetNumberOfPhysicalMonitorsFromHMONITOR_ = GetFunction(0, "GetNumberOfPhysicalMonitorsFromHMONITOR")
  26.   GetPhysicalMonitorsFromHMONITOR_ = GetFunction(0, "GetPhysicalMonitorsFromHMONITOR")
  27.   DestroyPhysicalMonitors_ = GetFunction(0, "DestroyPhysicalMonitors")
  28.   SetVCPFeature_ =GetFunction(0, "SetVCPFeature")
  29. ;  hMonitor = MonitorFromPoint_(0, #MONITOR_DEFAULTTOPRIMARY)
  30. ;  If hMonitor
  31. ;       If GetNumberOfPhysicalMonitorsFromHMONITOR_(hMonitor, @PhysicalMonitorArraySize) And PhysicalMonitorArraySize > 0
  32. ;         ReDim PhysicalMonitorArray(PhysicalMonitorArraySize - 1)
  33. ;          If GetPhysicalMonitorsFromHMONITOR_(hMonitor, PhysicalMonitorArraySize, @PhysicalMonitorArray())
  34. ;            For PhysicalMonitorArrayIndex = 0 To PhysicalMonitorArraySize - 1  
  35. ;              ;SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$D6,4 )
  36. ;              SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$E1,0 )
  37. ;            Next
  38. ;            DestroyPhysicalMonitors_(PhysicalMonitorArraySize, @PhysicalMonitorArray())
  39. ;          EndIf
  40. ;        EndIf
  41. ;      EndIf
  42.  
  43. Global TimeOFF, Messaga.s,EscON
  44. TimeOFF =60
  45. MessagaON = 0
  46. EscON = 0
  47. ParameterCount.i = CountProgramParameters()                                                        
  48. If ParameterCount.i <>  0                                                                          
  49.   If Val(ProgramParameter(0)) > 0: TimeOFF =  Val(ProgramParameter(0)): EndIf
  50.   If Val(ProgramParameter(1)) > 0: MessagaON = 1: EndIf  
  51.   If Val(ProgramParameter(2)) > 0: EscON = 1: EndIf
  52. EndIf                                                                                          
  53. Procedure MonicOff()
  54.    hMonitor = MonitorFromPoint_(0, #MONITOR_DEFAULTTOPRIMARY)
  55.    If hMonitor
  56.       If GetNumberOfPhysicalMonitorsFromHMONITOR_(hMonitor, @PhysicalMonitorArraySize) And PhysicalMonitorArraySize > 0
  57.         ReDim PhysicalMonitorArray(PhysicalMonitorArraySize - 1)
  58.          If GetPhysicalMonitorsFromHMONITOR_(hMonitor, PhysicalMonitorArraySize, @PhysicalMonitorArray())
  59.            For PhysicalMonitorArrayIndex = 0 To PhysicalMonitorArraySize - 1  
  60.              ;SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$D6,4 )
  61.              ; sams SetVCPFeature,[esi+PHYSICAL_MONITOR.hPhysicalMonitor],0E1h,0
  62.  
  63.              SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$E1,0 )
  64.            Next
  65.            DestroyPhysicalMonitors_(PhysicalMonitorArraySize, @PhysicalMonitorArray())
  66.          EndIf
  67.        EndIf
  68.      EndIf
  69.    ;SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_MONITORPOWER, 2)
  70.    GetCursorPos_(pt.POINT)
  71.       Mx = pt\x
  72.       My = pt\y
  73.       offM = 0
  74.  Repeat
  75.     If EscON = 1    
  76.      If GetAsyncKeyState_(27)=-32767
  77.        offM = 1; esc = 27
  78.      Else
  79.        ;SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_MONITORPOWER, 2)
  80.      EndIf
  81.     Else
  82.    For i = 5 To 255
  83.      If GetAsyncKeyState_(i)=-32767
  84.        offM = 1
  85.      Else
  86.       ; SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_MONITORPOWER, 2)
  87.      EndIf
  88.    Next
  89.  EndIf
  90.  
  91. ;     GetCursorPos_(pt.POINT)
  92. ;     If Mx <> pt\x Or My = pt\y
  93. ;       ;SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_MONITORPOWER, 2)
  94. ;       Mx = pt\x
  95. ;       My = pt\y
  96. ;     EndIf
  97.  
  98.     Delay(1)  
  99.   Until offM = 1
  100.   hMonitor = MonitorFromPoint_(0, #MONITOR_DEFAULTTOPRIMARY)
  101.    If hMonitor
  102.       If GetNumberOfPhysicalMonitorsFromHMONITOR_(hMonitor, @PhysicalMonitorArraySize) And PhysicalMonitorArraySize > 0
  103.         ReDim PhysicalMonitorArray(PhysicalMonitorArraySize - 1)
  104.          If GetPhysicalMonitorsFromHMONITOR_(hMonitor, PhysicalMonitorArraySize, @PhysicalMonitorArray())
  105.            For PhysicalMonitorArrayIndex = 0 To PhysicalMonitorArraySize - 1  
  106.              ;SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$D6,1 )
  107.              SetVCPFeature_(PhysicalMonitorArray(PhysicalMonitorArrayIndex)\hPhysicalMonitor,$E1,1 )
  108.            Next
  109.            DestroyPhysicalMonitors_(PhysicalMonitorArraySize, @PhysicalMonitorArray())
  110.          EndIf
  111.        EndIf
  112.      EndIf
  113.  
  114.  
  115.   ;SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_MONITORPOWER, - 1)
  116. EndProcedure
  117. Procedure GetIdleTime()
  118.   Protected lipi.LASTINPUTINFO
  119.   lipi\cbSize = SizeOf(LASTINPUTINFO)
  120.   GetLastInputInfo_(@lipi)
  121.   sek.f = (GetTickCount_() - lipi\dwTime) / 1000
  122.   If sek>=TimeOFF
  123.     MonicOff()
  124.   EndIf
  125.   SetGadgetText(0, "Монитор будет потушен автоматически после " + StrD((TimeOFF - sek), 1) + " сек. простоя/бездействия! ")
  126.  
  127.  
  128. EndProcedure
  129.  
  130. MonicOff()
  131. Wh=50
  132. Ww=250
  133. OpenWindow(0, 0, 0, Ww, Wh, "", #PB_Window_BorderLess|#PB_Window_ScreenCentered)
  134. SetClassLongPtr_(WindowID(0), #GCL_STYLE, $00020000)
  135. TextGadget(0, 0, 0, Ww-0, Wh-0, "", #PB_Text_Center)
  136. AddWindowTimer(0, 1, 200)
  137. HideWindow(0, #True)
  138. ; Добавление значка в область уведомлений (SysTray)
  139.   AddSysTrayIcon(0, WindowID(0), CatchImage(0, ?Logo))
  140. GetIdleTime()
  141.  If CreatePopupMenu(0)      ; Начинается создание всплывающего Меню...
  142.    MenuItem(1, "Выход")
  143.    MenuBar()
  144.    MenuItem(2, "Погасить экран")
  145. EndIf
  146.  StickyWindow(0,1)
  147.  If MessagaON>0
  148.    HideWindow(0, #False) ;  Мессага для уведомления
  149.  EndIf
  150.  
  151. Repeat
  152.   Select WaitWindowEvent()
  153.     Case #PB_Event_CloseWindow : Break
  154.     Case #PB_Event_Timer  
  155.       Debug Timer
  156.       GetIdleTime()
  157.     Case #PB_Event_SysTray
  158.       If EventType()=#PB_EventType_RightClick
  159.          DisplayPopupMenu(0, WindowID(0))  
  160.        EndIf
  161.     Case #PB_Event_Menu        
  162.           Select EventMenu()    
  163.             Case 1 :End
  164.             Case 2
  165.               MonicOff()  
  166.           EndSelect
  167.   EndSelect
  168. ForEver
  169. CloseLibrary(0)
  170. DataSection
  171.     Logo:
  172.       IncludeBinary "offmon.ico"
  173.   EndDataSection
Advertisement
RAW Paste Data Copied
Advertisement