What I've done so far is to register for the monitor being powered on/off to reconnect to the camera. Not sure if that is the best solution or not, but seems to work for me. GUID_MONITOR_POWER_ON is sent when the monitor powers on and when powers off.
Note: fPowerNotify: PVoid;
fPowerNotify := RegisterPowerSettingNotification(Self.Handle, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
Then when receiving a WM_PowerBroadcast message, I look for PBT_POWERSETTINGCHANGE like this:
PBT_POWERSETTINGCHANGE:
begin
if PPowerBroadcastSetting(Msg.LParam)^.Data[0] = 0 then
begin
Log('Power Setting Change - Monitor: Off.'); // Treating as sleeping
// Do whatever to disconnect the camera
end else
begin
Log('Power Setting Change - Monitor: On.'); // Treating as waking up
// Do whatever to reconnect the camera
end;
end;
If my handle changes, like when changing the vcl style, I unregister and re-register it in the FormShow event:
if global.MainHandle <> Self.Handle then
begin
global.MainHandle := Self.Handle;
// Re-setup notifications for "Modern Standby" with the updated handle
if Assigned(fPowerNotify) then
UnregisterPowerSettingNotification(fPowerNotify);
fPowerNotify := RegisterPowerSettingNotification(Self.Handle, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
end;
Eric