• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Accelerator problem

I have an SDI application with a DialogBar to the right. The DialogBar contains a PropertySheet with several PropertyPages. The View contains an image. My problem is that sometimes accelerators like Ctrl+Z does not work. Often this happens after changing page on the PropertySheet. If I then click in the image the accelerators works again. What should I do to solve this?
0
P1R
Asked:
P1R
  • 3
1 Solution
 
SteveGTRCommented:
You might try creating a class derived from CPropertySheet and instantiating it. Within the class override the PreTranslateMessage() function and manually process accelerator requests like so:

BOOL CMyPropSheet::PreTranslateMessage(MSG* pMsg)
{
  // Enable accelerator processing
  if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
    {
    HACCEL hAccel = ((CFrameWnd*) AfxGetApp()->GetMainWnd())->GetDefaultAccelerator();

    if (hAccel && ::TranslateAccelerator(m_hWnd, hAccel, pMsg))
      return TRUE;
    }

  return CPropertySheet::PreTranslateMessage(pMsg);
}

Good Luck,
Steve
0
 
P1RAuthor Commented:
(I have already a class derived from CPropertySheet and I have overridden the PreTranslateMessage() function in order to call pToolTip->RelayEvent(pMsg);)

I tried to add the code for enabling accelerator processing as you suggested, but the result is still the same. I have also tried to add the code for enabling accelerator to the PreTranslateMessage() functions for each PropertyPage, and for the View, but still the same result. What to do next?
0
 
P1RAuthor Commented:
I have got it working now. I put the PreTranslateMessage function in the CMyPropertyPage class. Then I needed to set focus to the main window. The PreTranslateMessage function will be

BOOL CMyPropertyPage::PreTranslateMessage(MSG* pMsg)
{
     if (pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
     {
          CFrameWnd* mainWnd = (CFrameWnd*) AfxGetApp()->GetMainWnd();
          mainWnd->SetFocus();
          HACCEL hAccel = mainWnd->GetDefaultAccelerator();
          if(hAccel && ::TranslateAccelerator(m_hWnd, hAccel, pMsg))
               return TRUE;
     }

     return CPropertyPage::PreTranslateMessage(pMsg);
}
0
 
P1RAuthor Commented:
I happened to post this question also in the WinProg section. There I got an answer from DanRollins and I think it is fair to accept both as answers. Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now