我想实现以下功能,用鼠标单击一个按钮执行A段代码,当按住键盘的ctrl键再单击此按钮执行B段代码。
请问各位大侠怎么做?最好能提供一个例子
[email protected]
多谢了

解决方案 »

  1.   

    void CTestDlg::OnButton1() 
    {
    BOOL bCtrlKeyDown = GetKeyState (VK_CONTROL) < 0; if (bCtrlKeyDown)
    {
    AfxMessageBox("Ctrl Press down");
    }
    else
    {
    AfxMessageBox("Ctrl Press no down");
    }

    }
      

  2.   

    继承一个cbutton类
    然后影射函数
    OnLButtonUp( UINT nFlags, CPoint point )
    当 nFlags & MK_CONTROL != 0 的时候,就表示同时按下了ctrl
      

  3.   

    判断按键状态
    SHORT GetKeyState(
      int nVirtKey   // virtual-key code
    );
      

  4.   

    GetKeyState(VK_LCONTROL)返回的东西不一样。区分这个直就可以了。
      

  5.   

    重载OnLButtonDown函数,GetKeyState判断Ctrl按键信息。实现分支。
      

  6.   

    newzk(zk) 的方法不错!
    void CTestDlg::OnButton1() 
    {
    BOOL bCtrlKeyDown = GetKeyState (VK_CONTROL) < 0; if (bCtrlKeyDown)
    {
    AfxMessageBox("Ctrl Press down");
    }
    else
    {
    AfxMessageBox("Ctrl Press no down");
    }

    }
      

  7.   

    void CTestDlg::OnButton1() 
    {
    BOOL bKeyStat = FALSE; if (!bKeyStat )
    {
    AfxMessageBox("Ctrl Press down");
    }
    else
    {
    AfxMessageBox("Ctrl Press no down");
    }
    bKeyStat =!bKeyStat ;}
      

  8.   

    上面的有错误,下面修正
    static BOOL bKeyStat = FALSE;

    if (!bKeyStat )
    {
    AfxMessageBox("111111");
    }
    else
    {
    AfxMessageBox("222222");
    }
    bKeyStat =!bKeyStat ;