I'm writing a C++ app, and I want to get the current lid state of the laptop.
Note: not catch an event of the lid state changing, but once main()
is executed, get the current lid state.
Asked
Active
Viewed 267 times
1

Remy Lebeau
- 555,201
- 31
- 458
- 770

Hrach Martirosyan
- 11
- 2
-
1FYI: [SO: Get current laptop lid state](https://stackoverflow.com/q/26869987/7478597) – Scheff's Cat Nov 04 '21 at 18:32
1 Answers
-3
The implementation how to get lid state by C#. https://github.com/rowandh/lidstatusservice
I think that shouldn't be problematic to translate the code to C++.

Narek Aydinyan
- 195
- 10
-
1That solution is not querying the current lid status. It is launching a background service that calls `RegisterPowerSettingNotification()` to receive `PBT_POWERSETTINGCHANGE` notifications looking for `GUID_LIDSWITCH_STATE_CHANGE` events: "*The state of the lid has changed (open or closed).*" The OP stated they did not want to handle events. – Remy Lebeau Nov 04 '21 at 23:00
-
@RemyLebeau With all respect, docs says - "Immediately after registration, the callback will be invoked with the current value of the power setting.". I. e. it is possible to get the current setting value with RegisterPowerSettingNotification. – n0ne Sep 07 '22 at 12:41
-
@n0ne still doesn't change the fact that the OP didn't want to handle events just to get the value – Remy Lebeau Sep 07 '22 at 15:03