Get lid status in C/C++

This is a discussion on Get lid status in C/C++ within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am looking for a way to get lid status in Windows using C/C++. I want to do certain ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    2

    Get lid status in C/C++

    Hi,

    I am looking for a way to get lid status in Windows using C/C++. I want to do certain things when the laptop's lid is down so I am trying to find an interface to read its status.
    Unfortunately I haven't found any way to do so. I have tried almost anything I have found on the web but nothing worked.

    Any Idea is more than welcome.

    Thank you in advance. :-)

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,604
    Anything like that is going to be proprietary to the board used by the laptop.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,942
    O_o

    You can't do this.

    In every operating system I know of the user can configure "what happens", the ACPI power state, when you "close the lid" on a portable device. The device may "go to sleep", "hibernate", or "power off".

    From a developer standpoint, "what happens" is simply not a realistic concern. You, as a developer, can either deal with the interruption or annoy your users when your application fails.

    Some operating systems provide an API to allow certain applications to request a "wait period" to gracefully shutdown. Others at least provide a system notification event (`WM_POWERBROADCAST') to alert applications to the interruption. One way or the other, once the operating system "switches" to such a state, the CPU is "off limits".

    It doesn't make any sense to allow a program to execute while in a "power saving" state like "sleep" and is simply impossible in a state like "power off".

    Soma

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    2
    I want to read the lid status in order to decide whether the laptop should sleep or remain powered on and do some other things. It is a special application and the default power management will be disabled (eg auto suspend).

    For example under linux, hal/udev provides info about the lid status (in most cases). In some laptop you can even read it via /proc but I coulnd't found anything similar for windows.

    How does windows know when the lid is down? I think that drivers should provide a "standard" interface to read the status.
    Last edited by thednick; 07-20-2010 at 01:23 AM.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,942
    Ah. So you don't want to know the "lid status" so much as you want to know when a "lid event" happens before the ACPI has a chance. That is a different story. It can be done, but since you've said "the default power management will be disabled" I have no intention of telling you how to do it.

    No offense, I just don't trust you. The same code could be used to do a lot of naughty things.

    Soma

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,796
    thednick, you may have good intentions, but phantomotap has a point, so in accordance with the forum guidelines, I am closing this thread.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  2. Status bar
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2005, 10:45 AM
  3. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 05:31 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21