We help IT Professionals succeed at work.

How do you change accelerator in a MFC SDI program

artwilkes
artwilkes used Ask the Experts™
on
How can you change accelerator in a MFC SDI program.
I'm trying to use the following code.  But there is all ready an acceserator designated and the functions fails.  How do I invalidate the previous accelerator.
Or How do I call a new one?
void CMainFrame::SetAcceleratorMode(int nID)
{

  LoadAccelTable(MAKEINTRESOURCE(nID));

}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi artwilkes,

a MFC application with a main frame usually loads its accelerator table from IDR_MAINFRAME resource. Is there a reason why you need to load another one?

It's not recommended to load another accelerator table, therefore the LoadAccelTable ASSERTs.

If you really need it in a SDI application it should be possible to use this:
void CMainFrame::SetAcceleratorMode(int nID)
{
 ::DestroyAcceleratorTable(m_hAccelTable);
 m_hAccelTable = NULL;
 LoadAccelTable(MAKEINTRESOURCE(nID));
}

But never use this in MDI application or in case you anyhow implement multiple document types!

Hope that helps,

ZOPPO

Author

Commented:
Worked Great