如何暂停Windows关机

如何暂停Windows关机

本文介绍了如何暂停Windows关机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在启动和关闭时将声卡静音/取消静音。



我已经找到一些代码来做这些工作,关机,声音从不被静音。



有人可以告诉我如何暂停关机足够长的时间让我的应用程序静音?我可以使用一个简单的TTimer来暂停应用程序足够长的时间来运行静音,然后让Windows关闭。



如何让Windows等待但是我注意到,如果我在Firefox上运行并尝试关机,Windows会停止一个消息,这些程序正在阻止Windows关闭...,需要一个单击以强制关闭Firefox。

解决方案

由于Windows Vista,如果您使用操作系统注册关机原因字符串,或者如果您的应用程序顶级窗口,操作系统将无限期地等待您的程序从 WM_QUERYENDSESSION 返回,同时显示阻止应用程序屏幕,或者直到用户选择强制结束程序。



以下示例代码模拟45秒等待,睡眠。在等待的前五秒,操作系统等待耐心等待,只有这样才能显示全屏UI。立即显示屏幕的唯一方法是立即从 WM_QUERYENDSESSION 返回false。但是在这种情况下,您将无法恢复关机。



有关Vista及更高版本操作系统关闭行为的详细信息,请参阅。

  type 
TForm1 = class(TForm)
..
protected
procedure WMQueryEndSession(var Message:TWMQueryEndSession);
message WM_QUERYENDSESSION;
..

...

函数ShutdownBlockReasonCreate(hWnd:HWND;原因:LPCWSTR):Bool;
stdcall;外部用户32;
函数ShutdownBlockReasonDestroy(hWnd:HWND):Bool;标准外部用户32;


程序TForm1.WMQueryEndSession(var Message:TWMQueryEndSession);
const
ENDSESSION_CRITICAL = $ 40000000;
begin
Message.Result:= LRESULT(True);
if((Message.Unused and ENDSESSION_CRITICAL)= 0)then begin
ShutdownBlockReasonCreate(Handle,'wait wait while static ...');

睡眠(45000); //在这里做你的工作

ShutdownBlockReasonDestroy(Handle);
结束
结束


I need to mute/un-mute the sound card at startup and shutdown.

I have found some code to do the work, but often Windows slams through the shutdown and the sound never gets muted.

Can someone please tell me how to pause the shutdown long enough for my app to mute the sound? I can use a simple TTimer to pause the app long enough for it to run the muting and then let Windows get on with shutting down.

How do I tell Windows to wait though?

I notice that if I leave Firefox running and try to shutdown, Windows stops with a message, "These programs are preventing windows closing..." and needs a click to force Firefox to close. I need to find that.

解决方案

Since Windows Vista, if you register a shutdown reason string with the OS or if your application has a top level window, the OS will wait indefinitely for your program to return from WM_QUERYENDSESSION while displaying the blocking applications screen - or until the user chooses to forcefully end the program of course.

The below sample code simulates a 45 seconds wait with Sleep. In the first five seconds of the wait the OS waits patiently, only then it displays the full screen UI. The only way to show the screen immediately is to immediately return false from WM_QUERYENDSESSION. But in this case you won't be able to resume shutdown.

For details on shutdown behavior of the OS for Vista and later, see documentation.

type
  TForm1 = class(TForm)
    ..
  protected
    procedure WMQueryEndSession(var Message: TWMQueryEndSession);
      message WM_QUERYENDSESSION;
    ..

...

function ShutdownBlockReasonCreate(hWnd: HWND; Reason: LPCWSTR): Bool;
    stdcall; external user32;
function ShutdownBlockReasonDestroy(hWnd: HWND): Bool; stdcall; external user32;


procedure TForm1.WMQueryEndSession(var Message: TWMQueryEndSession);
const
  ENDSESSION_CRITICAL = $40000000;
begin
  Message.Result := LRESULT(True);
  if ((Message.Unused and ENDSESSION_CRITICAL) = 0) then begin
    ShutdownBlockReasonCreate(Handle, 'please wait while muting...');

    Sleep(45000); // do your work here

    ShutdownBlockReasonDestroy(Handle);
  end;
end;

这篇关于如何暂停Windows关机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:59