在 Vista 上请求暂停,但允许其他应用程序取消
我的应用程序在完成一项冗长的任务后,使用 Win32 SetSuspendState()
API 触发系统挂起或休眠。
API 接受参数“ForceCritical”,该参数确定系统是否立即挂起,或者是否首先广播 PBT_APMQUERYSUSPEND
以允许其他应用有机会取消挂起。我的应用程序使用它来与媒体播放器等其他应用程序很好地配合,因此如果您正在听音乐或其他内容,它不会暂停。
由于某种原因,从 Vista 开始,MS 已经改变了一些事情,所以此参数被忽略,因此 SetSuspendState
立即导致挂起,其他应用程序没有机会停止它。
有谁知道我如何才能在 Vista 上再次获得所需的“礼貌”行为?
My application uses the Win32 SetSuspendState()
API to trigger system suspend or hibernation when it has finished doing a lengthy task.
The API accepts a parameter "ForceCritical" which determines whether or not the system suspends immediately or whether it broadcasts PBT_APMQUERYSUSPEND
first to allow other apps the chance to cancel the suspend. My app uses this to play nicely with other apps like Media Player, so it doesn't suspend if you're listening to music or something.
For some reason, starting with Vista, MS have changed things so this parameter is ignored so SetSuspendState
immediately causes a suspend and other applications have no opportunity to stop it.
Does anyone know how I can get the desired "polite" behaviour back again on Vista?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSDN 说
我猜测 WMP 会这样做,但旧的应用程序不会这样做。您可以通过向所有顶级窗口发送
WM_POWERBROADCAST:PBT_APMQUERYSUSPEND
消息并检查其返回值来模拟这一点(发送超时消息,以便挂起的应用程序不会挂起您的应用程序)MSDN says
I would guess that WMP does this, but older apps don't. You could probably emulate this by sending the
WM_POWERBROADCAST:PBT_APMQUERYSUSPEND
message to all top level windows and check their return values (Send the message with a timeout so a hung app does not hang your app)