bool CAcceleratorManager::Write() { CDWordArray AccelsDatasArray; CDWordArray CmdDatasArray; int iCount = 0; CCmdAccelOb*pCmdAccel; CAccelsOb* pAccel; DWORD dwAccelData; WORD wKey; POSITION pos = m_mapAccelTable.GetStartPosition(); while (pos != NULL) { m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); CmdDatasArray.RemoveAll(); POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); while (pos != NULL) { pAccel = pCmdAccel->m_Accels.GetNext(pos); // if (!pAccel->m_bLocked) { dwAccelData = pAccel->GetData(); CmdDatasArray.Add(dwAccelData); // } } if (CmdDatasArray.GetSize() > 0) { CmdDatasArray.InsertAt(0, MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.GetSize())); AccelsDatasArray.Append(CmdDatasArray); iCount++; } } // AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount)); int count = AccelsDatasArray.GetSize(); DWORD *data = (DWORD *)malloc(count * sizeof(DWORD)); ASSERT(data != NULL); for (int index = 0; index < count; index++) data[index] = AccelsDatasArray[index]; regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD)); AccelsDatasArray.RemoveAll(); CmdDatasArray.RemoveAll(); free(data); return true; }
bool CAcceleratorManager::Write() { std::vector<DWORD> AccelsDatasArray; std::vector<DWORD> CmdDatasArray; int iCount = 0; CCmdAccelOb* pCmdAccel; CAccelsOb* pAccel; DWORD dwAccelData; WORD wKey; CMapWordToCCmdAccelOb::iterator it = m_mapAccelTable.begin(); while (it != m_mapAccelTable.end()) { wKey = it->first; pCmdAccel = it->second; CmdDatasArray.clear(); std::list<CAccelsOb*>::iterator it2 = pCmdAccel->m_Accels.begin(); while (it2 != pCmdAccel->m_Accels.end()) { pAccel = *it2; // if (!pAccel->m_bLocked) { dwAccelData = pAccel->GetData(); CmdDatasArray.push_back(dwAccelData); //} it2++; } if (CmdDatasArray.size() > 0) { CmdDatasArray.insert(CmdDatasArray.begin(), MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.size())); AccelsDatasArray.insert(AccelsDatasArray.end(), CmdDatasArray.begin(), CmdDatasArray.end()); iCount++; } it++; } // AccelsDatasArray.insert(AccelsDataArray.begin(), MAKELONG(65535, iCount)); int count = AccelsDatasArray.size(); DWORD *data = (DWORD *)malloc(count * sizeof(DWORD)); ASSERT(data != NULL); std::vector<DWORD>::iterator it3 = AccelsDatasArray.begin(); int index = 0; while(it3 != AccelsDatasArray.end()) { data[index] = AccelsDatasArray[index]; index++; it3++; } HKEY hKey; LONG res = RegCreateKeyEx(m_hRegKey, m_szRegKey, 0L,"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if(res == ERROR_SUCCESS) { res = RegSetValueEx(hKey, "keyboard", 0L, REG_BINARY, (CONST BYTE *)data, count * sizeof(DWORD)); RegCloseKey(hKey); } AccelsDatasArray.clear(); CmdDatasArray.clear(); free(data); if (res == ERROR_SUCCESS) return true; else return false; }