Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detect Lid closing GUID_LIDSWITCH_STATE_CHANGE for MIDI-OX
#1
Hi Gintaras,

Since MIDI-OX hangs after returning from hibernate, I have been trying with your PM_Powermanagement and PowerEvents examples to get a trigger on closing the lid (GUID_LIDSWITCH_STATE_CHANGE) or pressing the power button in order to close MIDI-OX first before hibernating. But I find myself unable to get something going Sad

Could you give me an example ?

Regards,
GertC
#2
Run this. Its thread runs all the time and can launch your other macros on lid open/closed and suspend/resume events. Delete the out lines and add mac "your macro" where need. You can assign trigger "QM events -> file loaded" to this function.

Function lid_close_open_triggers
Trigger @1     Help - how to add the trigger to the macro
Code:
Copy      Help
;stop if started second thread
if getopt(nthreads)>1
,clo win("lid_close_open_triggers" "#32770")
,ret

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "lid_close_open_triggers"
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0 0 128)) ret


#sub DlgProc
function# hDlg message wParam lParam

type __POWERBROADCAST_SETTING5219 GUID'PowerSetting DataLength Data

sel message
,case WM_INITDIALOG
,int-- t_isLidOpen=1
,int-- t_h=RegisterPowerSettingNotification(hDlg GUID_LIDSWITCH_STATE_CHANGE DEVICE_NOTIFY_WINDOW_HANDLE)
,if(t_h=0) end ERR_FAILED
,
,case WM_DESTROY
,UnregisterPowerSettingNotification t_h
,
,case WM_POWERBROADCAST
,sel wParam
,,case PBT_POWERSETTINGCHANGE
,,__POWERBROADCAST_SETTING5219& x=+lParam
,,if !memcmp(&x.PowerSetting GUID_LIDSWITCH_STATE_CHANGE sizeof(GUID))
,,,if x.Data!=t_isLidOpen
,,,,t_isLidOpen=x.Data
,,,,out _s.timeformat(F"Lid {iif(x.Data `opened` `closed`)} at {{TT}.")
,,,,
,,,,;if !t_isLidOpen ;;lid closed
,,,,,;mac "lid closed"
,,
,,case PBT_APMSUSPEND
,,out _s.timeformat("Suspended at {TT}.")
,,
,,case PBT_APMRESUMEAUTOMATIC
,,out _s.timeformat("Resumed at {TT}.")
,,
,,case PBT_APMRESUMESUSPEND
,,out _s.timeformat("User-resumed at {TT}.")
,,
,,case else
,,out _s.timeformat(F"{wParam} at {{TT}.")
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1
#3
Magical !

For anyone who uses MIDI-OX: I ran into a problem that returning from hibernation MIDI-OX hangs in such a way that it is impossible to kill the process (access denied Win 10 - even with all rights correctly set). After some research I found that it is probably due to the way MIDI-OX intertwines with Kernel routines and only a restart can solve that. So this solution we got from Gintaras here circumvents the whole problem and no one has to think anymore before closing the lid !

Thanks a million.

GertC


Forum Jump:


Users browsing this thread: 1 Guest(s)