How to pause Windows

I need to disable / disable the sound card at startup and shutdown.

I found code to do this work, but often Windows shuts down and the sound never mutes.

Can someone please tell me how to pause the shutdown long enough for my application to mute? I can use simple TTimer to pause the application long enough so that it can start the shutdown, and then let Windows shut down.

How to tell Windows to wait?

I notice that if I leave Firefox running and try to shut down, Windows will stop reporting: "These programs prevent windows from closing ..." and it takes a click to force Firefox to close. I need to find this.

+3
source share
2 answers

Starting with Windows Vista, if you register a reason line for WM_QUERYENDSESSION OS, or if your application has a top-level window, the OS will wait indefinitely for your program to return with WM_QUERYENDSESSION when the lock applications screen is displayed - or until the user decides, of course finish the program.

Below is an example code simulating 45 seconds of sleep using Sleep . In the first five seconds of waiting, the operating system waits patiently, only then displays a full-screen interface. The only way to immediately display the screen is to immediately return false from WM_QUERYENDSESSION . But in this case, you cannot resume the shutdown.

For more information about disabling the OS for Vista and later, see the 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; 
+5
source

You need to handle the WM_QUERYENDSESSION handle. It is sent to each application before Windows starts the shutdown process. Do what you need to quickly, because the inability to respond fast enough causes the behavior that you observe in FireFox, which is usually a sign of a poorly designed application (and the user can complete it before you get the opportunity 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; 

(As well as an aside: turning on / off sounds is a setting for each user, and you should have a very good need for interfering with the user choice. If I were you, I would make sure that my uninstaller was well tested, because any application that interfered with my sound settings in this way would be deleted very quickly from my system.)

+3
source

Source: https://habr.com/ru/post/1201276/


All Articles