PowerManager.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "stdafx.h"
  2. #include "PowerManager.h"
  3. #include "Misc.h"
  4. static HWND s_notifyHwnd;
  5. static ULONG PowerChanged(PVOID Context, ULONG Type, PVOID Setting);
  6. ULONG PowerChanged(PVOID Context, ULONG Type, PVOID Setting)
  7. {
  8. //a
  9. //b
  10. //c
  11. CString cs;
  12. cs.Format(_T("PowerChanged Type %d"), Type);
  13. Log(cs);
  14. if(Type == PBT_APMRESUMEAUTOMATIC)
  15. {
  16. //had reports of the main window not showing clips after resuming (report was from a vmware vm), catch the resuming callback from windows
  17. //and close and reopen the database
  18. Log(_T("windows is RESUMING, sending message to main window to close and reopen the database/qpastewnd"));
  19. ::PostMessage(s_notifyHwnd, WM_REOPEN_DATABASE, 0, 0);
  20. }
  21. return 0;
  22. }
  23. CPowerManager::CPowerManager()
  24. {
  25. m_registrationHandle = 0;
  26. }
  27. CPowerManager::~CPowerManager(void)
  28. {
  29. }
  30. void CPowerManager::Start(HWND hWnd)
  31. {
  32. s_notifyHwnd = hWnd;
  33. HMODULE powrprof = LoadLibrary( _T("powrprof.dll") );
  34. if( powrprof != NULL )
  35. {
  36. DWORD (_stdcall*PowerRegisterSuspendResumeNotification)(_In_ DWORD,_In_ HANDLE,_Out_ PHPOWERNOTIFY);
  37. PowerRegisterSuspendResumeNotification = (DWORD(_stdcall*)(_In_ DWORD,_In_ HANDLE,_Out_ PHPOWERNOTIFY))GetProcAddress(powrprof, "PowerRegisterSuspendResumeNotification");
  38. if(PowerRegisterSuspendResumeNotification)
  39. {
  40. static _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS testCallback = {PowerChanged, nullptr};
  41. PowerRegisterSuspendResumeNotification(DEVICE_NOTIFY_CALLBACK, &testCallback, &m_registrationHandle);
  42. }
  43. ::FreeLibrary(powrprof);
  44. }
  45. }
  46. void CPowerManager::Close()
  47. {
  48. if(m_registrationHandle != 0)
  49. {
  50. HMODULE powrprof = LoadLibrary( _T("powrprof.dll") );
  51. if( powrprof != NULL )
  52. {
  53. DWORD (_stdcall*PowerUnregisterSuspendResumeNotification)(_Inout_ PHPOWERNOTIFY);
  54. PowerUnregisterSuspendResumeNotification = (DWORD(_stdcall*)(_Inout_ PHPOWERNOTIFY))GetProcAddress(powrprof, "PowerUnregisterSuspendResumeNotification");
  55. if(PowerUnregisterSuspendResumeNotification)
  56. {
  57. PowerUnregisterSuspendResumeNotification(&m_registrationHandle);
  58. }
  59. ::FreeLibrary(powrprof);
  60. }
  61. }
  62. }