Пример #1
0
void AccelEditor::SelChangeCommands()
{
  HWND h = GetDlgItem(IDC_COMMANDS);
  // Check if some commands exist.
  int index = SendMessage(h, LB_GETCURSEL, 0, 0);
  if (index == LB_ERR)
    return;

  WORD wIDCommand = LOWORD(SendMessage(h, LB_GETITEMDATA, index, 0));
  h = GetDlgItem(IDC_CURRENTS);
  SendMessage(h, LB_RESETCONTENT, 0, 0);

  CCmdAccelOb* pCmdAccel;
  CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);
  if (it != mgr.m_mapAccelTable.end()) {
    CAccelsOb* pAccel;
    CStdString szBuffer;
    pCmdAccel = it->second;
    it++;
    std::list<CAccelsOb*>::iterator i = pCmdAccel->m_Accels.begin();
    // Add the keys to the 'currents keys' listbox.
    while (i != pCmdAccel->m_Accels.end()) {
      pAccel = *i;
      i++;
      pAccel->GetString(szBuffer);
      index = SendMessage(h, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)szBuffer));
      // and a pointer to the accel object.
      SendMessage(h, LB_SETITEMDATA, index, (LPARAM)pAccel);
    }
  }
  // Init the key editor
//  m_pKey->ResetKey();

}
Пример #2
0
void AccelEditor::OnSelchangeCommands()
{
  // Check if some commands exist.
  int index = m_commands.GetCurSel();
  if (index == LB_ERR)
    return;

  WORD wIDCommand = LOWORD(m_commands.GetItemData(index));
  m_currents.ResetContent();

  CCmdAccelOb* pCmdAccel;

  if (mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel)) {
    CAccelsOb* pAccel;
    CString szBuffer;
    POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();

    // Add the keys to the 'currents keys' listbox.
    while (pos != NULL) {
      pAccel = pCmdAccel->m_Accels.GetNext(pos);
      pAccel->GetString(szBuffer);
      index = m_currents.AddString(szBuffer);
      // and a pointer to the accel object.
      m_currents.SetItemData(index, (DWORD_PTR)pAccel);
    }
  }
  // Init the key editor
  //  m_pKey->ResetKey();

}
//////////////////////////////////////////////////////////////////////
// In/Out to the registry
//
bool CAcceleratorManager::Load()
{
//	ASSERT(szRegKey != NULL);

//	m_hRegKey  = hRegKey;
//	m_szRegKey = szRegKey;

	DWORD data[2048/sizeof(DWORD)];

	DWORD len = sizeof(data);
	if (regQueryBinaryValue("keyboard", (char *)data, len))
	{
		int count = len/sizeof(DWORD);

		CCmdAccelOb*pCmdAccel;
		CAccelsOb*  pAccel;
		DWORD       dwIDAccelData, dwAccelData;
		BOOL        bExistID;
		int         iIndex = 0;
		if (count)
		{
			WORD     wKey;
			POSITION pos = m_mapAccelTable.GetStartPosition();

			while (pos != NULL)
			{
				m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
				pCmdAccel->DeleteUserAccels();
			}

			while (iIndex < count)
			{
				dwIDAccelData = data[iIndex++];

				WORD wIDCommand = LOWORD(dwIDAccelData);
				bExistID = m_mapAccelTable.Lookup(wIDCommand, pCmdAccel);

				if (bExistID)
				{
					pCmdAccel->DeleteUserAccels();
				}
				for (int j = 0; j < HIWORD(dwIDAccelData) && iIndex < count; j++)
				{
					dwAccelData = data[iIndex++];
					if (bExistID)
					{
						pAccel = new CAccelsOb;
						ASSERT(pAccel != NULL);
						pAccel->SetData(dwAccelData);
						pCmdAccel->Add(pAccel);
					}
				}
			}
		}
		UpdateWndTable();
		return true;
	}
	return false;
}
Пример #4
0
void AccelEditor::OnAssign()
{
	if (CheckAffected())
		return;

	// get the currently selected group
	HTREEITEM hItem = m_commands.GetSelectedItem();
	if (hItem == NULL)
		return;  // abort

	// Get the object who manage the accels list, associated to the command.
	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));

	CCmdAccelOb *pCmdAccel;
	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
		return;

	WORD wKey;
	bool bCtrl, bAlt, bShift;
	if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
		return;  // no valid key, abort

	BYTE cVirt = 0;
	if (bCtrl)
		cVirt |= FCONTROL;
	if (bAlt)
		cVirt |= FALT;
	if (bShift)
		cVirt |= FSHIFT;

	cVirt |= FVIRTKEY;

	// Create the new key...
	CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, false);
	ASSERT(pAccel != NULL);
	// ...and add in the list.
	pCmdAccel->m_Accels.AddTail(pAccel);

	// Update the listbox.
	CString szBuffer;
	pAccel->GetString(szBuffer);

	int index = m_currents.GetNextItem(-1, LVNI_SELECTED);
	if (index < 0)
		index = 0;
	m_currents.InsertItem(index, szBuffer);
	m_currents.SetItemData(index, reinterpret_cast<DWORD>(pAccel));
	m_currents.SetItemState(-1, 0, LVIS_SELECTED);	// deselect other items first
	m_currents.SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
	GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
	GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(TRUE);

	// Reset the key editor.
//	m_key.ResetKey();

	m_modified = TRUE;
	GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(TRUE);
}
//////////////////////////////////////////////////////////////////////
// In/Out to the registry
//////////////////////////////////////////////////////////////////////
//
//
bool CAcceleratorManager::Load(HKEY hRegKey, LPCTSTR szRegKey)
{
  ASSERT(szRegKey != NULL);
  HKEY hKey;

  m_hRegKey = hRegKey;
  m_szRegKey = szRegKey;

  LONG res = RegOpenKeyEx(hRegKey, szRegKey, 0L, KEY_ALL_ACCESS, &hKey);
  if(res == ERROR_SUCCESS) {
    DWORD data[2048/sizeof(DWORD)];

    DWORD dwType;
    DWORD len = sizeof(data);
    res = RegQueryValueEx(hKey, "keyboard", NULL, &dwType, 
                          (LPBYTE)data, &len);
    RegCloseKey(hKey);

    if(res == ERROR_SUCCESS) {
      int count = len/sizeof(DWORD);

      CCmdAccelOb* pCmdAccel;
      CAccelsOb* pAccel;
      DWORD dwIDAccelData, dwAccelData;

      int iIndex = 0;
      if(count) {
        while(iIndex < count) {
          dwIDAccelData = data[iIndex++];

          WORD wIDCommand = LOWORD(dwIDAccelData);
          CMapWordToCCmdAccelOb::iterator it = m_mapAccelTable.find(wIDCommand);
          bool bExistID = (it != m_mapAccelTable.end());

          if (bExistID) {
            pCmdAccel = it->second;
            pCmdAccel->DeleteUserAccels();
          }
          for (int j = 0; j < HIWORD(dwIDAccelData) && iIndex < count; j++) {
            dwAccelData = data[iIndex++];
            if (bExistID) {
              pAccel = new CAccelsOb;
              ASSERT(pAccel != NULL);
              pAccel->SetData(dwAccelData);
              pCmdAccel->Add(pAccel);
            }
          }
        }
      }
      UpdateWndTable();
      return true;
    }
    return false;
  }
  return true;
}
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;
}
void CAcceleratorManager::UpdateMenu(HMENU menu)
{
  int count = GetMenuItemCount(menu);

  MENUITEMINFO info;
  wchar_t ss[128];
  ZeroMemory(&info, sizeof(info));
  info.cbSize = sizeof(info);
  info.fMask = MIIM_ID | MIIM_SUBMENU;
  for(int i = 0; i < count; i++) {
    GetMenuItemInfo(menu, i, TRUE, &info);

    if(info.hSubMenu != NULL) {
      UpdateMenu(info.hSubMenu);
    } else {
      if(info.wID != -1) {
        MENUITEMINFOW info2;
        ZeroMemory(&info2, sizeof(info2));
        info2.cbSize = sizeof(info2);
        info2.fMask = MIIM_STRING;
        info2.dwTypeData = ss;
        info2.cch = 128;
        GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);
        CStdStringW str = ss;
        int index = str.Find('\t');
        if(index != -1)
          str = str.Left(index);

        CMapWordToCCmdAccelOb::iterator it = m_mapAccelTable.find(info.wID);

        if(it != m_mapAccelTable.end()) {
          CCmdAccelOb *o = it->second;
          if(o->m_Accels.begin() != o->m_Accels.end()) {
            std::list<CAccelsOb*>::iterator j = o->m_Accels.begin();

            CAccelsOb *accel = *j;

            CStdString s;
            accel->GetString(s);
            str += "\t";
            str += s;
          }
        }
        if(str != ss)
          ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
      }
    }
  }
}
Пример #8
0
void AccelEditor::OnTvnSelchangedCommands(NMHDR *pNMHDR, LRESULT *pResult)
{
//	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);

	// TODO: Add your control notification handler code here
	// Check if some commands exist.
	HTREEITEM hItem = m_commands.GetSelectedItem();
	if (hItem == NULL)
		return;

	m_currents.DeleteAllItems();

	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
	CCmdAccelOb *pCmdAccel;
	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel))
	{
		CAccelsOb *pAccel;
		CString	   szBuffer;
		POSITION   pos = pCmdAccel->m_Accels.GetHeadPosition();

		// Add the keys to the 'currents keys' listbox.
		while (pos != NULL)
		{
			pAccel = pCmdAccel->m_Accels.GetNext(pos);
			pAccel->GetString(szBuffer);
			int index = m_currents.InsertItem(m_currents.GetItemCount(), szBuffer);
			// and a pointer to the accel object.
			m_currents.SetItemData(index, (DWORD)pAccel);
		}

		m_currents.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
		GetDlgItem(IDC_ASSIGN)->EnableWindow(TRUE);
		m_currents.EnableWindow(TRUE);
	}
	else
	{
		GetDlgItem(IDC_ASSIGN)->EnableWindow(FALSE);
		m_currents.EnableWindow(FALSE);
	}

	// Init the key editor
//  m_pKey->ResetKey();
//	m_alreadyAffected.SetWindowText("");

	CheckListSelections();

	*pResult = 0;
}
Пример #9
0
BOOL AccelEditor::CheckAffected()
{
	m_alreadyAffected.SetWindowText("");

	WORD wKey;
	bool bCtrl, bAlt, bShift;
	if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
		return TRUE;  // no valid key, abort

	POSITION posItem = m_hItems.GetHeadPosition();
	while (posItem != NULL)
	{
		HTREEITEM hItem		  = m_hItems.GetNext(posItem);
		WORD	  wIDCommand2 = LOWORD(m_commands.GetItemData(hItem));

		CCmdAccelOb *pCmdAccel;
		m_mgr.m_mapAccelTable.Lookup(wIDCommand2, pCmdAccel);

		POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
		while (pos != NULL)
		{
			CAccelsOb *pAccel = pCmdAccel->m_Accels.GetNext(pos);
			if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift))
			{
				// the key is already affected (in the same or other command)
				// (the parts that were commented out allow for a one-to-many mapping,
				//  which is only disabled because the MFC stuff that automagically activates the commands
				//  doesn't seem to be capable of activating more than one command per accelerator...)
				m_alreadyAffected.SetWindowText(pCmdAccel->m_szCommand);
				return TRUE;
			}
		}
	}

	return FALSE;
}
void CAcceleratorManager::UpdateMenu(HMENU menu)
{
	int count = GetMenuItemCount(menu);

	OSVERSIONINFO info = {0};
	info.dwOSVersionInfoSize = sizeof(info);
	GetVersionEx(&info);

	if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
	{
		MENUITEMINFO info = {0};
		info.cbSize = sizeof(info) - sizeof(HBITMAP);
		info.fMask  = MIIM_ID | MIIM_SUBMENU;
		for (int i = 0; i < count; i++)
		{
			GetMenuItemInfo(menu, i, TRUE, &info);

			if (info.hSubMenu != NULL)
			{
				UpdateMenu(info.hSubMenu);
			}
			else
			{
				if (info.wID != (UINT)-1)
				{
					char         ss[128];
					MENUITEMINFO info2 = {0};
					info2.cbSize     = sizeof(info2) - sizeof(HBITMAP);	// FIXME: why?
					info2.fMask      = MIIM_STRING;
					info2.dwTypeData = ss;
					info2.cch        = 128;
					GetMenuItemInfo(menu, i, MF_BYPOSITION, &info2);

					CString str(ss);
					int     index = str.Find('\t');
					if (index != -1)
						str = str.Left(index);

					WORD command = info.wID;

					CCmdAccelOb *o;
					if (m_mapAccelTable.Lookup(command, o))
					{
						if (o->m_Accels.GetCount())
						{
							POSITION   pos   = o->m_Accels.GetHeadPosition();
							CAccelsOb *accel = o->m_Accels.GetNext(pos);

							CString s;
							accel->GetString(s);
							str += "\t";
							str += s;
						}
					}
					if (str != ss)
						ModifyMenu(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
				}
			}
		}
	}
	else
	{
		MENUITEMINFO info = {0};
		info.cbSize = sizeof(info);
		info.fMask  = MIIM_ID | MIIM_SUBMENU;
		for (int i = 0; i < count; i++)
		{
			GetMenuItemInfo(menu, i, TRUE, &info);

			if (info.hSubMenu != NULL)
			{
				UpdateMenu(info.hSubMenu);
			}
			else
			{
				if (info.wID != (WORD)-1)
				{
					wchar_t ss[128];
					wchar_t str[512];
					MENUITEMINFOW info2 = {0};
					info2.cbSize     = sizeof(info2);
					info2.fMask      = MIIM_STRING;
					info2.dwTypeData = ss;
					info2.cch        = 128;
					GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);

					wcscpy(str, ss);

					wchar_t *p = wcschr(str, '\t');
					if (p)
						*p = 0;

					CCmdAccelOb *o;
					WORD         command = info.wID;
					if (m_mapAccelTable.Lookup(command, o))
					{
						if (o->m_Accels.GetCount())
						{
							POSITION pos = o->m_Accels.GetHeadPosition();

							CAccelsOb *accel = o->m_Accels.GetNext(pos);

							CString s;
							accel->GetString(s);

							wchar_t temp[128];
							temp[0] = '\t';
							temp[1] = 0;
							wcscat(str, temp);
							p = temp;
							for (const char *sp = s; *sp; sp++)
								*p++ = *sp;
							*p = 0;
							wcscat(str, temp);
						}
					}
					if (wcscmp(str, ss))
						ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
				}
			}
		}
	}
}
Пример #11
0
void AccelEditor::OnAssign()
{
  // Control if it's not already affected
  CCmdAccelOb* pCmdAccel;
  CAccelsOb* pAccel;
  WORD wIDCommand;
  POSITION pos;

  WORD wKey;
  bool bCtrl, bAlt, bShift;

  if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
    return; // no valid key, abort

  int count = m_commands.GetCount();
  int index;
  for (index = 0; index < count; index++) {

    wIDCommand = LOWORD(m_commands.GetItemData(index));
    mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel);

    pos = pCmdAccel->m_Accels.GetHeadPosition();
    while (pos != NULL) {
      pAccel = pCmdAccel->m_Accels.GetNext(pos);
      if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift)) {
        // the key is already affected (in the same or other command)
        m_alreadyAffected.SetWindowText(pCmdAccel->m_szCommand);
        m_key.SetSel(0, -1);
        return; // abort
      }
    }
  }

  // OK, we can add the accel key in the currently selected group
  index = m_commands.GetCurSel();
  if (index == LB_ERR)
    return;

  // Get the object who manage the accels list, associated to the command.
  wIDCommand = LOWORD(m_commands.GetItemData(index));

  if (mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
    return;

  BYTE cVirt = 0;
  if (bCtrl)
    cVirt |= FCONTROL;
  if (bAlt)
    cVirt |= FALT;
  if (bShift)
    cVirt |= FSHIFT;

  cVirt |= FVIRTKEY;

  // Create the new key...
  pAccel = new CAccelsOb(cVirt, wKey, false);
  ASSERT(pAccel != NULL);
  // ...and add in the list.
  pCmdAccel->m_Accels.AddTail(pAccel);

  // Update the listbox.
  CString szBuffer;
  pAccel->GetString(szBuffer);

  index = m_currents.AddString(szBuffer);
  m_currents.SetItemData(index, (DWORD_PTR)pAccel);

  // Reset the key editor.
  m_key.ResetKey();
}
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;
}
Пример #13
0
void AccelEditor::Assign()
{
  // Control if it's not already affected
  CCmdAccelOb* pCmdAccel;
  CAccelsOb* pAccel;
  WORD wIDCommand;
  
  WORD wKey;
  bool bCtrl, bAlt, bShift;

  if (!m_Key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
    return; // no valid key, abort

  HWND h = GetDlgItem(IDC_COMMANDS);

  int count = ::SendMessage(h, LB_GETCOUNT, 0, 0);
  for (int index = 0; index < count; index++) {

    wIDCommand = LOWORD(::SendMessage(h, LB_GETITEMDATA, index, 0));
    CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);
    ASSERT(it != mgr.m_mapAccelTable.end());

    pCmdAccel = it->second;

    std::list<CAccelsOb*>::iterator it2 = pCmdAccel->m_Accels.begin();
    while (it2 != pCmdAccel->m_Accels.end()) {
      pAccel = *it2;
      it2++;
      if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift)) {
        // the key is already affected (in the same or other command)
        ::SetWindowText(GetDlgItem(IDC_ALREADY_AFFECTED), pCmdAccel->m_szCommand);
        ::SendMessage(m_Key, EM_SETSEL, 0, -1);
        return; // abort
      }
    }
  }

  // OK, we can add the accel key in the currently selected group
  index = ::SendMessage(h, LB_GETCURSEL, 0, 0);
  if (index == LB_ERR)
    return;

  // Get the object who manage the accels list, associated to the command.
  wIDCommand = LOWORD(::SendMessage(h, LB_GETITEMDATA, index, 0));

  CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);

  if (it == mgr.m_mapAccelTable.end())
    return;

  pCmdAccel = it->second;
  
  BYTE cVirt = 0;
  if (bCtrl)
    cVirt |= FCONTROL;
  if (bAlt)
    cVirt |= FALT;
  if (bShift)
    cVirt |= FSHIFT;

  cVirt |= FVIRTKEY;

  // Create the new key...
  pAccel = new CAccelsOb(cVirt, wKey, false);
  ASSERT(pAccel != NULL);
  // ...and add in the list.
  pCmdAccel->m_Accels.push_back(pAccel);

  // Update the listbox.
  CStdString szBuffer;
  pAccel->GetString(szBuffer);
  h = GetDlgItem(IDC_CURRENTS);

  index = ::SendMessage(h, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)szBuffer));
  ::SendMessage(h, LB_SETITEMDATA, index, (LPARAM)pAccel);

  // Reset the key editor.
  m_Key.ResetKey();

}