From: fiveight on
Hi All:

In explorer, if I press F10, the focus will be set on menu bar. But in
vs2008, F10 is the shortcut of "next" command. In my own MFC program, I use
F10 as a shortcut of a command too. When press F10, the command will run
first, and then the focus will be set on menu bar. How can I use F10 to run
the command and not change the focus? I try to catch WM_KEYUP+VK_F10 message
in PreTranslateMsg function of CWinApp, But it does not work.

Thanks!

Fiveight

From: Seetharam on
This fixes it :

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_SYSKEYDOWN)
{
if(pMsg->wParam == VK_F10)
return TRUE;
}
return CFrameWnd::PreTranslateMessage(pMsg);
}

-SM
From: AliR (VC++ MVP) on
Do not try to catch the F10 key in OnKeyDown, or in PreTranslateMessage.

Do it the right way, it will only take 2 minutes to do.

Open your resource editor, open the accelerator table (IDR_MAINFRAME).
First make sure there is no item that is assigned F10, then go to the bottom
of the list and insert a new item, give it an ID (for example
ID_MYOPERATION, this can be the same as a menu item id, if you do that then
when the short cut key is pressed, then it will be like the user selected
the menu item), and select F10 as the key, make sure the Modifier is either
blank or says None.

Then go to your class where you want to handle the F10 key, and handle the
ID of the accelerator just like you would a menu item.

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_COMMAND(ID_MYF10, OnMyf10)
END_MESSAGE_MAP()

void CMainFrame::OnMyf10()
{
MessageBeep(1);
}


Now F10 no longer does its default thing, and does whatever you want to do



AliR.

"fiveight" <fiveight(a)tom.com> wrote in message
news:2FD39D88-259E-4F3D-9E7C-8AE7308A846B(a)microsoft.com...
> Hi All:
>
> In explorer, if I press F10, the focus will be set on menu bar. But in
> vs2008, F10 is the shortcut of "next" command. In my own MFC program, I
> use F10 as a shortcut of a command too. When press F10, the command will
> run first, and then the focus will be set on menu bar. How can I use F10
> to run the command and not change the focus? I try to catch
> WM_KEYUP+VK_F10 message in PreTranslateMsg function of CWinApp, But it
> does not work.
>
> Thanks!
>
> Fiveight


From: fiveight on
Thank you very much!

If change WM_SYSKEYDOWN to WM_SYSKEYUP, It will do work! ^_^

Fiveight

"Seetharam" <smisro(a)gmail.com>
??????:28984a84-878e-42be-aea4-e5b9e9bc6a99(a)d1g2000hsg.googlegroups.com...
> This fixes it :
>
> BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
> {
> if(pMsg->message == WM_SYSKEYDOWN)
> {
> if(pMsg->wParam == VK_F10)
> return TRUE;
> }
> return CFrameWnd::PreTranslateMessage(pMsg);
> }
>
> -SM


From: fiveight on
Yes, AliR. What you said is the method of adding shortcut. But after adding
this shortcut, if you press F10, first the ID_MYF10 command will run, and
after you release F10 key, the focus will be set on menu bar.

Seetharam is right. I have to catch WM_SYSKEYUP+VK_F10 in
PreTranslateMessage. And this will not affect the ID_MYF10 command running.

Thanks

Fiveight

"AliR (VC++ MVP)" <AliR(a)online.nospam> д����Ϣ����:5tGRj.873$To6.641(a)newssvr21.news.prodigy.net...
> Do not try to catch the F10 key in OnKeyDown, or in PreTranslateMessage.
>
> Do it the right way, it will only take 2 minutes to do.
>
> Open your resource editor, open the accelerator table (IDR_MAINFRAME).
> First make sure there is no item that is assigned F10, then go to the
> bottom of the list and insert a new item, give it an ID (for example
> ID_MYOPERATION, this can be the same as a menu item id, if you do that
> then when the short cut key is pressed, then it will be like the user
> selected the menu item), and select F10 as the key, make sure the Modifier
> is either blank or says None.
>
> Then go to your class where you want to handle the F10 key, and handle the
> ID of the accelerator just like you would a menu item.
>
> BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
> ON_COMMAND(ID_MYF10, OnMyf10)
> END_MESSAGE_MAP()
>
> void CMainFrame::OnMyf10()
> {
> MessageBeep(1);
> }
>
>
> Now F10 no longer does its default thing, and does whatever you want to do
>
>
>
> AliR.
>
> "fiveight" <fiveight(a)tom.com> wrote in message
> news:2FD39D88-259E-4F3D-9E7C-8AE7308A846B(a)microsoft.com...
>> Hi All:
>>
>> In explorer, if I press F10, the focus will be set on menu bar. But in
>> vs2008, F10 is the shortcut of "next" command. In my own MFC program, I
>> use F10 as a shortcut of a command too. When press F10, the command will
>> run first, and then the focus will be set on menu bar. How can I use F10
>> to run the command and not change the focus? I try to catch
>> WM_KEYUP+VK_F10 message in PreTranslateMsg function of CWinApp, But it
>> does not work.
>>
>> Thanks!
>>
>> Fiveight
>
>