SHEnableSoftkey

Send Feedback

This function enables or disables individual soft keys by command identifier or index.

HRESULT SHEnableSoftkey(
  HWND hwndMenuBar,
  UINT uid,
  BOOL bByIndex,
  BOOL bEnable
);

Parameters

  • hwndMenuBar
    [in] Handle to the soft key bar as returned from SHCreateMenuBar or SHFindMenuBar.
  • uid
    The command identifier of the soft key or the index (0 or 1).
  • bByIndex
    Set to TRUE if the uid parameter is an index, FALSE if it is a command identifier.
  • bEnable
    Set to TRUE to enable the soft key, FALSE to disable it.

Return Values

S_OK indicates success; otherwise, returns a failure code.

Code Example

The following code example demonstrates how to use SHEnableSoftkey.

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

Pocket PC: Windows Mobile 2003 Second Edition and later.
Smartphone: Smartphone 2002 and later.
OS Versions: Windows CE 3.0 and later.
Header: Aygshell.h
Library: Aygshell.lib.

See Also

Soft Key and Menu Guidelines

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.