IAPCSpeech::AddVMenuCommandsFromResource

This method adds commands from a resource file to a voice menu.

Syntax

HRESULT IAPCSpeech::AddVMenuCommandFromResource( PIVCMDMENUW pVMenu, HINSTANCE hinst, PCWSTR pszMenuName, DWORD dwMenuState, DWORD dwFlag );

Parameters

pVMenu
Pointer to the menu to which commands are to be added.
hinst
Handle to the application instance.
pszMenuName
Pointer to the null-terminated string that contains the name of the menu.
dwMenuState
Specifies a DWORD that contains the state of the menu.
dwFlag
Specifies a DWORD that contains a flag.

Return Values

An appropriate HRESULT value is returned.

Remarks

Voice menus can be defined in a resource file. Each menu item has a string, an identifier, and a state. Create a voice menu with CreateVMenu passing in a null list of grammar identifiers. Then call AddVMenuCommandsFromResource, passing in your resource identifier and instance. The items are added to the existing menu, as shown in the following code example:

// Create a voice menu resource.
IDVM_ASEDIT MENUEX PRELOAD DISCARDABLE 
BEGIN
    MENUITEM "One\tTo enter numbers, say Zero through Nine", VC_ONE,
    0, VMS_NUMBERS
    MENUITEM "Two", VC_TWO, 0, VMS_NUMBERS
    MENUITEM "Three", VC_THREE, 0, VMS_NUMBERS
    MENUITEM "Four", VC_FOUR, 0, VMS_NUMBERS
    MENUITEM "Five", VC_FIVE, 0, VMS_NUMBERS
    MENUITEM "Six", VC_SIX, 0, VMS_NUMBERS 
    MENUITEM "Seven", VC_SEVEN, 0, VMS_NUMBERS
    MENUITEM "Eight", VC_EIGHT, 0, VMS_NUMBERS
    MENUITEM "Nine", VC_NINE, 0, VMS_NUMBERS
    MENUITEM "Zero", VC_ZERO, 0, VMS_NUMBERS 
    MENUITEM "Review\tTo read what you have entered, say Review"
    VC_REVIEW, 0, VMS_REVIEW
    MENUITEM "Delete\tTo remove the current character, say Delete",
    VC_DELETE, 0, VMS_DELETE 
    MENUITEM "Ok\tTo keep your changes, say Okay", VC_OK, 0, VMS_OK
    MENUITEM "Cancel\tTo cancel your changes, say Cancel", VC_CANCEL, 0,
    VMS_CANCEL 
END
// IDVM_ASEDIT and all of the VMS_* parameters are specific to the
// application. The last flag enables the application to
// define multiple states in which the menu can be loaded. Therefore,
// one menu resource can be used to load two voice menus: one for an edit mode and one for a review mode, if both exist.

// Create an empty voice menu.
CreateVMenu(
    NULL,
    &vn,
    m_hInst,
    0, 
    NULL, 
    APCSPCH_VM_USEEXISTING,
    &m_pVoiceMenuCards );

// Load in an voice command from a resource.
    if (SUCCEEDED( hr))
    {
    hr = m_pSpeech->AddVMenuCommandsFromResource( 
    m_pVoiceMenuCards, m_hInst,
MAKEINTRESOURCE(IDVM_CARDS), 0, APCSPCH_VM_USEEXISTING);
    } 
// By loading a menu from a resource file, you can use the same voice command and corresponding identifier in several applications, even though the voice command may differ in each. For example, the word PREVIOUS can have the same identifier whether it moves you back a screen in one application and restores the former settings of another application. Loading a menu from a resource file also enables more consistent coding, and enables the voice command to behave like a keystroke rather than a custom identifier.