Click to Rate and Give Feedback
MSDN
MSDN Library
Shell
Shell Reference
AYGShell Reference
AYGShell Functions
 SHCreateMenuBar

  Switch on low bandwidth view
SHCreateMenuBar
Windows Mobile SupportedWindows Embedded CE Supported
8/28/2008

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


BOOL SHCreateMenuBar(
  SHMENUBARINFO * pmb
);
pmb

[in] Pointer to an SHMENUBARINFO structure.

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

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, 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 6 Standard.
  • SHCreateMenuBar will create a traditional style menu bar for Windows Mobile 6 Professional and Windows Mobile 6 Classic.

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);
}
Headeraygshell.h
Libraryaygshell.lib
Windows Embedded CEWindows CE .NET 4.2 and later
Windows MobilePocket PC 2000 and later, Smartphone 2002 and later

Reference

SHMENUBARINFO

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker