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
  • 505,946
  • 29
  • 409
  • 696

1 Answers1

-4

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