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

解决方案 »

  1.   

    无法捕获WM_QUIT消息,因为当发出这个消息以后,就退出消息循环了,所以无法对这个消息做出相应的处理.
      

  2.   

    我只是说这个意思。消息应该都是对窗口发的吧。CONSOLE窗口如何找到?GetStdHandler?
    我可以捕获WM_QUERYDESTROY(可能是吧)啊
      

  3.   

    cosole窗口和你的console程序是两码事,你是想在一个console程序中捕获对cosole窗口的操作,是不是?
      

  4.   

    要不你就HOOK吧,那也没多大用处呀(小题大作了)
      

  5.   

    SetConsoleCtrlHandlerThe 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,系统退出等等事件你都可以自己收到并处理.