1

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.

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

1 Answers1

-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++.

  • 1
    That 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