WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: George Vagenas on August 10, 2013, 04:05:05 PM

Title: Menu Item Initialization
Post by: George Vagenas on August 10, 2013, 04:05:05 PM
I modified the Dialog Menu Example
; Dialog Menu Example:

#DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd)
   MSG_INIT = 0
   MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
   MSG_MENUITEM=15           ; MenuItem selected
   RET_DO_CANCEL=0           ; Cancels dialog
   RET_DO_DEFAULT= -1        ; Continue with default processing for control
   RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
   ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
   Switch MyDialog_Message                                  ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
         DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE)
         DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@TRUE)
         DialogProcOptions(MyDialog_Handle,16,@TRUE)
         Return(RET_DO_DEFAULT)
     Case MSG_BUTTONPUSHED
        Switch ON_EQUAL
           Case MyDialog_Name == "PushButton_RightClickMe"           ; Right Click Me!
              Pause('Notice','You Left-Clicked the button')
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "PushButton_Cancel"       ; Cancel
              Return(RET_DO_CANCEL)
        EndSwitch                                          ; MyDialog_Name
        Return(RET_DO_DEFAULT)
     Case MSG_MENUITEM
        Switch ON_EQUAL
           Case MyDialog_Name == "cmi1_PushButton_RightClickMe"      ; PushButton_RightClickMe Context Menu One
              Pause('You Selected:','Context Menu One')
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "cmi3_PushButton_RightClickMe"      ; cmi1_PushButton_RightClickMe Subcontext Menu One
              Pause('You Selected:','Subcontext Menu One')
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "cmi2_PushButton_RightClickMe"      ; PushButton_RightClickMe Context menu Two
              Pause('You Selected:','Context menu Two')
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "mbi1_MyDialog"           ; Dialog_Bar Menu Item One
              ;NOTICE : The user-defined callback is not called in response to the mouse selection of menu
              ;item that have an associated dropdown menus or submenus. The associated dropdown or submenu
              ;is displayed instead. Hot-keys should not be used with menu items that display a dropdown
              ;or submenu.
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "mbi2_MyDialog"           ; mbi1_MyDialog SubMenu Item One
              Pause('You Selected:','SubMenu Item One')
              Return(RET_DO_NOT_EXIT)
           Case MyDialog_Name == "mbi3_MyDialog"           ; Dialog_Bar Menu Item Two
              Pause('You Selected:','Menu Item Two')
              Return(RET_DO_NOT_EXIT)
        EndSwitch                                          ; MyDialog_Name
        Return(RET_DO_DEFAULT)
   case 16   
         pause('Menu Init',  MyDialog_Name)
        Return(RET_DO_DEFAULT)
   EndSwitch                                                ; MyDialog_Message
   Return(RET_DO_DEFAULT)
#EndFunction
                                                ; End of Dialog Callback MyDialogCallbackProc
;MENUITEMs can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.
;
;Dropdown menus are created by placing the name of a MENUITEM displayed in the menu bar in the parent attribute
;of the menu item's template entry.  A submenu is started by placing the name of a MENUITEM other than a menu bar
;displayed menu item in the parent attribute.
;
;Context menus are usually activated by right-clicking the client area of a control or dialog.  Create context
;menus by specifying the name of a control in the parent attribute.  If you use the DEFAULT keyword as the
;MENUITEM parent, the context menu will by associated with the dialog and display when the user right clicks on
;an 'empty' area of the dialog or on any control that does not already have a system or template supplied context
;menu.
MyDialogFormat=`WWWDLGED,6.2`
MyDialogCaption=`Menu Sample`
MyDialogX=241
MyDialogY=080
MyDialogWidth=242
MyDialogHeight=117
MyDialogNumControls=010
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0
MyDialog001=`073,047,078,012,PUSHBUTTON,"PushButton_RightClickMe",DEFAULT,"Right Click Me!",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`093,093,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`000,000,000,000,MENUITEM,"cmi1_PushButton_RightClickMe","PushButton_RightClickMe","Context Menu One",DEFAULT,3,DEFAULT`
MyDialog004=`000,000,000,000,MENUITEM,"cmi3_PushButton_RightClickMe","cmi1_PushButton_RightClickMe","Subcontext Menu One",DEFAULT,4,DEFAULT`
MyDialog005=`000,000,000,000,MENUITEM,"cmi2_PushButton_RightClickMe","PushButton_RightClickMe","Context menu Two",DEFAULT,5,DEFAULT`
MyDialog006=`000,000,000,000,MENUBAR,"Dialog_Bar"`
MyDialog007=`000,000,000,000,MENUITEM,"mbi1_MyDialog","Dialog_Bar","Menu Item One",DEFAULT,7,DEFAULT`
MyDialog008=`000,000,000,000,MENUITEM,"mbi2_MyDialog","mbi1_MyDialog","SubMenu Item One",DEFAULT,8,DEFAULT`
MyDialog009=`000,000,000,000,MENUITEM,"mbi3_MyDialog","Dialog_Bar","Menu Item Two",DEFAULT,9,DEFAULT`
MyDialog010=`000,000,000,000,MENUITEM,"mbi4_MyDialog","mbi3_MyDialog","SubMenu Item Two",DEFAULT,10,DEFAULT`
ButtonPushed=Dialog("MyDialog")
adding a DialogProcOptions(MyDialog_Handle,16,@TRUE) line to the initiialization section, a simple case statement to catch the event, and a submenu to the "mbi3_MyDialog" menu item.   
Could you provide an example of modifying the menus using this event.  As it is DialogProcOptions 16 prevents the menu events from firing.
Title: Re: Menu Item Initialization
Post by: JTaylor on August 10, 2013, 05:55:46 PM
Here is an example.  You can only, dynamically, change the text on a menu as far as I know.   Assuming I remember correctly, this feature was added primarily because there was no way to know a menu item had been clicked unless it was the final menu item in the path....was thinking there may have been another reason but can't recall.  I know it was added because I asked a question and/or made a request at the time the menus were implemented because the lack made some reasonable task impossible to do.  Just can't think what it was.

Jim




Home_Path = DirScript()
DirChange(Home_Path)
GoSub Load_Routines

Init_Dialog_Constants()

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`Menu Sample`
MyDialogX=241
MyDialogY=080
MyDialogWidth=242
MyDialogHeight=117
MyDialogNumControls=010
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`073,047,078,012,PUSHBUTTON,"pb_MyD_RightClickMe!",DEFAULT,"Right Click Me!",1,1,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`093,093,036,012,PUSHBUTTON,"pb_MyD_Cancel",DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`000,000,000,000,MENUBAR,"mb_MyD_MENUBAR"`
MyDialog004=`000,000,000,000,MENUITEM,"mn_MyD_ContextMenuOne","pb_MyD_RightClickMe!","Context Menu One",DEFAULT,3,DEFAULT`
MyDialog005=`000,000,000,000,MENUITEM,"mn_MyD_SubcontextMenuOne","mn_MyD_ContextMenuOne","Subcontext Menu One",DEFAULT,4,DEFAULT`
MyDialog006=`000,000,000,000,MENUITEM,"mn_MyD_ContextmenuTwo","pb_MyD_RightClickMe!","Context menu Two",DEFAULT,5,DEFAULT`
MyDialog007=`000,000,000,000,MENUITEM,"mn_MyD_MenuItemOne","mb_MyD_MENUBAR","Menu Item One",DEFAULT,7,DEFAULT`
MyDialog008=`000,000,000,000,MENUITEM,"mn_MyD_SubMenuItemOne","mn_MyD_MenuItemOne","SubMenu Item One",DEFAULT,8,DEFAULT`
MyDialog009=`000,000,000,000,MENUITEM,"mn_MyD_MenuItemTwo","mb_MyD_MENUBAR","Menu Item Two",DEFAULT,9,DEFAULT`
MyDialog010=`000,000,000,000,MENUITEM,"mn_MyD_SubMenuItemTwo","mn_MyD_MenuItemTwo","SubMenu Item Two",DEFAULT,10,DEFAULT`

ButtonPushed=Dialog("MyDialog")


Exit

:Load_Routines



#DefineSubRoutine MyDialogCallbackProc(MyD_Handle,DMsg,DCID,DEInfo,ChangeInfo)

Switch (DMsg)
    Case msg_init                 ; Dialog Initialization
    DialogProcOptions(MyD_Handle, msg_timer,0)                            ; TimerEvent (0- Off).
    DialogProcOptions(MyD_Handle, msg_closevia49,1)                       ; Close selected (IntControl(49....) (1-On, 0-Off).
    DialogProcOptions(MyD_Handle, dpo_disablestate,0)                     ; Dialog Disable (1-Disable, 2-Wait cursor, 0-Enable).
    DialogProcOptions(MyD_Handle, dpo_changebackground,-1)                ; Change Dialog Background (Bitmap File or RGB String).
    DialogProcOptions(MyD_Handle, msg_buttonpushed,1)                     ; PushButton/PictureButton.
    DialogProcOptions(MyD_Handle, msg_menuitem,1)                         ; MENUItem.
    DialogProcOptions(MyD_Handle, msg_menuiteminit,1)                     ; MENUItemInit.
    Break
  Case msg_timer                ; TimerEvent
    Break
  Case msg_closevia49           ; Close   
    Return 9
    Break
  Case msg_menuiteminit             ; Check Box 
    If DCID == 'mn_MyD_MenuItemOne' Then
      DialogControlSet(MyD_Handle,"mn_MyD_SubMenuItemOne",dc_title,"Thanks for Selecting my Parent...I've changed my Title")
    EndIf
    Break
  Case msg_menuitem             ; Check Box 
    Switch(DialogProcOptions(MyD_Handle,dpo_getnumber,DCID))
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_ContextMenuOne")
        Message("You clicked...","'mn_MyD_ContextMenuOne' with menu text of 'ContextMenuOne'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_SubcontextMenuOne")
        Message("You clicked...","'mn_MyD_SubcontextMenuOne' with menu text of 'SubcontextMenuOne'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_ContextmenuTwo")
        Message("You clicked...","'mn_MyD_ContextmenuTwo' with menu text of 'ContextmenuTwo'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_MenuItemOne")
        Message("You clicked...","'mn_MyD_MenuItemOne' with menu text of 'MenuItemOne'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_SubMenuItemOne")
        Message("You clicked...","'mn_MyD_SubMenuItemOne' with menu text of 'SubMenuItemOne'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_MenuItemTwo")
        Message("You clicked...","'mn_MyD_MenuItemTwo' with menu text of 'MenuItemTwo'")
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"mn_MyD_SubMenuItemTwo")
        Message("You clicked...","'mn_MyD_SubMenuItemTwo' with menu text of 'SubMenuItemTwo'")
        Break
    EndSwitch
    Break
  Case msg_buttonpushed         ; PushButtion
    Switch(DialogProcOptions(MyD_Handle,dpo_getnumber,DCID))
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"pb_MyD_RightClickMe!")
        nSelection = DialogControlGet(MyD_Handle,"pb_MyD_RightClickMe!",dc_title)
        Pause('Notice','You Left-Clicked the button')
        Break
      Case DialogProcOptions(MyD_Handle,dpo_getnumber,"pb_MyD_Cancel")
        nSelection = DialogControlGet(MyD_Handle,"pb_MyD_Cancel",dc_title)
        Return -1
        Break
    EndSwitch
    Break
EndSwitch
Return -2

#EndSubRoutine
 

#DefineSubRoutine Init_Dialog_Constants()

   MSG_INIT               = 0    ; The one-time initilization
   MSG_TIMER              = 1    ; Timer event
   MSG_BUTTONPUSHED       = 2    ; Pushbutton or Picturebutton
   MSG_RADIOPUSHED        = 3    ; Radiobutton clicked
   MSG_CHECKBOX           = 4    ; Checkbox clicked
   MSG_EDITBOX            = 5    ; Editbox or Multilinebox
   MSG_FILESELECT         = 6    ; Filelistbox
   MSG_ITEMSELECT         = 7    ; Itembox
   MSG_COMBOCHANGE        = 8    ; Combobox/Droplistbox
   MSG_CALENDAR           = 9    ; Calendar date change
   MSG_SPINNER            = 10   ; Spinner number change
   MSG_CLOSEVIA49         = 11   ; Close clicked (Enabled via Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK = 12   ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK = 13   ; Get double-click message on an ItemBox
   MSG_COMEVENT           = 14   ; Get double-click message on an ItemBox
   MSG_MENUITEM           = 15   ; MenuItem selected
   MSG_MENUITEMINIT       = 16   ; MenuItem initialized
   MSG_RESIZE             = 17   ; Dialog resized
   MSG_RVITEMSELROW       = 18   ; Reportview item select row
   MSG_RVDBLCLICKROW      = 19   ; Reportview double-click row
   MSG_RVCHECKEDITEM      = 20   ; Reportview checked/unchecked Item
   MSG_RVITEMTEXT         = 21   ; Reportview item text
   MSG_RVHEADER           = 22   ; Reportview header clicked

   DPO_DISABLESTATE       = 1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog
   DPO_CHANGEBACKGROUND   = 1001 ; -1=GetSetting otherise bitmap or color string
   DPO_CHANGESYSMENU      = 1002 ; -1=Get Current 0=none 1=close 2=close/min 3=close/max 4=close/min/max
   DPO_CHANGETITLE        = 1003 ; -1=Get Current otherise new title
   DPO_GETNAME            = 1004 ;  Returns the name associated with a control's number.
   DPO_GETNUMBER          = 1005 ;  Returns the number associated with a control's name.
   DPO_GETCLIENTAREA      = 1007 ;  Returns the number associated with a control's name.


   ;DialogControlState Constants
   DCSTATE_SETFOCUS       = 1      ; Give Control Focus
   DCSTATE_QUERYSTYLE     = 2      ; Query control's style
   DCSTATE_ADDSTYLE       = 3      ; Add control style
   DCSTATE_REMOVESTYLE    = 4      ; Remove control style
   DCSTATE_GETFOCUS       = 5      ; Get control that has focus
   DCSTATE_MOVEMOUSEOVER  = 6      ; Move the mouse over the control

   DCSTYLE_INVISIBLE      = 1      ; Set Control Invisible
   DCSTYLE_DISABLED       = 2      ; Set Control Disabled
   DCSTYLE_NOUSERDATA     = 4      ; Note: Setable via DialogControlState function ONLY SPINNER control only
   DCSTYLE_READONLY       = 8      ; Sets control to read-only (user cannot type in data) EDITBOX MULTILINEBOX SPINNER
   DCSTYLE_PASSWORD       = 16     ; Sets 'password mode' where only *'s are displayed EDITBOX
   DCSTYLE_DEFAULTBUTTON  = 32     ; Sets a button as a the default button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_DIGITSONLY     = 64     ; Set edit box to accept digits only EDITMOX MULTILINEBOX
   DCSTYLE_FLAT           = 128    ; Makes a 'flat' hyperlink-looking button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_HEIGHT         = 256    ; Turns off automatic height adjustment on ItemBoxes and FileListBoxes
   DCSTYLE_CENTER         = 512    ; Center Text in VARYTEXT and STATICTEXT Controls
   DCSTYLE_RIGHT          = 1024   ; Right Justify Text in VARYTEXT and STATICTEXT Controls
   DCSTYLE_NOSELCURLEFT   = 2048   ; No selection, cursor left EDITBOX MULTILINEBOX
   DCSTYLE_NOSELCURRIGHT  = 4096   ; No selection, cursor right EDITBOX MULTILINEBOX
   DCSTYLE_NOSELCURRIGHT  = 4096   ; No selection, cursor right EDITBOX MULTILINEBOX
   DCSTYLE_SHIELD         = 8192   ; Display Security Shield icon on button (Vista only) PUSHBUTTON PICTUREBUTTON
   DCSTYLE_MENUCHECK      = 32768  ; Adds a check mark to the left of a menu item MENUITEM
   DCSTYLE_MENURADIO      = 65536  ; Adds a radio button like dot graphic to the left of a menu item MENUITEM
   DCSTYLE_MENUSEP        = 131072 ; Causes a separator bar graphic to display instead of text at the menu item's location in the menu MENUITEM
   DCSTYLE_MENUBREAK      = 262144 ; Cause a column break to occur at the specific item when used with drop-down, context, or submenus.  Causes a line break (new row) with menu items hosted directly by the MENUBAR MENUITEM
   DCSTYLE_NOHEADER       = 524288    ; No header bar REPORTVIEW
   DCSTYLE_COLHEADER      = 1048576   ; First row column header REPORTVIEW
   DCSTYLE_GRIDLINES      = 2097152   ; Grid lines REPORTVIEW
   DCSTYLE_SELONEROW      = 4194304   ; Only one row can be selected at a time REPORTVIEW
   DCSTYLE_SELALLROW      = 8388608   ; Highlight complete row REPORTVIEW
   DCSTYLE_SORTASC        = 16777216  ; Ascending sort REPORTVIEW
   DCSTYLE_SORTDESC       = 33554432  ; Descending sort REPORTVIEW
   DCSTYLE_EDITCOL        = 67108864  ; Edit first columns text REPORTVIEW
   DCSTYLE_COLCHECKBOX    = 134217728 ; Add checkbox to first column REPORTVIEW
   DCSTYLE_INSHEADER=268435456   ; Include column header text REPORTVIEW



   ;DialogControlSet / DialogControlGet Constants
   DC_CHECKBOX            = 1    ; CHECKBOX
   DC_RADIOBUTTON         = 2    ; RADIOBUTTON
   DC_EDITBOX             = 3    ; EDITBOX MULTILINEBOX
   DC_TITLE               = 4    ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON
   DC_ITEMBOXCONTENTS     = 5    ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXSELECT       = 6    ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_CALENDAR            = 7    ; CALENDAR
   DC_SPINNER             = 8    ; SPINNER
   DC_MULTITABSTOPS       = 9    ; MULTILINEBOX
   DC_ITEMSCROLLPOS       = 10   ; ITEMBOX FILELISTBOX
   DC_BACKGROUNDCOLOR     = 11   ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_PICTUREBITMAP       = 12   ; PICTURE PICTUREBUTTON
   DC_TEXTCOLOR           = 13   ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_ITEMBOXADD          = 14   ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXREMOVE       = 15   ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_RADIOCONTROL        = 16   ; RADIOBUTTON
   DC_POSITION            = 17   ; RADIOBUTTON
   DC_MENUNAMES           = 18   ; ALL CONTROLS
   DC_HANDLE              = 19   ; ALL CONTROLS (Except MENUBAR and MENUITEM)
   DC_RVCOLHEAD           = 20   ; REPORTVIEW
   DC_RVCOLWIDTH          = 21   ; REPORTVIEW
   DC_RVCOLMATCH          = 24   ; REPORTVIEW
   DC_RVCANCELEDIT        = 25   ; REPORTVIEW
   DC_RVCHECKEDROWS       = 26   ; REPORTVIEW
   DC_RVJUSTIFY           = 27   ; REPORTVIEW

   ;DialogObject constants
   
   DLGOBJECT_ADDEVENT     = 1    ; Call dialog callback when the specified event occurs 
   DLGOBJECT_REMOVEEVENT  = 2    ; Stop calling dialog callback when an event previously requested with 
   DLGOBJECT_GETOBJECT    = 3    ; Return an object references to the specified control
   DLGOBJECT_GETPICOBJECT = 4    ; Create and return an object reference to a picture object

   ;Return code constants
   RET_DO_CANCEL          =  0   ; Cancels dialog
   RET_DO_DEFAULT         = -1   ; Continue with default processing for control
   RET_DO_NOT_EXIT        = -2   ; Do not exit the dialog

#EndSubRoutine


Return
Title: Re: Menu Item Initialization
Post by: George Vagenas on August 10, 2013, 11:47:18 PM
Okay, thanks.  I've had dialogs where I've changed the titles of controls in response to user input, might want to do the same with menus at some point.