|
-
September 24th, 2003, 08:24 AM
#1
Accelerator Keys
Using the resource editor, i have created a few accelerator keys...However the problem is that the accelerator keys will only work if the CMainFrame class is in focus. If i have invoked another dialog box (another class) and that dialog box is now in focus, the accelerator keys cannot work because the message generated by pressing the Accelerator keys are send to the dialog in focus instead of the CMainFrame class.
Is there a way to solve this problem so that the Accelerator Keys can work even though the CMainFrame class is not in focus?
-
September 24th, 2003, 09:40 AM
#2
If the Accelerator keys are being sent to the dialog you can either handle them there, or Send them to the mainframe.
Generally, if the dialog is modal, it should not allow (handle) any commands that are not relavant to it, in other words, if you have a modal dialog getting information from the user, you do not want it to Send the message to the mainframe.
If the dialog is modaless, Sending the command to the mainframe may be a good solution IF it makes sense.
bytz
--This signature left intentionally blank--
-
September 24th, 2003, 02:09 PM
#3
One solution is to handle the message in the dialog window and pass it to main frame via PostMessage().
Kuphryn
-
September 24th, 2003, 09:09 PM
#4
Originally posted by bytz
If the Accelerator keys are being sent to the dialog you can either handle them there, or Send them to the mainframe.
Generally, if the dialog is modal, it should not allow (handle) any commands that are not relavant to it, in other words, if you have a modal dialog getting information from the user, you do not want it to Send the message to the mainframe.
If the dialog is modaless, Sending the command to the mainframe may be a good solution IF it makes sense.
How do i send the command to the mainframe? I tried using the PreTranslateMessage() function to handle the message and then call the correct functions in mainframe from the window in focus. However this solution have a problem because some functions called by the window (using the accelerator keys and handled in PreTranslateMessage) will need to close all windows using CDialog::OnOK. This will cause the application to crash since the function call is made in the PreTanslateMessage function of the window in focus.
Is there any way to handle the message without using PreTranslateMessage and then send the Message to the mainframe.
-
September 24th, 2003, 09:33 PM
#5
Originally posted by kuphryn
One solution is to handle the message in the dialog window and pass it to main frame via PostMessage().
Kuphryn
How do handle the message generated by the Accelerated keys in the dialog window?
And how can i find out what is the exact message generated by the Accelerator keys?
-
September 25th, 2003, 08:59 AM
#6
Accelerator keys generate a command message with the ID that you gave them. For example, "Ctrl+N" has (should have) an ID of ID_FILE_NEW, which is the same as the menu item File\New; both are handled by the OnFileNew method. The OnFileNew method is associated with the command message by this line in the message map:
ON_COMMAND(ID_FILE_NEW, OnFileNew)
You can add the necessary code by hand, or you should be able to use the class wizard...
bytz
--This signature left intentionally blank--
-
September 25th, 2003, 03:05 PM
#7
Are you loading the accelerator table in OnInitDialog?
Does your PreTranslateMessage translate the accelerator keys? If your PreTranslateMessage does anything other than translate the accelerator keys then you are probably not using PreTranslateMessage the way it should be to do what you want.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|