[VB6] 呼叫螢幕保護程式、關閉螢幕電源的小工具

剛好在論壇上看到有網友在問,其實這也不是啥複雜的程式,就是直接呼叫 API 而已,我把我的工具分享出來,想用就下載,不想用就自己搞即可。

我習慣在快速工具列建立下面的捷徑:

PowerShortCut

平常離開座位一會,可以直接點選「螢幕保護程式」,中午休息時,可以直接點選「關閉螢幕電源」,純粹就是為了自己方便而已。

需要執行檔可在下列位置抓取:

https://onedrive.live.com/?cid=145419920BFD55A7&id=145419920BFD55A7%215896

RunSSave.zip 是 螢幕保護程式

ScreenPowerOff.zip 是 關閉螢幕電源

ReBoot.zip 是 重新開機

原始碼部分:

螢幕保護程式

' Windows API
Public Declare Function GetDesktopWindow Lib"user32" () As Long
Private Declare Function SendMessage Lib"user32"Alias"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
' 訊息
Private Const WM_SYSCOMMAND = &H112&
Private Const SC_SCREENSAVE = &HF140&
Public Function myScreenSaverRunning()
   hWnd = GetDesktopWindow
   myScreenSaverRunning = SendMessage(hWnd, WM_SYSCOMMAND, SC_SCREENSAVE, ByVal 0&)
End Function

關閉螢幕電源

' Windows API
Public Declare Function GetDesktopWindow Lib"user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
' 訊息
Private Const WM_SYSCOMMAND = &H112&
Private Const SC_MONITORPOWER = &HF170&
Private Const HWND_BROADCAST = &HFFFF
Public Enum DisplayPowerFlags
   [On] = -1
   Low = 1
   Off = 2
End Enum
Public Function SetScreenPower(Optional ByVal nFlag As DisplayPowerFlags = Off)
   hWnd = GetDesktopWindow
   SetScreenPower = SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal nFlag)
End Function
Categories: 工作點滴, 技術分享 | 1 則迴響

文章導覽

One thought on “[VB6] 呼叫螢幕保護程式、關閉螢幕電源的小工具

  1. 通告: 呼叫螢幕保護程式(User32.dll) | Gamegear雜七雜八的研究

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

在WordPress.com寫網誌.

%d 位部落客按了讚: