如何在程序中发送一个组合键,如:ALT+F4?

解决方案 »

  1.   

    SendMessage   WM_CLOSE就可以了啊
    为什么非要发送ALT+F4呢
      

  2.   

    不知道是否是你需要,可以设置一个快接键,ALT + F4就OK了
      

  3.   

    可以通过发送WM_SYSKEYDOWN或者WM_SYSKEYUP来实现
    The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the alt key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lKeyData parameter. WM_SYSKEYDOWN 
    nVirtKey = (int) wParam;    // virtual-key code 
    lKeyData = lParam;          // key data 
     
      

  4.   

    无论关哪个进程,都用WM_CLOSE如果要用ALT+F4,用热键就可以了
      

  5.   

    如果你要发送一个热键,就用SendMessage()如果是自己的程序要用热键,就用HOTKEY控件。。
      

  6.   

    ALT+F4只是个比方,我是要给系统发一个任意的组合键。
      

  7.   

    ALT+F4:
    BOOL CTestDlgDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F4)
    {
    if(GetKeyState(VK_ALT) < 0)
    AfxMessageBox("ALT+F4");
    }
    return CDialog::PreTranslateMessage(pMsg);
    }
      

  8.   

    OnInitDialog()
    RegisterHotKey(m_hWnd,0Xa002,MOD_ALT,VK_F4);
    ::SetFocus(m_hWnd);***********************************************************
    BOOL CMySysHotKeyDlg::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if (pMsg->message==WM_HOTKEY && pMsg->wParam==0Xa002)
    {
    AfxMessageBox("My MessageBox!");
    }
    return CDialog::PreTranslateMessage(pMsg);
    }******************************************************************LRESULT CMySysHotKeyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(message == WM_CLOSE)
    {
    ::UnregisterHotKey(m_hWnd,0Xa002);
    }
    return CDialog::WindowProc(message, wParam, lParam);
    }