Getting Accelerator table from View
Colin Angus Mackay -- colin.angus.mackay@dial.pipex.com
Saturday, November 16, 1996
Environment: Win95, NT3.51, NT4.0, VC++ 4.1
I have a (possibly) very lengthy draw process in the app that I am
developing and I wish to be able to stop it by letting the user press
the space bar. I have set up in the accelerator table an ID_STOP_DRAWING
for the spacebar. I am however having trouble catching this message.
>From what I can see I need to get a handle to the Accelerator table from
the view. The following is the code I have (but I don't know how to get
hAccel), it is in a function that is called periodically from the
drawing functions to check whether it should continue or not.
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!::TranslateAccelerator(pWnd->hWnd, hAccel, &msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
How do I get the handle to the Accelerator table that my view uses
(IDR_MAINFRAME)? Or I am going about this the wrong way?
If any one can help, I'd be mose grateful,
Colin Mackay.
GoroKhM1 -- gorokhm1@SMTP.ATG-NET.COM
Monday, November 18, 1996
[Mini-digest: 3 responses]
The articles below work with accelerator table. It may help you.
// Q117500 Using Accelerators with an MFC Modeless Dialog Box
// Q100770 Accelerator Keys When Modal Dialog Box Main Window
-mg
MarkG@usa.net
-----From: kevin@earth.pln.com.tw (Kevin Tarn)
Why didn't you try to capture the space bar pressed by overrding PreTranslateMessage ?
BOOL CMyView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch (pMsg->message)
{
case WM_KEYDOWN:
{
if (pMsg->wParam == VK_SPACE)
{
OnKeyDown(pMsg->wParam, LOWORD(pMsg
->lParam), HIWORD(pMsg->lParam));
return TRUE;
}
else return CView:: PreTranslateMessage(pMsg);
break;
}
default:
return CView:: PreTranslateMessage(pMsg);
}
}
Kevin Tarn
kevin@pln.com.tw
----------
>Environment: Win95, NT3.51, NT4.0, VC++ 4.1
>I have a (possibly) very lengthy draw process in the app that I am
>developing and I wish to be able to stop it by letting the user press
>the space bar. I have set up in the accelerator table an ID_STOP_DRAWING
>for the spacebar. I am however having trouble catching this message.
>>From what I can see I need to get a handle to the Accelerator table from
>the view. The following is the code I have (but I don't know how to get
>hAccel), it is in a function that is called periodically from the
>drawing functions to check whether it should continue or not.
> if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
> {
> if (!::TranslateAccelerator(pWnd->hWnd, hAccel, &msg))
> {
> ::TranslateMessage(&msg);
> ::DispatchMessage(&msg);
> }
> }
>ow do I get the handle to the Accelerator table that my view uses
>IDR_MAINFRAME)? Or I am going about this the wrong way?
>f any one can help, I'd be mose grateful,
>Colin Mackay.
-----From: Dave_Rabbers@Quinton-Eng.CCMAIL.CompuServe.COM
Can your draw process run at Idle processing time? If you stick in an
OnIdle routine (in your CWinApp), and do a little drawing work within
each call, your stop drawing command can make its way through the
normal MFC command routing mechanism. The only trick is to design a
mechanism to get CWinApp OnIdle calls passed to the CView objects that
need them, but this is not very difficult to do.
| Вернуться в корень Архива
|