获取当前笔记本合盖状态 [英] Get current laptop lid state

查看:475
本文介绍了获取当前笔记本合盖状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个C#应用程序(特别是笔记本电脑),我想知道盖的状态下,即当它是开放的,什么时候结束。

I'm writing a C# app (specifically for laptops) and I want to be aware of the state of the lid, i.e. when is it open and when is it closed.

我已经使用的PInvoke一起的微软与 href=\"http://stackoverflow.com/questions/3355606/detect-laptop-lid-closure-and-opening\">这个苏答案

I've already used pInvoke along with Microsoft's RegisterPowerSettingNotification function with the help of this SO answer.

所以,用我知道当盖子被关闭或打开,并且知道它的状态,
,而上面我想要得到的状态别的前盖仍在继续。
我已经注意到,即使是在盖子没有改变,回调函数被调用,我可以检查它的参数就知道了盖的状态,但是这不是为我好,因为它是一个事件,我可以'T只是等待它发生(也许有另一种方式来解决此问题?)。

So, with the above I know when the lid is being closed or opened and know its state, BUT I want to get the state of the lid before anything else continues. I've noticed that even if there is no change to the lid, the callback function is called and I can check its parameter to know the lid's state, but this not good for me since it is an event and I can't simply wait for it to occur (maybe there's another way to work around this?).

我也试过PowerEnumerate功能,但无法从它的东西(也许有些事情我不知道有没有可能有所帮助)

I've also tried PowerEnumerate function but couldn't get something from it (maybe there is something I don't know there that could help)

编辑1:
我不能等待或延迟的应用程序,并且有要求我拿到国家没有CB 2的问题,第一个是,盖能而笔记本电脑连接到监视器从而允许使用笔记本电脑上的用户关闭。如果用户在这种情况下,启动该应用它不应该开始。
中的第二个原因是我想要的应用程序是用户友好的,并通知其启动或停止时会发生什么,如果我在错误的时间CB它可能被忽略,因为应用程序的内在逻辑,然后将不得不等待下一次我得到了CB,直到,我会的。

EDIT 1: I can't wait or delay the app, and there are 2 issues that require me to get the state without a CB, the first is that a lid can be closed while the laptop is connected to a monitor thus allowing the user to use the laptop. If the user starts the app in this situation it should not start. The second reason is that I want the app to be user friendly and notify what happens when it starts or stops, and if I get the cb in the wrong time it might be ignored, due to the app's inner logic, and then will have to wait until the next time I get a cb, I'd at all.

所以,(没有双关语意)
是有没有办法得到这个信息了?

So, (no pun intended) Is there a way to get this information right away?

编辑2:
似乎从评论说,目前还不清楚我需要什么。我需要一种方法来查询到盖的状态。即 - 调用一些API或东西,返回值是状态。
感谢

EDIT 2: It seems from comments that it's not clear what I need. I need a way to query to state of the lid. i.e. - call some API or something and that the return value is the state. thanks!

关键词:GUID_LIDSWITCH_STATE_CHANGE,WM_POWERBROADCAST,电源设置

Keywords: GUID_LIDSWITCH_STATE_CHANGE , WM_POWERBROADCAST, Power Setting

推荐答案

因此,通过@ Llwyd的回答导致长期搜索后,我找到了解决办法。
口注意到,当该盖关闭时,装置从设备管理器中删除,因此该解决方案是检查它是否有或没有。
背后的代码是有点庞大这里上传的,所以我不会,但下面是需要:
1)确定内部屏幕的name\ID与 WmiMonitorConnectionParams VideoOutputTechnology 和状态( DISPLAY_DEVICE_ATTACHED 和/或 DISPLAY_DEVICE_ACTIVE
2)一旦我知道该设备的名称/ ID我可以很容易地看看它通过枚举System.Windows.Forms.Screen.AllScreens(或保存从DISPLAY_DEVICE_ATTACHED值)

So after a long search led by @Llwyd's answer, I found a solution. I noticed that when the lid is closed the device is removed from the device manager, so the solution is to check whether it is there or not. The code behind it is a bit massive to upload here so I won't, but the following was need: 1) Identify Internal screen's name\ID with WmiMonitorConnectionParams and VideoOutputTechnology and state (DISPLAY_DEVICE_ATTACHED and/or DISPLAY_DEVICE_ACTIVE) 2) Once I know the device's name/ID I can easily look it up by enumerating System.Windows.Forms.Screen.AllScreens (or save the value from the DISPLAY_DEVICE_ATTACHED)

这篇关于获取当前笔记本合盖状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆