如何在console程序中捕捉windows消息,比如wm_quit等

sswweett 2006-08-23 11:43:54
如何在console程序中捕捉windows消息,比如wm_quit等
...全文
247 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sswweett 2006-08-23
  • 打赏
  • 举报
回复
我想在我的程序被误操作结束前有个选择的机会。
sswweett 2006-08-23
  • 打赏
  • 举报
回复
谢谢,结贴。不会的再问。
softrain 2006-08-23
  • 打赏
  • 举报
回复
SetConsoleCtrlHandler

The 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.


BOOL SetConsoleCtrlHandler(
PHANDLER_ROUTINE HandlerRoutine,
BOOL Add
);

Parameters
HandlerRoutine
[in] Pointer to the application-defined HandlerRoutine function to add or remove. This parameter can be NULL.
Windows Me/98/95: This parameter cannot 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.

MSDN上有例子,我就不贴了.用户关闭或者按CTRL+C,系统退出等等事件你都可以自己收到并处理.
hurryboylqs 2006-08-23
  • 打赏
  • 举报
回复
要不你就HOOK吧,那也没多大用处呀(小题大作了)
hailongchang 2006-08-23
  • 打赏
  • 举报
回复
cosole窗口和你的console程序是两码事,你是想在一个console程序中捕获对cosole窗口的操作,是不是?
forover 2006-08-23
  • 打赏
  • 举报
回复
可以告诉你无法捕获的
sswweett 2006-08-23
  • 打赏
  • 举报
回复
我只是说这个意思。消息应该都是对窗口发的吧。CONSOLE窗口如何找到?GetStdHandler?
我可以捕获WM_QUERYDESTROY(可能是吧)啊
hailongchang 2006-08-23
  • 打赏
  • 举报
回复
无法捕获WM_QUIT消息,因为当发出这个消息以后,就退出消息循环了,所以无法对这个消息做出相应的处理.

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧