CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200

    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?

  2. #2
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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--

  3. #3
    Join Date
    Feb 2002
    Posts
    5,757
    One solution is to handle the message in the dialog window and pass it to main frame via PostMessage().

    Kuphryn

  4. #4
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200
    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.

  5. #5
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200
    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?

  6. #6
    Join Date
    Sep 2002
    Location
    DC Metro Area, USA
    Posts
    1,509
    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--

  7. #7
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    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.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured