散分,前十楼每人十分
-----
动态修改加速键代码如下:
bool AlterAcceleratorTable
(
    LPACCEL paccelBase
    , const int nItemsAlready
    , const int nItemsBuffer
    , int &nItemsGood
)
{
  if (nItemsBuffer < nItemsAlready+1)
     return false;
  nItemsGood    = nItemsAlready;  //Ctrl+Q is set to  ID_FILE_PRINT_SETUP 
  paccelBase[nItemsGood].cmd    = ID_FILE_PRINT_SETUP;
  paccelBase[nItemsGood].fVirt  = FCONTROL |FVIRTKEY|FNOINVERT;
  paccelBase[nItemsGood].key    = 'Q';
  nItemsGood++;  return true;
}BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
  static bool s_bAccelAlted = false;
  if (!s_bAccelAlted  &&  NULL!=m_hAccelTable)
  {
    const int  nMaxCountAccel = 500;//set to be large enough. 
    ACCEL      paccBuffer[nMaxCountAccel];    int        nItemsRaw, nItem;
    nItemsRaw  = ::CopyAcceleratorTable (m_hAccelTable, NULL, NULL);
    nItem      = ::CopyAcceleratorTable (m_hAccelTable, &paccBuffer[0], nMaxCountAccel);
    if (    nItemsRaw==nItem
       &&  AlterAcceleratorTable(&paccBuffer[0], nItemsRaw, nMaxCountAccel, nItem)
       )
    {
       //bad implementation of AlterAcceleratorTable(). 
       ASSERT (nItem>0  &&  nItem<nMaxCountAccel);       HACCEL haccTemp = ::CreateAcceleratorTable (paccBuffer, nItem);
       if (NULL != haccTemp)
       {
         DestroyAcceleratorTable (m_hAccelTable);
         m_hAccelTable    = haccTemp;
         s_bAccelAlted    = true;
       }
     }
  }  return CMDIFrameWnd::PreTranslateMessage(pMsg);
}