函数参考


_WinAPI_ShutdownBlockReasonQuery

获取由_WinAPI_ShutdownBlockReasonCreate()函数创建的原因字符串

#Include <WinAPIEx.au3>
_WinAPI_ShutdownBlockReasonQuery ( $hWnd )

参数

$hWnd 应用程序主窗口句柄

返回值

成功: 返回原因字符串
失败: 返回空字符串并设置@error非0

注意/说明

函数只能被由$hWnd参数指定的窗口创建的线程所调用,
否则, 函数失败且错误代码为ERROR_ACCESS_DENIED (5).

最低系统要求: Windows Vista.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <ButtonConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

If _WinAPI_GetVersion() < '6.0' Then
    MsgBox(16, 'Error', 'Require Windows Vista or later.')
    Exit
EndIf

Global $hForm, $Msg, $Button, $Check

$hForm = GUICreate('MyGUI', 200, 200)
$Button = GUICtrlCreateButton('', 73, 62, 54, 54, $BS_ICON)
GUICtrlSetImage(-1, @SystemDir & '\shell32.dll', 45)
GUICtrlSetTip(-1, 'Log off ' & @UserName)
$Check = GUICtrlCreateCheckBox('Block Windows shutdown', 10, 173, 144, 21)
GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION')
GUISetState()

; 为当前进程设置最高的关闭优先级以防止终止其他进程.
_WinAPI_SetProcessShutdownParameters(0x03FF)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button
            Shutdown(0)
        Case $Check
            If GUICtrlRead($Check) = $GUI_CHECKED Then
                _WinAPI_ShutdownBlockReasonCreate($hForm, 'This application is blocking system shutdown because the saving critical data is in progress.')
            Else
                _WinAPI_ShutdownBlockReasonDestroy($hForm)
            EndIf
    EndSwitch
WEnd

Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case $hForm
            If _WinAPI_ShutdownBlockReasonQuery($hForm) Then
                Return 0
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_QUERYENDSESSION