PlatformWinAPI::PlatformWinAPI (const WinAPI::FakeQWidgetWinAPI_ptr& widget, const ICoreProxy_ptr& proxy, QObject* parent) : PlatformLayer (proxy, parent) , HPowerSchemeNotify_ (new HPOWERNOTIFY, aHPowerNotifyDeleter) , HPowerSourceNotify_ (new HPOWERNOTIFY, aHPowerNotifyDeleter) , HBatteryPowerNotify_ (new HPOWERNOTIFY, aHPowerNotifyDeleter) , FakeWidget_ (widget) { HWND h_wnd = reinterpret_cast<HWND> (FakeWidget_->winId ()); *HPowerSchemeNotify_ = RegisterPowerSettingNotification (h_wnd, &GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE); Q_ASSERT (*HPowerSchemeNotify_); *HPowerSourceNotify_ = RegisterPowerSettingNotification (h_wnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); Q_ASSERT (*HPowerSourceNotify_); *HBatteryPowerNotify_ = RegisterPowerSettingNotification (h_wnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); Q_ASSERT (*HBatteryPowerNotify_); connect (FakeWidget_.get (), SIGNAL (schemeChanged (QString)), this, SLOT (handleSchemeChanged (QString))); connect (FakeWidget_.get (), SIGNAL (powerSourceChanged (QString)), this, SLOT (handlePowerSourceChanged (QString))); }
void EnableBatteryNotifications() { // Create custom window to watch battery event // If we can get Gecko's window handle, this is unnecessary. if (sHWnd == nullptr) { WNDCLASSW wc; HMODULE hSelf = GetModuleHandle(nullptr); if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) { ZeroMemory(&wc, sizeof(WNDCLASSW)); wc.hInstance = hSelf; wc.lpfnWndProc = BatteryWindowProc; wc.lpszClassName = L"MozillaBatteryClass"; RegisterClassW(&wc); } sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher", 0, 0, 0, 0, 0, nullptr, nullptr, hSelf, nullptr); } if (sHWnd == nullptr) { return; } sPowerHandle = RegisterPowerSettingNotification(sHWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); sCapacityHandle = RegisterPowerSettingNotification(sHWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); }
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT /*lpCreateStruct*/) { BOOL fSuccess = FALSE; IMFAttributes* pAttributes = NULL; HRESULT hr = S_OK; hPreview = CreatePreviewWindow(GetModuleHandle(NULL), hwnd); if (hPreview == NULL) { goto done; } hStatus = CreateStatusBar(hwnd, IDC_STATUS_BAR); if (hStatus == NULL) { goto done; } if (FAILED(CaptureManager::CreateInstance(hwnd, &g_pEngine))) { goto done; } hr = g_pEngine->InitializeCaptureManager(hPreview, pSelectedDevice); if (FAILED(hr)) { ShowError(hwnd, IDS_ERR_SET_DEVICE, hr); goto done; } // Register for connected standy changes. This should come through the normal // WM_POWERBROADCAST messages that we're already handling below. // We also want to hook into the monitor on/off notification for AOAC (SOC) systems. g_hPowerNotify = RegisterSuspendResumeNotification((HANDLE)hwnd, DEVICE_NOTIFY_WINDOW_HANDLE); g_hPowerNotifyMonitor = RegisterPowerSettingNotification((HANDLE)hwnd, &GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE); ZeroMemory(&g_pwrCaps, sizeof(g_pwrCaps)); GetPwrCapabilities(&g_pwrCaps); UpdateUI(hwnd); fSuccess = TRUE; done: SafeRelease(&pAttributes); return fSuccess; }
/* * See https://msdn.microsoft.com/en-us/library/windows/desktop/aa373196(v=vs.85).aspx * See https://msdn.microsoft.com/en-us/library/aa383841(v=vs.85).aspx * See https://blogs.msdn.microsoft.com/oldnewthing/20060104-50/?p=32783 */ ScreenLockListenerWin::ScreenLockListenerWin(QWidget* parent) : ScreenLockListenerPrivate(parent) , QAbstractNativeEventFilter() { Q_ASSERT(parent != nullptr); // On windows, we need to register for platform specific messages and // install a message handler for them QCoreApplication::instance()->installNativeEventFilter(this); // This call requests a notification from windows when a laptop is closed HPOWERNOTIFY hPnotify = RegisterPowerSettingNotification( reinterpret_cast<HWND>(parent->winId()), &GUID_LIDSWITCH_STATE_CHANGE, DEVICE_NOTIFY_WINDOW_HANDLE); m_powerNotificationHandle = reinterpret_cast<void*>(hPnotify); // This call requests a notification for session changes if (!WTSRegisterSessionNotification(reinterpret_cast<HWND>(parent->winId()), NOTIFY_FOR_THIS_SESSION)) { } }
/// <summary> /// Registers the power status. When power setting changed, OS will notify us /// </summary> /// <param name="hWnd">The h WND.</param> VOID PowerSchemes::RegisterPowerStatus(HWND hWnd) { hNotify = RegisterPowerSettingNotification(hWnd, &GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE); hNotify = RegisterPowerSettingNotification(hWnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE); hNotify = RegisterPowerSettingNotification(hWnd, &GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE); hNotify = RegisterPowerSettingNotification(hWnd, &GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE); }