I have a dynamically created toolbar on a plain Win32 dialog. My buttons are added with & shortcuts which correctly puts underscore to characters following ampersand but pressing Alt+(char) causes a beep and the button is not clicked.
It has been a while since I have done Win32 API development. Is there something that needs to be done to a dynamically created child window (toolbar) in order for the accelerator keys to work?
This could be something really obvious that I am missing…
Well… You have to write code to handle these keypresses and convert them into
WM_COMMANDmessages. The traditional way to do this is to define an accelerator table and process them usingTranslateAccelerator()– but of course, you’re free to do it however you like… Just make sure the keys you handle jibe with the keys you underline!You might also find this KB article helpful: How to use accelerator keys within a modal dialog box in Visual C++… Or, for a more in-depth (and MFC-free) look at implementing custom message processing in dialogs, check out Raymond Chen’s articles on the dialog manager, specifically part 4: The dialog loop and part 9: Custom accelerators in dialog boxes (but seriously, read the whole thing, you know you want to…)