Share via


SHCreateMenuBar

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function creates a menu or softkey bar, as appropriate, to be associated with a specified window.

Note

Beginning with Windows Mobile 6.5.3, soft keys are replaced by touchable tiles on Windows Mobile Professional phones.

Syntax

BOOL SHCreateMenuBar(
  SHMENUBARINFO * pmb
);

Parameters

Return Value

This function returns TRUE if it is successful and FALSE if it fails.

Remarks

When successful, the newly created menu bar or soft key bar is positioned at the bottom of the specified window.

An application must resize its main window to accommodate the size of the menu bar. The following code shows how to programmatically determine the size of the menu bar.

hMenuBar = SHFindMenuBar( MyMainWindow);
GetWindowRect(hMenuBar, &MyRect);

In Windows Mobile 6.5, a soft key bar will be automatically created if the specification passed to SHCreateMenuBar function contains 2 or less top level menu items and those menu items do not contain images.

If the specification passed to SHCreateMenuBar function contains images or more than 2 top level menu items, the behavior is as follows.

  • SHCreateMenuBar will fail for Windows Mobile Standard.
  • SHCreateMenuBar will create a traditional style menu bar for Windows Mobile Professional and Windows Mobile Classic.

Code Example

The following code example demonstrates how to use SHCreateMenuBar.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

#include <aygshell.h>
extern HINSTANCE g_hInstance;
HWND g_hwndMb;
HMENU g_hMenu;
#define IDM_HELLO_MENU 100
LRESULT CALLBACK SHCreateMenuBarWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static fDisableSK = FALSE;
    switch(message)
    {
        case WM_CREATE:
            {
                SHMENUBARINFO mbi;
                ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
                mbi.cbSize     = sizeof(SHMENUBARINFO);
                mbi.hwndParent = hwnd;
                mbi.nToolBarId = IDM_HELLO_MENU;
                mbi.hInstRes   = g_hInstance;
                mbi.dwFlags    = SHCMBF_HMENU;
                if(SHCreateMenuBar(&mbi))
                {
                    g_hwndMb          = mbi.hwndMB;
                    TBBUTTONINFO tbbi = {0};
                    tbbi.cbSize       = sizeof(tbbi);
                    tbbi.dwMask       = TBIF_LPARAM | TBIF_BYINDEX;
                    SendMessage(g_hwndMb, TB_GETBUTTONINFO,0, (LPARAM)&tbbi);
                    g_hMenu           = (HMENU)tbbi.lParam;
                }
                else
                {
                    DestroyWindow(hwnd);
                    PostQuitMessage(1);
                    return(-1);
                }
                break;
            }
        case WM_KEYDOWN:
            {
                // When the user presses the space key, toggle between full screen and normal mode.
                if (VK_SPACE == wParam)
                {
                    if(fDisableSK)
                    {
                        SHEnableSoftkey(g_hwndMb, /*uid*, 0 for SK1, 1 for SK2*/1, /*bByIndex*/TRUE, TRUE);
                    }
                    else
                    {
                        SHEnableSoftkey(g_hwndMb, /*uid*, 0 for SK1, 1 for SK2*/1, /*bByIndex*/TRUE, FALSE);
                    }
                }
                break;
            }
    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

Requirements

Header aygshell.h
Library aygshell.lib
Windows Embedded CE Windows CE .NET 4.2 and later
Windows Mobile Pocket PC 2000 and later, Smartphone 2002 and later

See Also

Reference

SHMENUBARINFO