Export (0) Print
Expand All

SHCreateMenuBar (Windows CE 5.0)

Windows CE 5.0
Send Feedback

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

Syntax

BOOL SHCreateMenuBar(
  SHMENUBARINFO * pmb
);

Parameters

pmb
[in] Pointer to an SHMENUBARINFO structure.

Return Values

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

Windows Mobile Remarks

In Windows Mobile 5.0, 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 a Windows Mobile 5.0-based Smartphone
  • SHCreateMenuBar will create a traditional style menu bar for a Windows Mobile 5.0-based Pocket PC

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

OS Versions: Windows CE .NET 4.2 and later
Pocket PC: Pocket PC 2000 and later
Smartphone: Smartphone 2002 and later
Header: aygshell.h
Library: aygshell.lib

See Also

SHMENUBARINFO


Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft