Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
To create a soft key bar and soft keys, you can create a resource file and specify the Windows Embedded CE SHMENUBARINFOstructure and the SHCreateMenuBarfunction during the handling of the Windows Embedded CE WM_INITDIALOGmessage.
Note: |
---|
Beginning with Windows Mobile 6.5.3, soft keys are replaced by touchable tiles on Windows Mobile Professional phones. |
To Create a Soft Key Bar and Soft Keys
-
Create a resource file by doing the following:
Identify any menu that is displayed by a soft key. In the following example, the IDR_MAIN_MENU menu is displayed and contains the DONE command.
Copy Code // MENU IDR_MAIN_MENU MENU BEGIN : : // SUBMENU 2. This submenu is displayed by the right soft key. POPUP "" BEGIN MENUITEM "Done" IDM_CARDVIEW_SK2_DONE END END
Indicate the text that appears on the soft key labels, and assign a string resource ID to each text string. In the following example, the text strings are "Edit" and "Menu" and the string resource IDs are IDS_CARDVIEW_EDIT and IDS_CARDVIEW_MENU.
Copy Code // STRING TABLE STRINGTABLE DISCARDABLEBEGIN : IDS_CARDVIEW_EDIT "Edit" IDS_CARDVIEW_MENU "Menu" : END
Indicate the display and functionality of the soft key bar and the soft keys, as shown in the following example.
Copy Code // Card View Soft key bar IDR_CARDVIEW_MENUBAR RCDATA BEGIN IDR_MAIN_MENU, 2, I_IMAGENONE, IDM_CARDVIEW_SK1_EDIT, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_CARDVIEW_EDIT, 0, NOMENU, I_IMAGENONE, IDM_CARDVIEW_SK2_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE, IDS_CARDVIEW_MENU, 0, 2,END
-
Add the SHMENUBARINFOstructure to the application source code. Specify the resource ID for the soft key bar by using the nToolBarID structure member. In the following example, the nToolBarID structure member specifies IDR_CARDVIEW_MENUBAR.
Copy Code SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); // Reset mbi to 0. mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwnd; // Soft key bar's owner. mbi.nToolBarId = IDR_CARDVIEW_MENUBAR; // Soft key bar resource. mbi.hInstRes = g_hinst; // HINST in which resource is located.
-
Add the SHCreateMenuBarfunction to the application source code.
Example
Copy Code | |
---|---|
//////////////////////////////////////////////////////////////////// // EXAMPLE 1 //////////////////////////////////////////////////////////////////// // MENU IDR_MAIN_MENU MENU BEGIN : : // SUBMENU 2. This submenu is displayed by the right soft key POPUP "" BEGIN MENUITEM "Done" IDM_CARDVIEW_SK2_DONE END END //////////////////////////////////////////////////////////////////// // STRING TABLE //////////////////////////////////////////////////////////////////// STRINGTABLE DISCARDABLEBEGIN : IDS_CARDVIEW_EDIT "Edit" IDS_CARDVIEW_MENU "Menu" : END // Card View Soft key bar IDR_CARDVIEW_MENUBAR RCDATA BEGIN IDR_MAIN_MENU, 2, I_IMAGENONE, IDM_CARDVIEW_SK1_EDIT, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE, IDS_CARDVIEW_EDIT, 0, NOMENU, I_IMAGENONE, IDM_CARDVIEW_SK2_MENU, TBSTATE_ENABLED, TBSTYLE_DROPDOWN | TBSTYLE_AUTOSIZE, IDS_CARDVIEW_MENU, 0, 2, END //////////////////////////////////////////////////////////// // EXAMPLE 2 //////////////////////////////////////////////////////////// BOOL rb; int rc; LRESULT lr; SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); // Reset mbi to 0. mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwnd; // Soft key bar's owner. mbi.nToolBarId = IDR_CARDVIEW_MENUBAR; // Soft key bar resource. mbi.hInstRes = g_hinst; // HINST in which resource is located. // Create the Soft key bar. rb = SHCreateMenuBar(&mbi); if (rb == FALSE) // SHCreateMenuBar failed. { rc = MessageBox(NULL, _T("Could not create soft key bar."), _T("Error"), MB_OK); if (rc == 0) // Not enough memory to create MessageBox. return E_OUTOFMEMORY; return E_FAIL; // Replace with specific error handling. } |