I would like to use RegisterPowerSettingNotification in VB6.
It expects a GUID as a parameter:
HPOWERNOTIFY RegisterPowerSettingNotification(
HANDLE hRecipient,
LPCGUID PowerSettingGuid,
DWORD Flags
);
I don't find any examples on how to do that in VB6. Specifically, I don't understand how to define this GUID. I guess it's not just a string.
This is what I could come up with so far:
Private hPowerSrc&
Private hBattCapacity&
Private hMonitorOn&
Private hPowerScheme&
Private Const DEVICE_NOTIFY_WINDOW_HANDLE As Long = 0
Private Sub pInitPower()
hPowerSrc = RegisterPowerSettingNotification(Me.hWnd, GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE)
hBattCapacity = RegisterPowerSettingNotification(Me.hWnd, GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE)
hMonitorOn = RegisterPowerSettingNotification(Me.hWnd, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE)
hPowerScheme = RegisterPowerSettingNotification(Me.hWnd, GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE)
End Sub
How would I complete this sample including the API declaration and GUIDs and calling it?
Thank you!
CodePudding user response:
Per How to use GUID in VB6, try something like this:
Private hPowerSrc&
Private hBattCapacity&
Private hMonitorOn&
Private hPowerScheme&
Private Const DEVICE_NOTIFY_WINDOW_HANDLE As Long = 0
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef clsid As GUID) As Long
Private Declare Function RegisterPowerSettingNotification Lib "user32" (ByVal hRecipient As Long, ByRef PowerSettingGuid As GUID, ByVal Flags As Long) As Long;
Private Sub pInitPower()
Dim GUID_ACDC_POWER_SOURCE as GUID
Dim GUID_BATTERY_PERCENTAGE_REMAINING as GUID
Dim GUID_MONITOR_POWER_ON as GUID
Dim GUID_POWERSCHEME_PERSONALITY as GUID
CLSIDFromString StrPtr("{5D3E9A59-E9D5-4B00-A6BD-FF34FF516548}"), GUID_ACDC_POWER_SOURCE
CLSIDFromString StrPtr("{A7AD8041-B45A-4CAE-87A3-EECBB468A9E1}"), GUID_BATTERY_PERCENTAGE_REMAINING
CLSIDFromString StrPtr("{02731015-4510-4526-99E6-E5A17EBD1AEA}"), GUID_MONITOR_POWER_ON
CLSIDFromString StrPtr("{245d8541-3943-4422-b025-13A784F679B7}"), GUID_POWERSCHEME_PERSONALITY
hPowerSrc = RegisterPowerSettingNotification(Me.hWnd, GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE)
hBattCapacity = RegisterPowerSettingNotification(Me.hWnd, GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE)
hMonitorOn = RegisterPowerSettingNotification(Me.hWnd, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE)
hPowerScheme = RegisterPowerSettingNotification(Me.hWnd, GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE)
End Sub