locked
a question about Bind a Command to a Single Shortcut Key RRS feed

  • Question

  •           I want to Bind a Command to a Single Shortcut Key  .I have read the article:

    How to: Bind a Command to a Single Shortcut Key

            the code like this:

    public void OnConnection(object application, ext_ConnectMode 
    connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;
        BindingsExample(_applicationObject);
    
    }
    
    public void BindingsExample(DTE2 dte)
    {
        Commands cmds;
        Command cmd;
    
        try
        {
            // Set references to the Commands collection and the 
            // File.NewFile command.
            cmds = dte.Commands;
            cmd = cmds.Item("File.NewFile", 1);
    
            // Assigns the command (File.NewFile) globally to the F2 key.
            cmd.Bindings = "Global::F2";
            System.Windows.Forms.MessageBox.Show("key remapped");
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show(ex.Message);
        }
    }
    


              but i donot use C# or VB, I use Visual C++ ATL,  my code as follow:

    CComPtr<Command> pCreatedCommand;
    // create the command
    ......
    
    //Bind the Command to a Single Shortcut Key  
    
    HRESULT hr = pCreatedCommand->put_Bindings(CComVariant(_T("Global::F6")));
    


      but the return value is E_INVALIDARG.  i change the into:

    HRESULT hr = pCreatedCommand->put_Bindings(CComVariant(_T("Global::CTRL+ALT+SHIFT+7")));

         but the return value still is E_INVALIDARG.

    My dev env :   WinXP+ sp3,  Visual Studio 2005 Simplified Chinese Editon + sp1, MultiByte set ,   Visual C++ ATL

     

     

     

     

     

     

     


    前无古人,后无来者
    Friday, October 7, 2011 5:18 AM

Answers