1,我现在启动进程“A”,那么在windows任务栏将出现一个“A”的按钮;
2,我又启动进程“B”,那么在windows任务栏就又有一个“B”的按钮;
3,我在windows任务栏中先点击“A”进程,紧接着点击“B”进程。
问题是,如何在“B”进程中获取上述动作,换句话说动作3会给进程“B”发什么消息呢?个人觉得另一种表述可以是“进程如何获取自己在windows任务栏上的状态,如何响应它在windows任务栏上的状态变化?”如果有人说是SYSCOMMAND,那么我已经试过了,似乎它只是对单个进程的状态的变化响应。我的问题是在多个进程中的切换状态。请大拿指教。

解决方案 »

  1.   

    多个进程,那你需要用到HOOK了.关于HOOK, 随便搜索一下,在CSDN里已经被讨论的很烂了.
      

  2.   

    系统托盘,窗口消息 TRAY_NOTIFY
      

  3.   

    同意3楼。在WM_ACTIVE的wParam参数里能判断是何种方式激活本窗口的。
      

  4.   

    又看了一遍题目,觉得楼主想要解决的问题,似乎与多个进程切换无关."进程如何获取自己在windows任务栏上的状态,如何响应它在windows任务栏上的状态变化?"如果是这样,只是想得到这个.同意四楼.
      

  5.   

    看到了大家的回复,首先感谢大家。
    wawaku:我这个应该是和多进程无关的,我只是想监控一种程序的操作,并对其做出反应。
             其实就是想知道用户在windows任务栏不断点击不同的按钮时,什么时候我的程序被点击激活。不知道说清楚了没有。
             而且我用SPY++看过,没有发现什么特殊的消息被发送给我的程序。
    chenyu2202863:WM_MOUSEACTIVATE似乎没有效果,我打了断点,但进不去。
    Mackz:WM_ACTIVATE是可以响应的,但WM_ACTIVATE似乎在操作中不止一个,这样就需要用到其参数来判断了。目前我正在测试是否可行,先谢谢了。一伙我再更新回复。
      

  6.   

    ReMackz:WM_ACTIVATE消息后的状态nState为WA_ACTIVE时可以响应,但好像不稳定,因为WA_ACTIVE的意思是The window is being activated through some method other than a mouse click,所以发生条件没法收敛。这样就带来了风险。我的想法是,微软应该对它的taskbar有一个管理机制,但是否这个管理机制会与各个app有专门的消息互动,或者给出接口让我们去监控taskbar的状态变化,这样我就可以实时的对这个行为做出处理了。如果只是单对本身app进行监控的话,我的感觉是不太可能实现。
      

  7.   

    The WM_ACTIVATE message is sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately. SyntaxWM_ACTIVATE    WPARAM wParam
        LPARAM lParam;
        
    ParameterswParam
    The low-order word specifies whether the window is being activated or deactivated. This parameter can be one of the following values. The high-order word specifies the minimized state of the window being activated or deactivated. A nonzero value indicates the window is minimized. 
    WA_ACTIVE
    Activated by some method other than a mouse click (for example, by a call to the SetActiveWindow function or by use of the keyboard interface to select the window).
    WA_CLICKACTIVE
    Activated by a mouse click.
    WA_INACTIVE
    Deactivated.
    lParam
    Handle to the window being activated or deactivated, depending on the value of the wParam parameter. If the low-order word of wParam is WA_INACTIVE, lParam is the handle to the window being activated. If the low-order word of wParam is WA_ACTIVE or WA_CLICKACTIVE, lParam is the handle to the window being deactivated. This handle can be NULL. 
    Return ValueIf an application processes this message, it should return zero. 
    ResIf the window is being activated and is not minimized, the DefWindowProc function sets the keyboard focus to the window. If the window is activated by a mouse click, it also receives a WM_MOUSEACTIVATE message. 
      

  8.   

    你想要的应该是这个吧.
    LRESULT CDialogTestDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {

    if((message == WM_ACTIVATE))&&(wParam == WA_ACTIVE))
    {
                //your code
    } return CDialog::DefWindowProc(message, wParam, lParam);
    }
      

  9.   

    ReMackz:WM_ACTIVATE消息后的状态nState为WA_ACTIVE时可以响应,但好像不稳定,因为WA_ACTIVE的意思是The   window   is   being   activated   through   some   method   other   than   a   mouse   click,所以发生条件没法收敛。这样就带来了风险。我的想法是,微软应该对它的taskbar有一个管理机制,但是否这个管理机制会与各个app有专门的消息互动,或者给出接口让我们去监控taskbar的状态变化,这样我就可以实时的对这个行为做出处理了。如果只是单对本身app进行监控的话,我的感觉是不太可能实现。
    =====================================================================建议应该去多看一些MFC消息机制的书. DefWindowProc就是用来处理这些消息的.
      

  10.   

    hehe,有道理,不过还是不能满足我的要求。目前已经向头们申请暂停这个改善了。
    因为我只要我说的这种情况的响应,别的情况不会触发我的代码。
    还是谢谢了。
      

  11.   

    汗,我测试了一下WM_ACTIVATE的WA_ACTIVE...很奇怪诶.
    我写了一个很简单的Dialog,如果遇到WA_ACTIVE就弹出一个MessageBox,其它什么内容也没有.
    发现在这个Dialog出现之前,MessageBox弹出了4次,出现之后无论我怎么切换,切到其他窗口再切回来,WA_ACTIVE都没有出现过了...