From: Paul on
Thank you. Thank you. Thank you.

I was having a problem ADDING an accelerator key. It was as if I was being ignored. Same root cause however, my changes to the accelerator were being overwritten at run time by stored registry settings. Delete the registry entries and magically the accelerator starts working!

I had a similar problem some months ago with a toolbar that had its buttons reorganised. In that case I had been playing with toolbar customisation early on in development but then turned it off. MFC, however, was still using the registry information to shuffle the toolbar buttons around even though the toolbar had been totally redesigned. Same solution - delete the registry entries. I may even add deleting the registry entries to our build process so that it doesn't catch us out again.

Thanks again.

PJH



Steve Achelis wrote:

<snip>I found the culprit!
28-Apr-10

<snip>

I found the culprit! Apparently the CKeyboardManager stores the
accelerators (in \HKEY_CURRENT_USER\Software\Company\Product\Workspace
\Keyboard-0). I know the user can customize the accelerator keys by
right-clicking on the Quick Access Toolbar, choosing Customize and
then Customize Keyboard Shortcuts, but I am surprised my resource-
defined accelerator ended up in the registry (and I did not check the
customized keyboard shortcuts dialog before deleting the Keyboard-0
entry in the registry). At this point I am just glad to have this bug
behind me.

Steve

Previous Posts In This Thread:

On Monday, April 26, 2010 3:24 PM
Steve Achelis wrote:

Accelerator that can't be deleted
I think my computer is possessed. My app (in VS2008 using the MFC
Enhancement Pack) defined an accelerator for the '-' key which posted
the message ID_VIEW_ZOOMOUT (which is defined as 33455). I wanted to
remove this accelerator. So I deleted the following line in the
"IDR_MAINFRAME ACCELERATORS" section of my rc file:

"-", ID_VIEW_ZOOMOUT, ASCII, NOINVERT

Easy enough, but pressing '-' still calls my OnZoomOut function! Hum,
so I search my code for all occurrences of ID_VIEW_ZOOMOUT to make
sure I am not posting it elsewhere. I am not. So I deleted the
Intermediate file and did a Clean and Rebuild. it is still posting the
message. Using spy, I can see that when WM_CHAR is 45 (the '-'
character), spy reports that the ID_VIEW_ZOOMOUT command is "sent from
an accelerator.=94 Here is the output from Spy:

<00036> 00130900 S WM_COMMAND wNotifyCode: 1 (sent from an
accelerator) wID:33455

I can=92t imagine where this accelerator is defined. I tried removing
all but one line from the ACCELERATORS section of the rc file (if I
remove all accelerator keys, it goes away, I think this is because
there is no longer an accelerator handler). I currently just have this
one dummy line in the ACCELERATOR section:

"B", 100, VIRTKEY, CONTROL, NOINVERT

I=92ve searched the project to make sure there isn=92t another ACCELERATOR
section. I=92ve searched to make there isn=92t another command with the
same value (33455). I=92ve changed the value of ID_VIEW_ZOOMOUT (to
33456) to see if that=92d make a difference (it still gets posted).
FWIW, if I do a =93return=94 at the beginning of my
CMainFrame::PreTranslateMessage the command doesn=92t get processed
(because I=92m not processing the keystroke). Oh, I have checked my
PreTranslateMessage to make sure it is not handling the message
(although Spy would not be telling me it was "sent from an accelerator"
in that case).

I=92m truly stumped. Any ideas?

Thanks!

[FWIW, I posted this message four hours ago and I received an email
confirming it, but the message never appeared on
microsoft.public.vc.mfc. Apologies if this later turns into a
duplicate post!]

On Monday, April 26, 2010 7:37 PM
David Ching wrote:

Are you sure you do not have another accelerator table in res\<your app>.rc2?
Are you sure you do not have another accelerator table in res\<your app>.rc2?
I would search for ID_VIEW_ZOOMOUT in all files in the folder.

-- David

On Monday, April 26, 2010 8:27 PM
Tom Serface wrote:

Not sure what is going on, but could not you comment out your handler code
Not sure what is going on, but could not you comment out your handler code so
that it would effectively ignore the message?

Also, is the message still in the resource.h file? Could be this is a
standard Windows behavior and you are just still handling it even if it is not
in your specific accelerator.

Tom

On Monday, April 26, 2010 8:37 PM
Steve Achelis wrote:

c2?
c2?

I have searched for ID_VIEW_ZOOMOUT, searched for the literal 33455 (in
case it was defined and associated with the '-' key), checked rc2, and
searched for ACCELERATORS (case sensitive, which is how it appears in
the rc file). And if I remove that last, lone, dummy accelerator (see
original post), the problem goes away. If I keep the dummy entry and
view the accelerators from the resource editor (rather than from the
text editor), only the one dummy entry is there.

Still stumped.

On Monday, April 26, 2010 9:57 PM
David Ching wrote:

Could you open your .exe in Visual Studio (open the .
Could you open your .exe in Visual Studio (open the .exe 'Resources') and
see what accelerators are actually compiled into the .exe. If worst comes
to worst you can delete any ones that should not be there and re-save the
..exe. This is really weird.

-- David

On Monday, April 26, 2010 10:09 PM
Hector Santos wrote:

I think it would be nice that people provide a "VS" version for theirquestions.
I think it would be nice that people provide a "VS" version for their
questions. At least until, people catch up with VS2010. We know have:

VS98 (1998, VC6)
VS2003
VS2005
VS2008
VS2010

and it appears new questions are VS2010 related.

David Ching wrote:




--
HLS

On Monday, April 26, 2010 11:11 PM
Steve Achelis wrote:

Hector, my original post stated VS2008...
Hector, my original post stated VS2008...

On Monday, April 26, 2010 11:15 PM
Steve Achelis wrote:

mesThat's a good thought, David, at least to see what accelerators are inthe
mes

That's a good thought, David, at least to see what accelerators are in
the exe.

Opening the exe shows two brances under Accelerator in th exe. One is
144 and contains my dummy entry (command 100 on the 'B' key). The
other is 30997 which has three entries: 58112 is VK_ESCAPE, 58114 is
VK_NEXT, and 58115 is VK_PRIOR. I am guessing (not a good thing to
do...) that these are defaults for the framework. In any case, I do not
see anything related to my command ID or my keystroke. Yeah, really
weird!

On Wednesday, April 28, 2010 9:18 AM
Steve Achelis wrote:

<snip>I found the culprit!
<snip>

I found the culprit! Apparently the CKeyboardManager stores the
accelerators (in \HKEY_CURRENT_USER\Software\Company\Product\Workspace
\Keyboard-0). I know the user can customize the accelerator keys by
right-clicking on the Quick Access Toolbar, choosing Customize and
then Customize Keyboard Shortcuts, but I am surprised my resource-
defined accelerator ended up in the registry (and I did not check the
customized keyboard shortcuts dialog before deleting the Keyboard-0
entry in the registry). At this point I am just glad to have this bug
behind me.

Steve

On Wednesday, April 28, 2010 9:36 AM
Tom Serface wrote:

Thanks for posting that.
Thanks for posting that. I was not losing sleep over it, but I confess that
this one had me curious. it is nice to know the resolution.

Tom


Submitted via EggHeadCafe - Software Developer Portal of Choice
Load Testing ASP.NET Applications with Visual Studio 2010
http://www.eggheadcafe.com/tutorials/aspnet/13e16f83-4cf2-4c9d-b75b-aa67fc309108/load-testing-aspnet-applications-with-visual-studio-2010.aspx