| 136 | } |
| 137 | |
| 138 | void OnMainWindowCreated(HWND hWnd) |
| 139 | { |
| 140 | // Register for app suspending/resuming events |
| 141 | PlmSuspendComplete = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); |
| 142 | PlmSignalResume = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); |
| 143 | if (!PlmSuspendComplete || !PlmSignalResume) |
| 144 | return; |
| 145 | if (RegisterAppStateChangeNotification([](BOOLEAN quiesced, PVOID context) |
| 146 | { |
| 147 | if (quiesced) |
| 148 | { |
| 149 | ResetEvent(PlmSuspendComplete); |
| 150 | ResetEvent(PlmSignalResume); |
| 151 | |
| 152 | // To ensure we use the main UI thread to process the notification, we self-post a message |
| 153 | PostMessage(reinterpret_cast<HWND>(context), WM_USER, 0, 0); |
| 154 | |
| 155 | // To defer suspend, you must wait to exit this callback |
| 156 | WaitForSingleObject(PlmSuspendComplete, INFINITE); |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | SetEvent(PlmSignalResume); |
| 161 | } |
| 162 | }, hWnd, &Plm)) |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | void CALLBACK AddUserComplete(_In_ XAsyncBlock* ab) |
| 167 | { |