////////////////////////////////////////////////////////////////////// // Update the application's ACCELs table // bool CAcceleratorManager::UpdateWndTable() { int iLoop = 0; CTypedPtrArray<CPtrArray, LPACCEL> arrayACCEL; CCmdAccelOb*pCmdAccel; WORD wKey; LPACCEL pACCEL; CAccelsOb* pAccelOb; POSITION pos = m_mapAccelTable.GetStartPosition(); while (pos != NULL) { m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); while (pos != NULL) { pAccelOb = pCmdAccel->m_Accels.GetNext(pos); pACCEL = new ACCEL; ASSERT(pACCEL != NULL); pACCEL->fVirt = pAccelOb->m_cVirt; pACCEL->key = pAccelOb->m_wKey; pACCEL->cmd = pCmdAccel->m_wIDCommand; arrayACCEL.Add(pACCEL); } } int nAccel = arrayACCEL.GetSize(); LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, nAccel * sizeof(ACCEL)); if (!lpAccel) { for (iLoop = 0; iLoop < nAccel; iLoop++) delete arrayACCEL.GetAt(iLoop); arrayACCEL.RemoveAll(); return false; } for (iLoop = 0; iLoop < nAccel; iLoop++) { pACCEL = arrayACCEL.GetAt(iLoop); lpAccel[iLoop].fVirt = pACCEL->fVirt; lpAccel[iLoop].key = pACCEL->key; lpAccel[iLoop].cmd = pACCEL->cmd; delete pACCEL; } arrayACCEL.RemoveAll(); HACCEL hNewTable = CreateAcceleratorTable(lpAccel, nAccel); if (!hNewTable) { ::LocalFree(lpAccel); return false; } HACCEL hOldTable = theApp.hAccel; if (!::DestroyAcceleratorTable(hOldTable)) { ::LocalFree(lpAccel); return false; } theApp.hAccel = hNewTable; ::LocalFree(lpAccel); UpdateMenu(GetMenu(*AfxGetApp()->m_pMainWnd)); return true; }