Share via


SHCreateMenuBar (Windows Embedded CE 6.0)

1/6/2010

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

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

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

See Also

Reference

AYGShell Functions
SHMENUBARINFO