Link to home
Start Free TrialLog in
Avatar of P1R
P1R

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of P1R
P1R

ASKER

(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?
Avatar of P1R

ASKER

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);
}
Avatar of P1R

ASKER

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!