Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Pre-requisites for this tutorial: All about Dynamic Dialogs 6.2
NOTE: If you are unfamiliar with WIL Dialog code and Dialog Callback Procedures, you should start with that tutorial first.
'Menu' support was added to WIL Dialogs starting in WinBatch version 2009C. WIL Dialogs support both dropdown and context menus. The WIL Dialog Menu Editor is now provided with the WIL Dialog Editor.
Two WIL Dialog "control types" were added to provide support for menus in WIL dialogs: MENUBAR and MENUITEM.
A MENUBAR is a horizontal bar that appears at the top of your dialog just below the title bar. A menu bar contains menu items. Generally, menu items displayed in the menu bar cause dropdown menus to be displayed when selected by the user. A WIL Dialog with a menu bar looks something like this:
When the mouse is positioned over one of the menu items on the menu bar, a dropdown menu will appear.
The WIL source code for this 'Sample Menubar' dialog looks like this:
MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`Sample Menubar` MyDialogX=-1 MyDialogY=-1 MyDialogWidth=180 MyDialogHeight=120 MyDialogNumControls=013 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`043,097,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`091,097,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,029,156,038,STATICTEXT,"StaticText_1",DEFAULT,"A MENUBAR is a horizontal bar that appears at the top of your dialog just below the title bar. A menu bar contains menu items. Generally, menu items displayed in the menu bar cause dropdown menus to be displayed when selected by the user.",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`000,000,000,000,MENUBAR,"Dialog_Bar"` MyDialog005=`000,000,000,000,MENUITEM,"mbi_Run","Dialog_Bar","Run",DEFAULT,20,0` MyDialog006=`000,000,000,000,MENUITEM,"mbi_Notepad","mbi_Run","Notepad",DEFAULT,10,0` MyDialog007=`000,000,000,000,MENUITEM,"mbi_Calc","mbi_Run","Calculator",DEFAULT,20,0` MyDialog008=`000,000,000,000,MENUITEM,"mbi_Services","mbi_Run","Services",DEFAULT,30,0` MyDialog009=`005,015,160,062,GROUPBOX,"GroupBox_1",DEFAULT,"MENUBAR",DEFAULT,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`000,000,000,000,MENUITEM,"mbi_Favorites","Dialog_Bar","Favorites",DEFAULT,10,DEFAULT` MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT` MyDialog012=`000,000,000,000,MENUITEM,"mbi_MSDN","mbi_Favorites","msdn.microsoft.com",DEFAULT,30,DEFAULT` MyDialog013=`000,000,000,000,MENUITEM,"mbi_Techdb","mbi_Favorites","techsupt.winbatch.com",DEFAULT,20,DEFAULT` ButtonPushed = Dialog("MyDialog")
A MENUITEM can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.
When the user right clicks on any empty space in a WIL Dialog a context menu will appear:
When the user right clicks on a control (PUSHBUTTON) in a WIL Dialog and context menu appears over that button control:
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.
Dialog dropdown context menu code:
MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT`
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 key word 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.
Dialog context menu code:
MyDialog014=`000,000,000,000,MENUITEM,"cmi_MainContextMenu",DEFAULT,"Main Menu",DEFAULT,10,DEFAULT`
Dialog control context menu code:
MyDialog015=`000,000,000,000,MENUITEM,"cmi1_PushButton_OK","PushButton_OK","OK Button - Context Menu",DEFAULT,10,DEFAULT`
The WIL source code for this 'Sample MenuItem' dialog looks like this:
MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`Sample MenuItem` MyDialogX=-01 MyDialogY=-01 MyDialogWidth=180 MyDialogHeight=120 MyDialogNumControls=015 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`043,097,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`091,097,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,029,156,038,STATICTEXT,"StaticText_1",DEFAULT,"A MenuItem can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`000,000,000,000,MENUBAR,"Dialog_Bar"` MyDialog005=`000,000,000,000,MENUITEM,"mbi_Run","Dialog_Bar","Run",DEFAULT,20,0` MyDialog006=`000,000,000,000,MENUITEM,"mbi_Notepad","mbi_Run","Notepad",DEFAULT,10,0` MyDialog007=`000,000,000,000,MENUITEM,"mbi_Calc","mbi_Run","Calculator",DEFAULT,20,0` MyDialog008=`000,000,000,000,MENUITEM,"mbi_Services","mbi_Run","Services",DEFAULT,30,0` MyDialog009=`005,015,160,062,GROUPBOX,"GroupBox_1",DEFAULT,"MENUITEM",DEFAULT,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`000,000,000,000,MENUITEM,"mbi_Favorites","Dialog_Bar","Favorites",DEFAULT,10,DEFAULT` MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT` MyDialog012=`000,000,000,000,MENUITEM,"mbi_MSDN","mbi_Favorites","msdn.microsoft.com",DEFAULT,30,DEFAULT` MyDialog013=`000,000,000,000,MENUITEM,"mbi_Techdb","mbi_Favorites","techsupt.winbatch.com",DEFAULT,20,DEFAULT` MyDialog014=`000,000,000,000,MENUITEM,"cmi_MainContextMenu",DEFAULT,"Main Menu",DEFAULT,10,DEFAULT` MyDialog015=`000,000,000,000,MENUITEM,"cmi1_PushButton_OK","PushButton_OK","OK Button - Context Menu",DEFAULT,10,DEFAULT` ButtonPushed=Dialog("MyDialog")
The WIL Dialog Menu Editor can be used to create a dialog with menus. The WIL Dialog Menu Editor is now provided along with the WIL Dialog Editor.
First you should familiarize yourself with the WIL Dialog Editor.
Using the WIL Dialog Editor is easy. These steps offer a general overview for using the Dialog Editor as well as a quick way to become comfortable with dialog box construction.
1. Run the Dialog Editor: Start Menu | Programs | WinBatch | WIL Dialog Editor.
2. Familiarize yourself with the standard menus in this program: FILE, EDIT, VIEW, INSERT, ALIGN, TEST and HELP.
3. Give your dialog box a name.
4. Decide the size of your dialog box.
5. Add a control, i.e. an OK button.
6. Save your dialog box.
Once you have become comfortable working with the WIL Dialog Editor you can begin creating menus using the WIL Dialog Menu Editor.
To access the WIL Dialog Menu Editor, you must have the WIL Dialog Editor open. Under the VIEW menu you will see the menu selection 'Menu Editor'. Or you can right click anywhere inside your dialog in the WIL Dialog Editor and select 'Menu Editor...'
Near the upper left hand corner of the Menu Editor you will see a set of radio buttons. These radio buttons allow you to specify the type of menu you would like to create. You have two options: Menu Bar or Context. The Menu Bar radio button allows you to create a horizontal bar that appears at the top of your dialog just below the title bar. The Context radio button allows you to create a menu that gets displayed when a user right clicks on either a blank space in the Dialog or when they right-click on a specific control.
Once you have chosen your menu type you can then provide the Name, Text and Parent of your menu item.
The following explains the meaning and operation of each control in the Menu Editor dialog.
Menu Type
The two Menu Type radio buttons allow you to choose between editing the menus associated with the menu bar and the menus associated with your dialogs default context menu.
Menu Bar select to edit your dialog's menu bar menu items
Context select to edit your dialog's default context menu items
Note: The Menu Type group is enabled only for editing your main dialogs menus. Since controls only have a context menu, this group is not enabled.
Type
This read-only text indicates the control type of the currently selected menu control. It can display either MENUBAR or a
MENUITEM.
Name
This control is used to display and edit the control name attribute associated with the currently selected menu bar or menu item. The name is used to set the hierarchical relationship between menus and submenus. It is also used as the third parameter to your user-defined callback procedure on menu selection when you are processing menu events in your callback.
Text
This is the caption displayed by a menu item menu when its associated menu is displayed. You can add an access key for the menu item by placing an ampersand (&) immediately before the character in the caption. The access key will cause the menu item's selection while its hosting menu is visible. This attribute can also be used to associate a short-cut key with the menu item. This is done by appending a single backslash (\) to the caption followed by a key sequence. Use the key representations established for the SendKey function. The key sequence will automatically be converted to the system's current key representations when it is displayed next to the menu's caption in your dialog. Unlike an access key, a user can select a menu item using a hot-key combination even when the menu item and its menu are not displayed.
Note: Short-cut key combination should not be used with menu items that display dropdown menus or submenus. It is not considered good UI design and the menu caption my not display correctly.
Parent
The name of the selected menu item's parent or host is displayed here. The Parent name can be the name attribute for a regular control, the menu bar, another menu item, or the DEFAULT key word when the menu item is a top level menu item of your dialog's context menu. The arrow buttons are used to change a menu items Parent attribute.
Menu Styles
The check boxes in this group set the menu styles for the currently selected menu item.
Invisible the menu item is not displayed by its menu.
Disabled the menu item has the disabled appearance and does not generate a menu event.
Separator the menu item is displayed as a separator bar. The menu item's text is ignored.
Row Break the menu item starts a new row on the menu bar or a new column on other menus
Check the menu item displays a check mark to the left of the item's text
Radio the menu item displays a dot to the left of the item's text
Note: if both the check and radio style are selected, the check style will take precedence.
Left Arrow
Press this button to decrease the menu level of the currently selected menu. When the menu level is decreased the menu item may because a part of a different menu in the hierarchy. A change to the menu's relative position in the menu hierarchy will cause a change in the menu item's Parent name attribute.
Right Arrow
Use this button to increase the menu level of the selected menu item. Increasing the menu level can cause the selected menu item to be the start of a new submenu or dropdown menu. Any change to the menu's relative position in the menu hierarchy will be reflected in the menu item's Parent name attribute.
Up Arrow
You can move the selected menu item up in the display order with this button. Depending on the menu items current level and the level of surrounding menu items, moving a menu item up can also cause a change in the menu items menu membership. Any change in menu membership is reflected in the Parent name attribute and the position change is reflected in the Position attribute.
Down Arrow
This arrow button moves the selected menu item down in the display order. When a menu item is moved it can cause both a change in the Position attribute and a change in the Parent name attribute. A change to the Parent name attribute also changes the menu that displays the menu item.
New
This button creates a new menu item or the menu bar in the menu list. If a menu item is already selected, the new menu item will have the same menu level as the selected item. It will also be position just below the selected menu item. If the Menu Bar radio button is selected and the dialog does not already have a menu bar, a menu bar is created the first time this button is pressed.
Delete
Press this button to remove the selected menu item from menu item list. If the menu bar is selected the entire menu hierarchy is deleted. Deleted items are not removed from your dialog's template until either the Menu Type radio button selection is changed or the OK button is pressed.
Menu List View
The Menu List View is a two column list representing the menu bar and its menu items or the menu items of a context menu. The first column shows a menu item's caption and the second column shows the name of a menu item or the menu bar. Selecting an item from the list allows you to edit the attributes for that menu control.
The indentation level of the menu item in the Menu List View determines whether the menu item causes a menu command event or causes another menu to be displayed.
A menu item that appears flush left in the list is displayed when the context menu is displayed. These menu items can either cause a menu command event or a submenu, depending on the level of subsequent menu items.
The menu items indented one level are displayed on the menu bar. These menu items are best used to display dropdown menus.
A menu item indented more than the preceding menu item is displayed on a submenu or dropdown menu when the user clicks the preceding menu item.
A menu item followed by menu items that are further indented displays a submenu or a dropdown menu. The further indented items become menu items of that submenu or dropdown menu.
OK
Choose this button to verify and save changes to your dialog template before exiting the Menu Editor dialog.
Cancel
Choose this button to exit the Menu Editor dialog without saving changes.
Once you have created your custom WIL Dialog with menus in the WIL Dialog Editor you should save the dialog code to a .WBT script file. This can be accomplished by selecting the 'File | Save to Clipboard' menu in the WIL Dialog Editor. The entire source code for your dialog is now being stored in the clipboard. Simply paste the contents of the clipboard into a .WBT file within WinBatch Studio.
For this tutorial simply save the WIL Dialog code below as MyDialog.wbt The code will look something like this:
MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`Sample MenuItem` MyDialogX=-01 MyDialogY=-01 MyDialogWidth=180 MyDialogHeight=120 MyDialogNumControls=015 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`043,097,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`091,097,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,029,156,038,STATICTEXT,"StaticText_1",DEFAULT,"A MenuItem can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`000,000,000,000,MENUBAR,"Dialog_Bar"` MyDialog005=`000,000,000,000,MENUITEM,"mbi_Run","Dialog_Bar","Run",DEFAULT,20,0` MyDialog006=`000,000,000,000,MENUITEM,"mbi_Notepad","mbi_Run","Notepad",DEFAULT,10,0` MyDialog007=`000,000,000,000,MENUITEM,"mbi_Calc","mbi_Run","Calculator",DEFAULT,20,0` MyDialog008=`000,000,000,000,MENUITEM,"mbi_Services","mbi_Run","Services",DEFAULT,30,0` MyDialog009=`005,015,160,062,GROUPBOX,"GroupBox_1",DEFAULT,"MENUITEM",DEFAULT,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`000,000,000,000,MENUITEM,"mbi_Favorites","Dialog_Bar","Favorites",DEFAULT,10,DEFAULT` MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT` MyDialog012=`000,000,000,000,MENUITEM,"mbi_MSDN","mbi_Favorites","msdn.microsoft.com",DEFAULT,30,DEFAULT` MyDialog013=`000,000,000,000,MENUITEM,"mbi_Techdb","mbi_Favorites","techsupt.winbatch.com",DEFAULT,20,DEFAULT` MyDialog014=`000,000,000,000,MENUITEM,"cmi_MainContextMenu",DEFAULT,"Main Menu",DEFAULT,10,DEFAULT` MyDialog015=`000,000,000,000,MENUITEM,"cmi_PushButton_OK","PushButton_OK","OK Button - Context Menu",DEFAULT,10,DEFAULT` ButtonPushed=Dialog("MyDialog")
Now that we have a WIL Dialog with menus, we need to write the code to handle these menus. This can be accomplished by writing/generating a Dialog Callback Procedure. The easiest way to accomplish this is:
To highlight the entire WIL Dialog code in WinBatch Studio.
Right-click then select 'Code Blocks | Create Dialog Callbacks in Clipboard | Function with Constants'.
Now all of the necessary Dialog Callback Procedure code is written and stored to the clipboard. Paste the contents of the clipboard into you script just before the Dialog code. The code will now look something like this:
;============================================================ ;============================================================ ;============================================================ #DefineSubRoutine InitDialogConstants() ;DialogprocOptions Constants MSG_INIT=0 ; The one-time initialization 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 DialogProcOptions 1002 MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox MSG_COMEVENT=14 ; COMCONTROL Event notification from DialogObject (NOT DialogProcOptions) MSG_MENUITEM=15 ; MenuItem selected MSG_MENUITEMINIT=16 ; MenuItem initialized DPO_DISABLESTATE=1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog DPO_CHANGEBACKGROUND=1001 ; -1=Get Current 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 ; Set/Get Dialog Title - (-1 to get) DPO_GETNAME=1004 ; Returns the name associated with a control's number. DPO_GETNUMBER=1005 ; 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_DEFAULT=0 ; Set Default Style 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 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_NOADJUST=256 ; Turns off auto-height adjustment ITEMBOX FILELISTBOX DCSTYLE_TEXTCENTER=512 ; Center text in control VARYTEXT STATICTEXT DCSTYLE_TEXTRIGHT=1024 ; Flush-Right text in control VARYTEXT STATICTEXT DCSTYLE_NOSELCURLEFT=2048 ; No selection, cursor left 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 ; Separator bar graphic MENUITEM DCSTYLE_MENUBREAK=262144 ; column break MENUBAR ;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 MENUITEM 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_RADIOVALUE=16 ; RADIOBUTTON DC_POSITION=17 ; ALL CONTROLS (Except MENUBAR and MENUITEM) DC_MENUNAMES=18 ; ALL CONTROLS DC_HANDLE=19 ; ALL CONTROLS (Except MENUBAR and MENUITEM) ;DialogObject constants DLGOBJECT_ADDEVENT=1 ; Call dialog callback when the specified event occurs DLGOBJECT_STOPEVENT=2 ; Stop calling dialog callback when an event previously requested with DLGOBJECT_GETOBJECT=3 ; Return an object references to the specified control DLGOBJECT_GETPICTURE=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 Return #EndSubRoutine ;============================================================ ;============================================================ ;============================================================ #DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd) InitDialogConstants() ; Initialize Dialog Constants 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_TIMER,1000) ; DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) ; DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@TRUE) Return(RET_DO_DEFAULT) ; case MSG_BUTTONPUSHED ; if MyDialog_Name == "PushButton_OK" ; OK ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "PushButton_Cancel" ; Cancel ; return(RET_DO_DEFAULT) ; endif ; MyDialog_Name ; return(RET_DO_DEFAULT) ; case MSG_MENUITEM ; if MyDialog_Name == "mbi_Run" ; Dialog_Bar Run ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Services" ; mbi_Run Services ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "cmi_MainContextMenu" ; Main Menu ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu ; return(RET_DO_DEFAULT) ; endif ; MyDialog_Name ; return(RET_DO_DEFAULT) EndSwitch ; MyDialog_Message Return(RET_DO_DEFAULT) #EndFunction ; End of Dialog Callback MyDialogCallbackProc ;============================================================ ;============================================================ ;============================================================ MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`Sample MenuItem` MyDialogX=-01 MyDialogY=-01 MyDialogWidth=180 MyDialogHeight=120 MyDialogNumControls=015 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`043,097,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`091,097,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,029,156,038,STATICTEXT,"StaticText_1",DEFAULT,"A MenuItem can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`000,000,000,000,MENUBAR,"Dialog_Bar"` MyDialog005=`000,000,000,000,MENUITEM,"mbi_Run","Dialog_Bar","Run",DEFAULT,20,0` MyDialog006=`000,000,000,000,MENUITEM,"mbi_Notepad","mbi_Run","Notepad",DEFAULT,10,0` MyDialog007=`000,000,000,000,MENUITEM,"mbi_Calc","mbi_Run","Calculator",DEFAULT,20,0` MyDialog008=`000,000,000,000,MENUITEM,"mbi_Services","mbi_Run","Services",DEFAULT,30,0` MyDialog009=`005,015,160,062,GROUPBOX,"GroupBox_1",DEFAULT,"MENUITEM",DEFAULT,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`000,000,000,000,MENUITEM,"mbi_Favorites","Dialog_Bar","Favorites",DEFAULT,10,DEFAULT` MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT` MyDialog012=`000,000,000,000,MENUITEM,"mbi_MSDN","mbi_Favorites","msdn.microsoft.com",DEFAULT,30,DEFAULT` MyDialog013=`000,000,000,000,MENUITEM,"mbi_Techdb","mbi_Favorites","techsupt.winbatch.com",DEFAULT,20,DEFAULT` MyDialog014=`000,000,000,000,MENUITEM,"cmi_MainContextMenu",DEFAULT,"Main Menu",DEFAULT,10,DEFAULT` MyDialog015=`000,000,000,000,MENUITEM,"cmi_PushButton_OK","PushButton_OK","OK Button - Context Menu",DEFAULT,10,DEFAULT` ButtonPushed=Dialog("MyDialog")
Don't worry, this code seems intimidating at first, but you will get used to it. Basically, a Dialog Callback is simply a User Defined Function or Subroutine block that instructs WinBatch what to do when a user clicks in a dialog. Although it is possible to write all the Dialog Callback Procedure by hand, it gets exceedingly tedious very quickly. Furthermore, most Dialog Callback Procedure code has the same basic structure and most of the Dialog control functions have dozens of hard to remember request codes. Hence, an automatic Dialog Callback Procedure code generator has been added to WinBatch Studio. It will define a WHOLE bunch of useful constants and it will also generate a useful block of template code based on your dialog.
How does the Dialog know which Dialog callback UDF to call?
This line in the WIL dialog tells WinBatch to call the UserDefinedFunction named 'MyDialogCallbackProc'
MyDialogProcedure=`MyDialogCallbackProc`
Note: If this line in your Dialog doesn't have a procedure defined make sure to set it to 'MyDialogCallbackProc'.
Every Dialog Callback Procedure takes the same five parameters:
#DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd)
The parameters are:
MyDialog_Handle: A special
number that refers to the dialog. This number will be used later in subsequent
calls to various Dialog support functions.
MyDialog_Message: Another number.
This number is designed to allow your Dialog procedure to figure out what
is going on and why it was called. By default, your Dialog procedure will
be called once, with a MyDialog_Message value of zero. The idea is that
your code will request further services from WinBatch in regards to your
dialog.
MyDialog_Name: The name of
the control that caused a requested event to be directed to your Dialog
Procedure. This can be used, for example, to determine what pushbutton
a user may have clicked on or what radio button has been selected.
MyDialog_EventInfo: The event
information object (valid only when event-code = 14)
rsvd: This parameter is reserved.
The switch statement inside the Dialog Callback Procedure is the heart and soul. There is one case statement for each different type of 'message' that a Dialog can receive. Initially, the only message enabled by default is the MSG_INIT initialization message. When the Dialog Callback Procedure starts up, the Dialog Callback Procedure gets one chance to tell WinBatch what messages it wants to handle. Specifically the DialogProcOptions function is used to tell the dialog what messages to handle. In this case, we would like to handle both Button Pushed messages and Menu Item Selection messages. Simply uncomment those DialogProcOptions statements:
#DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd) InitDialogConstants() ; Initialize Dialog Constants 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_TIMER,1000) DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@TRUE) Return(RET_DO_DEFAULT) ; case MSG_BUTTONPUSHED ; if MyDialog_Name == "PushButton_OK" ; OK ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "PushButton_Cancel" ; Cancel ; return(RET_DO_DEFAULT) ; endif ; MyDialog_Name ; return(RET_DO_DEFAULT) ; case MSG_MENUITEM ; if MyDialog_Name == "mbi_Run" ; Dialog_Bar Run ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Services" ; mbi_Run Services ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "cmi_MainContextMenu" ; Main Menu ; return(RET_DO_DEFAULT) ; elseif MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu ; return(RET_DO_DEFAULT) ; endif ; MyDialog_Name ; return(RET_DO_DEFAULT) EndSwitch ; MyDialog_Message Return(RET_DO_DEFAULT) #EndFunction ; End of Dialog Callback MyDialogCallbackProc
By uncommenting those lines you are telling WinBatch to call this Dialog Callback Procedure anytime the user pushes a button or selects a menu item.
Now you must create Case statements that handle each of these individual messages. In this example you can simply uncomment the case MSG_BUTTONPUSHED and case MSG_MENUITEM sections of code:
#DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd) InitDialogConstants() ; Initialize Dialog Constants 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_TIMER,1000) DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@TRUE) Return(RET_DO_DEFAULT) Case MSG_BUTTONPUSHED ;<------------------- If MyDialog_Name == "PushButton_OK" ; OK Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "PushButton_Cancel" ; Cancel Return(RET_DO_DEFAULT) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT) Case MSG_MENUITEM ;<------------------- If MyDialog_Name == "mbi_Run" ; Dialog_Bar Run Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_Services" ; mbi_Run Services Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "cmi_MainContextMenu" ; Main Menu Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu Return(RET_DO_DEFAULT) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT) EndSwitch ; MyDialog_Message Return(RET_DO_DEFAULT) #EndFunction ; End of Dialog Callback MyDialogCallbackProc
Next lets change what happens when a user presses the CANCEL button. We need to tell the Dialog Callback Procedure that we would like the script to exit. This can be accomplished by changing the return value from RET_DO_DEFAULT to RET_DO_CANCEL:
Case MSG_BUTTONPUSHED If MyDialog_Name == "PushButton_OK" ; OK Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "PushButton_Cancel" ; Cancel Return(RET_DO_CANCEL) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT)
For this example we will just leave the OK button processing alone.
Now we are set to start handling menu item selections in the Dialog Callback procedure. First I recommend addressing each 'return' value for each menu option. By default they are all set to RET_DO_DEFAULT. This return value tells the dialog to exit and return to default processing. We would like to leave the dialog on the screen for the user, after they select a menu item, so we should change the return values for each menu item to RET_DO_NOT_EXIT:
Case MSG_MENUITEM If MyDialog_Name == "mbi_Run" ; Dialog_Bar Run Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Services" ; mbi_Run Services Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu Return(RET_DO_NOT_EXIT) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT)
Now we can start coding, what we want to happen, when a user selects each menu item. Lets start with the main Context menu. The main context menu for this Dialog is activated by right-clicking the 'empty' client area of this dialog. For this example we want to display a message to the user that notifies them what this script is used for. The code would look something like this:
ElseIf MyDialog_Name == "cmi_MainContextMenu" ; Main Menu Message('Hello','This is a sample script with menus that allows you to launch some useful tools') Return(RET_DO_NOT_EXIT)
For the rest of the menu options we are going to add ShellExecute statements to launch the various tools...
Case MSG_MENUITEM If MyDialog_Name == "mbi_Run" ; Dialog_Bar Run Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad ShellExecute('notepad.exe', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator ShellExecute('calc.exe', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Services" ; mbi_Run Services ShellExecute('mmc.exe', DirWindows(1):'services.msc', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com ShellExecute('http://www.winbatch.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com ShellExecute('http://msdn.microsoft.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com ShellExecute('http://techsupt.winbatch.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu Return(RET_DO_NOT_EXIT) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT)
Now all that is left is to define what you want to happen if the user right-clicks on the OK button control. Lets add a message that tells the user what the button does...
ElseIf MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu Message('Notice','Pressing this button will cause the dialog to close and the script to continue default processing.') Return(RET_DO_NOT_EXIT)
Here is what the completed code should look like:
;============================================================ ;============================================================ ;============================================================ #DefineSubRoutine InitDialogConstants() ;DialogprocOptions Constants MSG_INIT=0 ; The one-time initialization 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 DialogProcOptions 1002 MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox MSG_COMEVENT=14 ; COMCONTROL Event notification from DialogObject (NOT DialogProcOptions) MSG_MENUITEM=15 ; MenuItem selected MSG_MENUITEMINIT=16 ; MenuItem initialized DPO_DISABLESTATE=1000 ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog DPO_CHANGEBACKGROUND=1001 ; -1=Get Current 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 ; Set/Get Dialog Title - (-1 to get) DPO_GETNAME=1004 ; Returns the name associated with a control's number. DPO_GETNUMBER=1005 ; 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_DEFAULT=0 ; Set Default Style 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 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_NOADJUST=256 ; Turns off auto-height adjustment ITEMBOX FILELISTBOX DCSTYLE_TEXTCENTER=512 ; Center text in control VARYTEXT STATICTEXT DCSTYLE_TEXTRIGHT=1024 ; Flush-Right text in control VARYTEXT STATICTEXT DCSTYLE_NOSELCURLEFT=2048 ; No selection, cursor left 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 ; Separator bar graphic MENUITEM DCSTYLE_MENUBREAK=262144 ; column break MENUBAR ;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 MENUITEM 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_RADIOVALUE=16 ; RADIOBUTTON DC_POSITION=17 ; ALL CONTROLS (Except MENUBAR and MENUITEM) DC_MENUNAMES=18 ; ALL CONTROLS DC_HANDLE=19 ; ALL CONTROLS (Except MENUBAR and MENUITEM) ;DialogObject constants DLGOBJECT_ADDEVENT=1 ; Call dialog callback when the specified event occurs DLGOBJECT_STOPEVENT=2 ; Stop calling dialog callback when an event previously requested with DLGOBJECT_GETOBJECT=3 ; Return an object references to the specified control DLGOBJECT_GETPICTURE=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 Return #EndSubRoutine ;============================================================ ;============================================================ ;============================================================ #DefineFunction MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,rsvd) InitDialogConstants() ; Initialize Dialog Constants 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_TIMER,1000) DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) DialogProcOptions(MyDialog_Handle,MSG_MENUITEM,@TRUE) Return(RET_DO_DEFAULT) Case MSG_BUTTONPUSHED If MyDialog_Name == "PushButton_OK" ; OK Return(RET_DO_DEFAULT) ElseIf MyDialog_Name == "PushButton_Cancel" ; Cancel Return(RET_DO_CANCEL) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT) Case MSG_MENUITEM If MyDialog_Name == "mbi_Run" ; Dialog_Bar Run Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Notepad" ; mbi_Run Notepad ShellExecute('notepad.exe', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Calc" ; mbi_Run Calculator ShellExecute('calc.exe', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Services" ; mbi_Run Services ShellExecute('mmc.exe', DirWindows(1):'services.msc', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Favorites" ; Dialog_Bar Favorites Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_WinBatch" ; mbi_Favorites www.winbatch.com ShellExecute('http://www.winbatch.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_MSDN" ; mbi_Favorites msdn.microsoft.com ShellExecute('http://msdn.microsoft.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "mbi_Techdb" ; mbi_Favorites techsupt.winbatch.com ShellExecute('http://techsupt.winbatch.com', '', '', @NORMAL, '') Return(RET_DO_NOT_EXIT) ElseIf MyDialog_Name == "cmi_PushButton_OK" ; PushButton_OK OK Button - Context Menu Message('Notice','Pressing this button will cause the dialog to close and the script to continue default processing.') Return(RET_DO_NOT_EXIT) EndIf ; MyDialog_Name Return(RET_DO_DEFAULT) EndSwitch ; MyDialog_Message Return(RET_DO_DEFAULT) #EndFunction ; End of Dialog Callback MyDialogCallbackProc MyDialogFormat=`WWWDLGED,6.2` MyDialogCaption=`Sample MenuItem` MyDialogX=-01 MyDialogY=-01 MyDialogWidth=180 MyDialogHeight=120 MyDialogNumControls=015 MyDialogProcedure=`MyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`043,097,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`091,097,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`009,029,156,038,STATICTEXT,"StaticText_1",DEFAULT,"A MenuItem can be displayed on a menu bar or as a menu item associated with a drop-down, context menu or submenu.",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog004=`000,000,000,000,MENUBAR,"Dialog_Bar"` MyDialog005=`000,000,000,000,MENUITEM,"mbi_Run","Dialog_Bar","Run",DEFAULT,20,0` MyDialog006=`000,000,000,000,MENUITEM,"mbi_Notepad","mbi_Run","Notepad",DEFAULT,10,0` MyDialog007=`000,000,000,000,MENUITEM,"mbi_Calc","mbi_Run","Calculator",DEFAULT,20,0` MyDialog008=`000,000,000,000,MENUITEM,"mbi_Services","mbi_Run","Services",DEFAULT,30,0` MyDialog009=`005,015,160,062,GROUPBOX,"GroupBox_1",DEFAULT,"MENUITEM",DEFAULT,90,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog010=`000,000,000,000,MENUITEM,"mbi_Favorites","Dialog_Bar","Favorites",DEFAULT,10,DEFAULT` MyDialog011=`000,000,000,000,MENUITEM,"mbi_WinBatch","mbi_Favorites","www.winbatch.com",DEFAULT,10,DEFAULT` MyDialog012=`000,000,000,000,MENUITEM,"mbi_MSDN","mbi_Favorites","msdn.microsoft.com",DEFAULT,30,DEFAULT` MyDialog013=`000,000,000,000,MENUITEM,"mbi_Techdb","mbi_Favorites","techsupt.winbatch.com",DEFAULT,20,DEFAULT` MyDialog014=`000,000,000,000,MENUITEM,"cmi_MainContextMenu",DEFAULT,"Main Menu",DEFAULT,10,DEFAULT` MyDialog015=`000,000,000,000,MENUITEM,"cmi_PushButton_OK","PushButton_OK","OK Button - Context Menu",DEFAULT,10,DEFAULT` ButtonPushed=Dialog("MyDialog") Exit
Now try this process again but this time create your own customized WIL Dialog with menus.
Article ID: W17512
Filename: WIL Dialog - Menu Tutorial.txt
File Created: 2019:08:14:08:51:52
Last Updated: 2019:08:14:08:51:52