自己编写一个程序,在该程序中,有个按钮,点击按钮后,发送ctrl+W给VC程序,热键激活MFC ClassWizard。
怎么发送ctrl键啊?

解决方案 »

  1.   

    WM_SYSCHAR
    The WM_SYSCHAR message is posted to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. It specifies the character code of a system character key — that is, a character key that is pressed while the ALT key is down. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      UINT uMsg,       // WM_SYSCHAR
      WPARAM wParam,   // character code (TCHAR)
      LPARAM lParam    // key data
    );
    Parameters
    wParam 
    Specifies the character code of the window menu key. 
    lParam 
    Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Meaning 
    0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke was auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. 
    16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM). 
    24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 
    25–28 Reserved; do not use. 
    29 Specifies the context code. The value is 1 if the ALT key is held down while the key is pressed; otherwise, the value is 0. 
    30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up. 
    31 Specifies the transition state. The value is 1 if the key is being released, or it is 0 if the key is being pressed. 
      

  2.   

    keybd_event( VK_CONTROL,0,0,0 );
     ::SendMessage( hWnd, WM_KEYDOWN, 'W',0);
      

  3.   

    keybd_event( VK_CONTROL,0,0,0 );
     ::SendMessage( hWnd, WM_KEYDOWN, 'W',0); 
    Sleep (30);
    ::SendMessage( hEditWnd, WM_KEYUP, 'W',0);
      keybd_event( VK_CONTROL,0,KEYEVENTF_KEYUP,0 );