代码之家  ›  专栏  ›  技术社区  ›  Fábio

禁用MFC中的加速器表项

  •  6
  • Fábio  · 技术社区  · 15 年前

    当输入焦点在CEdit字段上时,我需要暂时禁用加速器表中的一些项。

    我的应用程序有一些与键盘键(A、S、D等)相关联的命令,当用户在字段中输入文本时,我需要禁用这些命令。

    2 回复  |  直到 9 年前
        2
  •  1
  •   Fabian    13 年前

    // Allocate the accelerator buffer
    HACCEL hAccelOld = LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACC_TECONTROL));
    int iNumAccelerators = CopyAcceleratorTable(hAccelOld, NULL, 0);   
    ACCEL *pAccels = new ACCEL[iNumAccelerators];
    
    // Copy the current table to the buffer
    VERIFY(CopyAcceleratorTable(hAccelOld, pAccels, iNumAccelerators) == iNumAccelerators);
    
    // Modify the pAccels array as required
    ...
    
    // Destroy the current table resource...
    VERIFY(DestroyAcceleratorTable(hAccelOld) == TRUE);
    
    // ... create a new one, based on our modified table
    m_hTerAcceleratorTable = CreateAcceleratorTable(pAccels, iNumAccelerators); 
    ASSERT(m_hTerAcceleratorTable != NULL);
    
    // Cleanup
    delete[] pAccels;
    
    推荐文章