SHCreateMenuBar (Compact 2013)

3/28/2014

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

Syntax

BOOL SHCreateMenuBar(
  SHMENUBARINFO* pmb
);

Parameters

Return Value

Returns TRUE on success and FALSE on failure.

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);

Central menus work in the same way as classic style menu bars, except that central menus allow only one central pop-up menu associated with a central menu soft key. You can open the central menu by pressing a menu key or tapping the menu soft key (on a touch screen). An OEM developer can configure the menu key to be assigned to a new hardware key or directional pad action.

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

See Also

Reference

Shell Functions
SHMENUBARINFO