网站首页  词典首页

请输入您要查询的函数:

 

术语 setconsolectrlhandler
释义 SetConsoleCtrlHandler
语法:
C++
BOOL WINAPI SetConsoleCtrlHandler(
__in_opt PHANDLER_ROUTINE HandlerRoutine,
__in BOOL Add
);
SetConsoleCtrlHandler功能
添加或删除应用程序定义的,从处理函数的调用进程列表HandlerRoutine功能。
如果没有指定处理函数,该函数设置了继承属性,确定是否调用进程忽略CTRL + C键信号。
参数
HandlerRoutine [中,可选]
该申请的指针定义HandlerRoutine功能被添加或删除。此参数可以为NULL。
新增 [in]
如果此参数为true时,处理被添加,如果它是假的处理程序被删除。
如果HandlerRoutine参数为NULL,一个真正的价值,导致调用进程忽略CTRL + C键的输入,FALSE值恢复了正常的处理按Ctrl + C输入。这种忽视或处理按Ctrl + C的属性子进程所继承。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
此功能提供了一个控制台应用程序和服务WM_QUERYENDSESSION与消息泵图形应用程序提供了类似的通知。您也可以使用图形化应用程序,从这个功能,但没有保证会前到达从WM_QUERYENDSESSION通知。
每一个控制台进程有其自身的应用列表定义HandlerRoutine函数处理按Ctrl + C和按Ctrl + Break信号。处理程序处理的职能也由系统当用户关闭主机产生的信号,注销或关闭系统。最初,为每个进程处理清单只包含一个默认的处理函数调用ExitProcess函数。一个控制台添加或删除程序通过调用SetConsoleCtrlHandler功能,不影响其他进程处理函数列表的其他处理函数。当一个控制台进程收到任何的控制信号,它的处理功能,被称为最后的注册,第一次所谓的处理程序,直到返回TRUE一个基础。如果没有处理返回TRUE,默认的处理程序被调用。
对于控制台,按Ctrl + C和按Ctrl + Break组合键通常作为信号处理过程(CTRL_C_EVENT和CTRL_BREAK_EVENT)。当控制台键盘焦点窗口接收按Ctrl + C或按Ctrl + Break,信号通常传递给所有进程共享的控制台。
按Ctrl + Break始终被视为一个信号,但典型的CTRL + C键的行为可以用三种方式,防止被称为处理函数变化:
该SetConsoleMode功能可以禁用控制台的输入缓冲器,因此按Ctrl + C是报告为键盘输入而不是作为一个信号ENABLE_PROCESSED_INPUT模式。
调用与NULL和真参数SetConsoleCtrlHandler导致调用进程忽略CTRL + C键信号。此属性继承子进程,但它可以启用或禁用任何进程,而不会影响现有的程序。
如果一个控制台进程正在调试和Ctrl + C信号没有被禁用,系统生成一个DBG_CONTROL_C异常。这将引发异常只调试器的好处,并应用程序不应使用异常处理程序来处理。如果调试器处理异常,应用程序将不会注意到按Ctrl +荤有一个例外:可报警等待将终止。如果调试器通过对未处理的异常,按Ctrl + C是传递给控制台进程和信号处理,先前讨论。
一个控制台程序可以使用GenerateConsoleCtrlEvent函数发送了CTRL + C或Ctrl + Break信号到控制台进程组。
该系统生成CTRL_CLOSE_EVENT,CTRL_LOGOFF_EVENT,当用户关闭控制台CTRL_SHUTDOWN_EVENT信号,注销或关闭系统,使该进程有机会清理终止前了。控制台函数,或任何C运行时函数调用控制台的功能,可能无法在对前面提到的三个信号任何处理可靠。原因是部分或全部清理内部控制台程序可能已经在执行的过程中信号处理程序调用。
实例
有关示例,请参见注册一个控制处理功能。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWincon.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
控制台控制处理程序
控制台函数
PRB:ExitProcess期间
GenerateConsoleCtrlEvent
GetConsoleMode
HandlerRoutine
SetConsoleMode
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==SetConsoleCtrlHandler Function
Adds or removes an application-defined HandlerRoutine function from the list of handler functions for the calling process.
If no handler function is specified, the function sets an inheritable attribute that determines whether the calling process ignores CTRL+C signals.
Syntax
C++
BOOL WINAPI SetConsoleCtrlHandler(
__in_opt PHANDLER_ROUTINE HandlerRoutine,
__in BOOL Add
);
Parameters
HandlerRoutine [in, optional]
A pointer to the application-defined HandlerRoutine function to be added or removed. This parameter can be NULL.
Add [in]
If this parameter is TRUE, the handler is added; if it is FALSE, the handler is removed.
If the HandlerRoutine parameter is NULL, a TRUE value causes the calling process to ignore CTRL+C input, and a FALSE value restores normal processing of CTRL+C input. This attribute of ignoring or processing CTRL+C is inherited by child processes.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
Remarks
This function provides a similar notification for console application and services that WM_QUERYENDSESSION provides for graphical applications with a message pump. You could also use this function from a graphical application, but there is no guarantee it would arrive before the notification from WM_QUERYENDSESSION.
Each console process has its own list of application-defined HandlerRoutine functions that handle CTRL+C and CTRL+BREAK signals. The handler functions also handle signals generated by the system when the user closes the console, logs off, or shuts down the system. Initially, the handler list for each process contains only a default handler function that calls the ExitProcess function. A console process adds or removes additional handler functions by calling the SetConsoleCtrlHandler function, which does not affect the list of handler functions for other processes. When a console process receives any of the control signals, its handler functions are called on a last-registered, first-called basis until one of the handlers returns TRUE. If none of the handlers returns TRUE, the default handler is called.
For console processes, the CTRL+C and CTRL+BREAK key combinations are typically treated as signals (CTRL_C_EVENT and CTRL_BREAK_EVENT). When a console window with the keyboard focus receives CTRL+C or CTRL+BREAK, the signal is typically passed to all processes sharing that console.
CTRL+BREAK is always treated as a signal, but typical CTRL+C behavior can be changed in three ways that prevent the handler functions from being called:
The SetConsoleMode function can disable the ENABLE_PROCESSED_INPUT mode for a console's input buffer, so CTRL+C is reported as keyboard input rather than as a signal.
Calling SetConsoleCtrlHandler with the NULL and TRUE arguments causes the calling process to ignore CTRL+C signals. This attribute is inherited by child processes, but it can be enabled or disabled by any process without affecting existing processes.
If a console process is being debugged and CTRL+C signals have not been disabled, the system generates a DBG_CONTROL_C exception. This exception is raised only for the benefit of the debugger, and an application should never use an exception handler to deal with it. If the debugger handles the exception, an application will not notice the CTRL+C, with one exception: alertable waits will terminate. If the debugger passes the exception on unhandled, CTRL+C is passed to the console process and treated as a signal, as previously discussed.
A console process can use the GenerateConsoleCtrlEvent function to send a CTRL+C or CTRL+BREAK signal to a console process group.
The system generates CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, and CTRL_SHUTDOWN_EVENT signals when the user closes the console, logs off, or shuts down the system so that the process has an opportunity to clean up before termination. Console functions, or any C run-time functions that call console functions, may not work reliably during processing of any of the three signals mentioned previously. The reason is that some or all of the internal console cleanup routines may have been called before executing the process signal handler.
Examples
For an example, see Registering a Control Handler Function .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWincon.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Console Control Handlers
Console Functions
ExitProcess
GenerateConsoleCtrlEvent
GetConsoleMode
HandlerRoutine
SetConsoleMode
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:20:49