WireLess Studio Widgets Developer's Guide
WSWDG ContentsWStWidget class reference

AddOption

Call this method to add a new option to a specific WS_MENU widget.

Ole declaration

VARIANT_BOOL AddOptionByName(LPCTSTR sObjectName, SHORT usIconId, LPCTSTR sOptionText);

VARIANT_BOOL AddOptionById(SHORT usObjectId, SHORT usIconId, LPCTSTR sOptionText);

Parameters
sObjectName
The name of the target widget.
usObjectId
The id of the target widget.
usIconId
The icon's id of the new option that was previously loaded using WStFactory::LoadExternalIcon. This parameter works only if the menu type is WS_BUTTON_MENU_TYPE ( For more information see ChangeMenuType). If this parameter is 0, no icon is displayed on the new option.
sOptionText
The new option text.
Return Value

On success, AddOption returns TRUE, FALSE otherwise. To get extended information, call WStError::GetLastErrorCode.

Remarks

The icon's id is omitted if the target menu's type is not WS_BUTTON_MENU_TYPE. The number of options that can be displayed by a button menu depends on it's size, if certain number of options is exceeded, no options are displayed ( Try MenuDemoModule.bas.txt using 30 or more options).

AddOption always loads the 32x32 pixel version of the selected icon.

Example
C#
using WirelessStudioOleWidgets;
WStWidget oWidget = new WStWidget();
WStFactory oFactory = new WStFactory();
short iMenuId = 15;
oFactory .CreateWidgetById((short)WSTFactoryConstants.WS_MENU, iMenuId,"", 0,0, 50, 50, "");
oWidget.ChangeMenuTypeById(iMenuId, (short)WSTWidgetConstants.WS_COMBO_BOX_MENU_TYPE);
oWidget.AddOptionById(iMenuId, 0, "Show Menu");
oWidget.AddOptionById(iMenuId, 0, "Save File");
oWidget.AddOptionById(iMenuId, 0, "Close Application");
Visual Basic 6 (Full Example: MenuDemoModule.bas.txt)
Public wsWidget As New WStWidget
Public wsFactory As New WStFactory		
...
Public Sub FillOptions(sMenuName As String, iOptionCount As Integer)
    Dim i As Integer
    Dim iIconIndex As Integer
    Dim sOptionIndex As String
    
    wsWidget.ClearOptionsByName sMenuName
    
    If iOptionCount < 1 Then
        Exit Sub
    End If
    
    iIconIndex = 1
        
    For i = 1 To iOptionCount
        sOptionIndex = i
        wsWidget.AddOptionByName sMenuName, iIconIndex, "Option " + sOptionIndex
        iIconIndex = Int((4 - 1 + 1) * Rnd + 1)
        
    Next i
    
End Sub
...
See also

GetOption | GetSelectedItem | ChangeMenuType | ClearOptions | EnableFlatStyle

WStWiget class reference | WStForm class reference | WStFactory class reference | WStError class reference