How to pause Windows shutdown

后端 未结 2 1774
广开言路
广开言路 2021-01-19 16:04

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 neve

2条回答
  •  遥遥无期
    2021-01-19 16:29

    You need to handle the WM_QUERYENDSESSION messsage. It's sent to each application before Windows starts the shutdown process. Do what you need quickly, because failure to respond rapidly enough causes the behavior you're observing in FireFox, which is usually a sign of a badly designed app (and the user may terminate it before you get a chance to finish).

    interface
    
    ...
    
    type
      TForm1 = class(TForm)
        procedure WMQueryEndSession(var Msg: TWMQueryEndSession);
          message WM_QUERYENDSESSION;
      end;
    
    implementation
    
    procedure TForm1.WMQueryEndSession(var Msg: TWMQueryEndSession);
    begin
      // Do what you need to do (quickly!) before closing
      Msg.Result := True; 
    end;
    

    (Just as an aside: The enabling/disabling of sounds is a per-user setting, and you should have a very good need for interfering with the user's choice. If I were you, I'd make sure my uninstaller was well-tested, because any app that interfered with my sound preferences this way would be removed from my system very quickly.)

提交回复
热议问题