C++ – How to programmatically activate the menu in Windows mobile

cmfcmobilewindows

In most versions of windows, you can get to the menu by pressing the F10 key, thus avoiding having to use the mouse. This behaviour does not appear to be present in Windows Mobile 5.0, but is desirable as the device I am using will be more keyboard than touch screen driven.

Is there a way of programmatically activating and using the menu on Windows Mobile 5.0, under C++ using either MFC or Windows API calls. I have tried setting the focus of the CFrameWnd and CCeCommandBar classes to no avail.

Best Answer

After a number of attempts, the following appears to work;

void CMyFrame::OnFocusMenu()
{
  PostMessage(WM_SYSCOMMAND,SC_KEYMENU,0);
}

FWIW, none of the following did, where m_wndCommandBar is the CCeCommandBar toolbar containing the menu;

::SetActiveWindow(m_wndCommandBar.m_hWnd);
m_wndCommandBar.PostMessage(WM_ACTIVATE,WA_ACTIVE,0);
m_wndCommandBar.PostMessage(WM_LBUTTONDOWN,0,0);
m_wndCommandBar.PostMessage(WM_LBUTTONUP,0,0);
m_wndCommandBar.OnActivate(WA_ACTIVE, NULL, FALSE);
m_wndCommandBar.SetFocus();