WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Tutorials
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Tutorial - Dynamic Dialogs - Format 6.1

WinBatch supports both static dialogs and dynamic dialogs. Both types of dialog are usually drawn with the WinBatch Dialog Editor.

When using a static dialog, the user fills in fields, check various items and makes assorted selections. Then they press some sort of Submit button and the dialog exits and the WinBatch code continues. Outside of standard primitive responses, the dialog does not interact with the user very much outside of accepting the user input.

When using Dynamic Dialogs, there is the potential for a Dialog Procedure written in a special WinBatch User Defined Function or User Defined Subroutine to interact with the user and do any number of actions as the user is progressing through the dialog. Actions might include validating user input, reconfiguring the dialogs, disabling various choices based on prior input, or, actually, almost anything.

The Dialog Editor allows automatic code generation of a standard static dialog. This tutorial covers the steps in transforming such a static dialog into a Dynamic Dialog.

Pre-requisites for this tutorial:A Quick Course on UDFs.

Getting Started

In order to get started with Dynamic Dialogs, we will start with a simple, basic dialog that has a single checkbox and an OK button, as shown on the right. In addition we'll review the various variables that define a dialog, without getting into all the murky detailed explanations that are in the official documentation.

The dialog at the right was made with the Dialog Editor included with WinBatch. The Dialog Editor produced the WinBatch code seen below.

- - - - EXAMPLE A - - - -

EXAFormat=`WWWDLGED,6.1`

EXACaption=`Example A`
EXAX=-1
EXAY=-1
EXAWidth=060
EXAHeight=045
EXANumControls=002
EXAProcedure=`DEFAULT`
EXAFont=`Microsoft Sans Serif|7373|70|34`
EXATextColor=`0|0|128`
EXABackground=`DEFAULT,128|255|255`

EXA001=`004,004,046,011,CHECKBOX,MyCheckBox,"Click Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXA002=`009,022,033,010,PUSHBUTTON,DEFAULT,"OK",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=dialog("EXA")
message("CheckBox Value on Dialog Exit is",MyCheckbox)

First of all, to get familiar with basic dialog code, here is the quick rundown. The EXA is the name of this dialog as specified in the Dialog Editor. It could be anything. In this case it stands for EXample A. The default name produced by the Dialog Editor, if not otherwise specified, is MyDialog. Thus all the dialog variables in this example all start with EXA.
EXAFormat
Used to tell WinBatch what kind of dialogs we are dealing with. These are the version 6.1 dialogs.

EXACaption
Simply specifies the caption or title of the dialog box.

EXAX
Specifies where the upper left corner of the dialog starts in relation to the left edge of the screen. In this case -1 is used to signify that the dialog is to be centered.

EXAY
Specifies where the upper left corner of the dialog starts in relation to the top edge of the screen. In this case -1 is used to signify that the dialog is to be centered.

EXAWidth
Specifies the width of the dialog.

EXAHeight
Specifies the height of the dialog.

EXANumControls
Tells WinBatch how many controls are in the dialog.

EXAProcedure
Specifies the Dialog Procedure. We'll be getting into this below, as this is the essence of this tutorial. When no Dialog Procedure is desired, this value is usually set to 'DEFAULT'.

EXAFont
Defines the default font for the dialog, used if a control does not have its own font specification.

EXATextColor
Defines the default text color, used if a control does not otherwise specify a text color.

EXABackground
Tells WinBatch what background to use for the dialog. It may be either a BMP file or a color.

EXA001
EXA002
etc.
The numbered variables define each of the controls in the dialog. They are difficult to code by hand, hence the Dialog Editor. But, usually, a quick inspection of the data on the line will tell you what control it is defining. You will need to be able to at least tell what control each variable is defining to get your Dynamic Dialogs to work.

ButtonPushed=Dialog("EXA")
Not really a dialog definition variable, but included here for completeness. This is the line that actually tells WinBatch to display the dialog on the screen.





Exercise A

It is obvious that these may be more or less inane exercises, but they only take a few seconds, and studies by seemingly reputable organizations have shown that actually doing the exercises greatly increases long term comprehension of the material. This first exercise is designed to get you familiar with the exercises and to make sure your system is properly set up to do them.

First of all there is one major requirement: A reasonably current version of WinBatch must be installed. 2005A or newer will be sufficient.

  1. Highlight and copy to clipboard the "Example A" WinBatch dialog code shown above.
  2. Run WinBatch Studio and select File/New.
  3. Paste the code into your new WinBatch Studio Window.
  4. Save the code someplace. We recommend that you use the filename "ExampleA.wbt" to help keep things straight.
  5. Hit the "RUN" button on the toolbar.
  6. Note the blue dialog, similar to the one show above appears on the screen,
  7. Note that you can click the check box, and the checked/unchecked state flips back and forth.
  8. Hit the OK button. A message box will appear showing you the state of the checkbox as the dialog was exited.
  9. Hit OK on the message box to exit the program.

Exercise A is complete.





Adding Dialog Procedure code

Basically, to do Dynamic Dialogs, you have to add code, either in a #DefineFunction or a #DefineSubroutine block to instruct WinBatch what to do. Although it is easily possible to write all the Dialog Procedure by hand, it gets exceedingly tedious very quickly. And, furthermore, most Dialog Procedure code has the same basic structure as other Dialog Procedure code. And, to carry on about this a bit more, most of the Dialog control functions have dozens of hard to remember request codes that give no really readable hint as to what is going on when examining the code.

Hence, an automatic Dialog Procedure code generator has been added to WinBatch Studio. It will define a WHOLE bunch of useful constants (many, many more than you will likely need) and it will also generate a useful block of template code based on your dialog.

To have WinBatch Studio generate the Dialog Procedure template code, you simply highlight your dialog code, top to bottom, starting with the line similar to..

       EXAFormat=`WWWDLGED,6.1`
all the way down to and including the
       ButtonPushed=Dialog("EXA")
line.

Next, RIGHT-Click the WinBatch edit window, to get the WinBatch Popup menu to come up, Then select the
     Code Blocks
          Create Dialog Callbacks in Clipboard
               Function with Constants
menu item.

When it is complete, usually just a second or two, paste the generated code into your script, usually above your original Dialog Definition code.

Next, to "hook it up, Locate the line similar to

   EXAProcedure=`EXACallbackProc`
in the area at the bottom of the code you pasted (usually a block marked in red), and move it into the corresponding line at the top of your Dialog Definition code you made with the Dialog Editor. Then delete the explanatory lines in the generated code that tell you what to do this particular operation.

Now you are done. At this point you have to uncomment desired lines in the generated code and add your own code to make the Dialog Callback do what you need. We will be going over this later in this article

Now, however, we will go over what happened as a result of the operations above. As before, we will present the code and then explain what is going on.

- - - - EXAMPLE B - - - -

;============================================================
;============================================================
;============================================================




#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 Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   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      ; -1=Get Current otherise new title

   ;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
   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

   ;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

   ;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 EXBCallbackProc(EXB_Handle,EXB_Message,EXB_ID,rsvd1,rsvd2)
   InitDialogConstants()                                    ; Initialize Dialog Constants
   Switch EXB_Message                                       ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(EXB_Handle,MSG_TIMER,1000)
;         DialogProcOptions(EXB_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(EXB_Handle,MSG_CHECKBOX,@TRUE)
         Return(RET_DO_DEFAULT)

;     case MSG_BUTTONPUSHED                                 ; ID 002  OK
;        return(RET_DO_DEFAULT)

;     case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
;        return(RET_DO_DEFAULT)

   EndSwitch                                                ; EXB_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback EXBCallbackProc

;============================================================
;============================================================
;============================================================




EXBFormat=`WWWDLGED,6.1`

EXBCaption=`Example B`
EXBX=-1
EXBY=-1
EXBWidth=060
EXBHeight=045
EXBNumControls=002
EXBProcedure=`EXBCallbackProc`
EXBFont=`Microsoft Sans Serif|7373|70|34`
EXBTextColor=`0|0|128`
EXBBackground=`DEFAULT,128|255|255`

EXB001=`004,004,046,011,CHECKBOX,MyCheckBox,"Click Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXB002=`009,022,033,010,PUSHBUTTON,DEFAULT,"OK",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("EXB")
Message("CheckBox Value on Dialog Exit is",MyCheckbox)

When examining the code above you can see that it starts off with a large #DefineSubroutine InitDialogConstants that defines a number of constants used in various Dialog control functions so that the constants may be used instead of numbers, brining a great deal of clarity to the code.

Those readers with particularly beady eyes will also note that the "EXA"s of the original example have been changed to "EXB"s. A change which was done purely to help keep these examples easy to differentiate.

Next, is the #DefineFunction EXBCallbackProc, which the template for your Dialog Procedure code.

Following that, is the only slightly (one line) modified version of the original Dialog code generated by the Dialog Editor. Further inspection will show that the EXBProcedure variable, unlike the EXAProcedure variable in the previous example, has been set to "EXBCallBackProc" which is the name of the #DefineFunction added just above. This is what links up the dialog to your code and also tells WinBatch to start processing the Dialog Callback Procedures.

The Dialog Procedure, EXBCallBackProc in this case, is a special case of either a #DefineFunction or a #DefineSubroutine.

#DefineFunction
A WinBatch procedure wherein all variables are "pure local". Basically the only way to get information into a #DefineFunction is via the passed parameters, and the only way to get information out of it is via the return value. Obscure exceptions do apply.

#DefineSubroutine
A WinBatch procedure wherein all variables are "global". All variables are in common with the rest of your program. This allows easy import and export of information from your #DefineSubroutine from and to the rest of your script. The downside is that it is easy to mistakenly stomp on information in your main script that you did not intend to. As usual, obscure exceptions apply.

In particular, the #DefineFunction (or #DefineSubroutine) must have five parameters. e.g.

#DefineFunction EXBCallbackProc(EXB_Handle,EXB_Message,EXB_ID,rsvd1,rsvd2)
The parameters are
  1. EXB_Handle: A special number that refers to the dialog. This number will be used later in subsequent calls to various Dialog support functions. It is not used in Example B.

  2. EXB_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 dlgmessage value of zero. The idea is that your code (as shown in a later example) will request further services from WinBatch in regards to your dialog.

  3. EXB_ID: The number of the control that caused a requested event (explained later) 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.

  4. rsvd1: This parameter is reserved and is not currently used. Nevertheless it is still required.

  5. rsvd2: This parameter is also reserved.

The Dialog support functions make use of quite a few different numbers to represent different things, and it can get quite confusing if you hard code all the numbers, as most people will quickly forget what they mean. So we start off on the right foot here by first defining a number of constants by calling the InitDialogConstants subroutine.

Note that since InitDialogConstants is defined as a subroutine, the variables the constants are assigned to are accessible by the code that called the subroutine (as opposed to a function, where the variables are hidden from the calling code).

   InitDialogConstants()                                    ; Initialize Dialog Constants
Next is the "Switch" statement in the Dialog Procedure.

The switch statement is the heart and soul of a Dialog Procedure. There is one case for each different type of message that it can receive. Initially, the only message enabled by default is the MSG_INIT initialization message.

When the Dialog Procedure starts up, by virtue of the EXBProcedure variable in the Dialog Definition statements discussed earlier, the Dialog Procedure gets one chance to tell WinBatch what it wants. Just before the Dialog is displayed to the user, the Dialog Procedure is called with a EXB_Message value of MSG_INIT, which is the signal that the Dialog procedure should perform its initialization steps. Generally the initializations steps consist of telling WinBatch, via various Dialog support functions (discussed later) what other messages your Dialog procedure wishes to receive.

The Switch statement produced by the Winbatch Studio code looks like...

   Switch EXB_Message                                       ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(EXB_Handle,MSG_TIMER,1000)
;         DialogProcOptions(EXB_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(EXB_Handle,MSG_CHECKBOX,@TRUE)
         Return(RET_DO_DEFAULT)

;     case MSG_BUTTONPUSHED                                 ; ID 002  OK
;        return(RET_DO_DEFAULT)

;     case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
;        return(RET_DO_DEFAULT)

   EndSwitch                                                ; EXB_Message
You will note that Much of the generated code is commented out and that the only active code is a case statement that captures the MSG_INIT message and returns, instructing WinBatch to simply do the default processing.

Thus, at this point, MSG_Init case does nothing except return to WinBatch, Uncommenting and adding more code will be discussed later.

What do the return values mean?

When Dialog procedures exit, they are supposed to return a value. The returned value is used by WinBatch to figure out what you wish to occur. The permitted return values and their actions are...
Positive Integer
e.g. 1, 2, 3, etc.
Exit the dialog. Sets the return value of the Dialog function to the specified value.

RET_DO_CANCEL
Cancel the dialog. Do normal CANCEL processing.

RET_DO_DEFAULT
Do default processing.

RET_DO_NOT_EXIT
Do default processing EXCEPT do not close the dialog.
So that's it. Our Example B simply has a hooked up Dialog Procedure and an initialization case that does, basically, nothing. But all the major pieces are in place now.




Exercise B

Ok. Please humor your tech writer here. As before just doing the steps *really* helps.

  1. Highlight and copy to clipboard the "Example B" WinBatch dialog code shown above.
  2. Run WinBatch Studio and select File/New.
  3. Paste the code into your new WinBatch Studio Window.
  4. Save the code someplace. We recommend that you use the filename "ExampleB.wbt" to help keep things straight.
  5. Hit the "RUN" button on the toolbar.
  6. Note the blue dialog, similar to the one show above appears on the screen,
  7. Note that you can click the check box, and the checked/unchecked state flips back and forth.
  8. Hit the OK button. A message box will appear showing you the state of the checkbox as the dialog was exited.
  9. Hit OK on the message box to exit the program.

You will note that there is _NO_ difference in functionality from the previous Example A. But hopefully we did not break anything either. Exercise B is complete.





Fleshing out the initialization procedure

Now that the basics are in place, we can work on the switch code to tell the dialog procedure what we are interested in. Our eventual goal is to ask the user to confirm the clicking of the checkbox. Thus we will need to be notified of any activity in a checkbox, and need to modify the automatically generated code to do this.

First the code...

- - - - EXAMPLE C - - - -

;============================================================
;============================================================
;============================================================




#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 Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   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      ; -1=Get Current otherise new title

   ;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
   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

   ;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

   ;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 EXCCallbackProc(EXC_Handle,EXC_Message,EXC_ID,rsvd1,rsvd2)
   InitDialogConstants()                                    ; Initialize Dialog Constants
   Switch EXC_Message                                       ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(EXC_Handle,MSG_TIMER,1000)
;         DialogProcOptions(EXC_Handle,MSG_BUTTONPUSHED,@TRUE)
         DialogProcOptions(EXC_Handle,MSG_CHECKBOX,@TRUE)
         Return(RET_DO_DEFAULT)

;     case MSG_BUTTONPUSHED                                 ; ID 002  OK
;        return(RET_DO_DEFAULT)

     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
        Return(RET_DO_DEFAULT)

   EndSwitch                                                ; EXC_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback EXCCallbackProc

;============================================================
;============================================================
;============================================================




EXCFormat=`WWWDLGED,6.1`

EXCCaption=`Example C`
EXCX=-1
EXCY=-1
EXCWidth=060
EXCHeight=045
EXCNumControls=002
EXCProcedure=`EXCCallbackProc`
EXCFont=`Microsoft Sans Serif|7373|70|34`
EXCTextColor=`0|0|128`
EXCBackground=`DEFAULT,128|255|255`

EXC001=`004,004,046,011,CHECKBOX,MyCheckBox,"Click Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXC002=`009,022,033,010,PUSHBUTTON,DEFAULT,"OK",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("EXC")
Message("CheckBox Value on Dialog Exit is",MyCheckbox)
There were not many changes this time. Besides the obvious EXB to EXC changes, three lines were uncommented.

In the MSG_INIT section, one line was uncommented to let WinBatch know that our Dialog Procedure is interested in CheckBox type messages.

         DialogProcOptions(EXC_Handle,MSG_CHECKBOX,@TRUE)
Then, two lines in the switch statement to allow handling of the MSG_CHECKBOX messages were uncommented.
     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
        Return(RET_DO_DEFAULT)

And, so far, that's it. you now have a ton of Dialog and Dialog Procedure code and have yet to write a single line of real code.



Exercise C

I agree this may be getting monotonous, and there is still no excitement in the dialog. When you run it, the results will be the same as before. Do it anyway.

  1. Highlight and copy to clipboard the "Example C" WinBatch dialog code shown above.
  2. Run WinBatch Studio and select File/New.
  3. Paste the code into your new WinBatch Studio Window.
  4. Save the code someplace. We recommend that you use the filename "ExampleC.wbt" to help keep things straight.
  5. Hit the "RUN" button on the toolbar.
  6. Note the blue dialog, similar to the one show above appears on the screen,
  7. Note that you can click the check box, and the checked/unchecked state flips back and forth.
  8. Hit the OK button. A message box will appear showing you the state of the checkbox as the dialog was exited.
  9. Hit OK on the message box to exit the program.

You will note that there is still _NO_ difference from the previous Examples A or B. Does everything still run? Exercise C is complete.








Now we will add some code to do something vaguely useful.

- - - - EXAMPLE D - - - -

;============================================================
;============================================================
;============================================================




#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 Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   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      ; -1=Get Current otherise new title

   ;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
   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

   ;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

   ;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 EXDCallbackProc(EXD_Handle,EXD_Message,EXD_ID,rsvd1,rsvd2)
   InitDialogConstants()                                    ; Initialize Dialog Constants
   Switch EXD_Message                                       ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(EXD_Handle,MSG_TIMER,1000)
;         DialogProcOptions(EXD_Handle,MSG_BUTTONPUSHED,@TRUE)
         DialogProcOptions(EXD_Handle,MSG_CHECKBOX,@TRUE)
         Return(RET_DO_DEFAULT)

;     case MSG_BUTTONPUSHED                                 ; ID 002  OK
;        return(RET_DO_DEFAULT)

     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
        flag=AskYesNo("Example D","Do you really want to change the value of this checkbox?")
        If flag==@NO
           ;Set it back to what it was
           cbval=DialogControlGet(EXD_Handle,EXD_ID,DC_CHECKBOX)  ; get new state
           DialogControlSet(EXD_Handle,EXD_ID,DC_CHECKBOX,!cbval) ; put back opposite state
        EndIf
        Return(RET_DO_DEFAULT)

   EndSwitch                                                ; EXD_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback EXDCallbackProc

;============================================================
;============================================================
;============================================================




EXDFormat=`WWWDLGED,6.1`

EXDCaption=`Example D`
EXDX=-1
EXDY=-1
EXDWidth=060
EXDHeight=045
EXDNumControls=002
EXDProcedure=`EXDCallbackProc`
EXDFont=`Microsoft Sans Serif|7373|70|34`
EXDTextColor=`0|0|128`
EXDBackground=`DEFAULT,128|255|255`

EXD001=`004,004,046,011,CHECKBOX,MyCheckBox,"Click Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXD002=`009,022,033,010,PUSHBUTTON,DEFAULT,"OK",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("EXD")
Message("CheckBox Value on Dialog Exit is",MyCheckbox)
In this rendition real code was typed into the MSG_CHECKBOX case to actually do something in the event the user clicks the checkbox.
     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me
        flag=AskYesNo("Example D","Do you really want to change the value of this checkbox?")
        If flag==@NO
           ;Set it back to what it was
           cbval=DialogControlGet(EXD_Handle,EXD_ID,DC_CHECKBOX)  ; get new state
           DialogControlSet(EXD_Handle,EXD_ID,DC_CHECKBOX,!cbval) ; put back opposite state
        EndIf
        Return(RET_DO_DEFAULT)
In this case, by virtue of the line we uncommented in the MSG_INIT case previously...
         DialogProcOptions(EXD_Handle,MSG_CHECKBOX,@TRUE)
a change to any checkbox in the dialog causes this code to run.

The WinBatch function AskYesNo is used to prompt the user to confirm the changing of the checkbox.

If the user selects "NO", then we read the value of the checkbox with the DialogControlGet function, passing EXD_Handle, EXD_ID, and the constant, DC_CHECKBOX. The function will return the value of the checkbox. We then do a DialogControlSet with the same parameters, plus an additional one, the value that we want the checkbox to be. (Note the use of the ! symbol, which means NOT, which basically flips a @TRUE to an @FALSE and vice versa.)

Also remember, that in WinBatch Studio, if you click on a function name (shown in blue), then hit Shift-F1, WinBatch Studio will pop open the help page for that function.





Exercise D

Finally interesting stuff begins to happen. At this point we have everything in place, and the Dialog procedure should function.

  1. Highlight and copy to clipboard the "Example D" WinBatch dialog code shown above.
  2. Run WinBatch Studio and select File/New.
  3. Paste the code into your new WinBatch Studio Window.
  4. Save the code someplace. We recommend that you use the filename "ExampleD.wbt" to help keep things straight.
  5. Hit the "RUN" button on the toolbar.
  6. Note the blue dialog, similar to the one show above appears on the screen,
  7. Note that when you click on the check box you are asked on confirm the change.
  8. Continue to play with the program to see how it works. I would hazard a guess that you should be able to handle this without further instructions.

Exercise D is complete.








There is just one more step to having this all figured out. The code we have been working with will treat *all* checkboxes in this manner. So what happens if there is more than one checkbox, and you only want to have the user confirm one of them? Well, as usual, there is simply a little more code. To wit...

- - - - EXAMPLE E - - - -

;============================================================
;============================================================
;============================================================




#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 Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   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      ; -1=Get Current otherise new title

   ;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
   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

   ;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

   ;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 EXECallbackProc(EXE_Handle,EXE_Message,EXE_ID,rsvd1,rsvd2)
   InitDialogConstants()                                    ; Initialize Dialog Constants
   Switch EXE_Message                                       ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(EXE_Handle,MSG_TIMER,1000)
;         DialogProcOptions(EXE_Handle,MSG_BUTTONPUSHED,@TRUE)
         DialogProcOptions(EXE_Handle,MSG_CHECKBOX,@TRUE)
         Return(RET_DO_DEFAULT)

;     case MSG_BUTTONPUSHED                                 ; ID 002  OK
;        return(RET_DO_DEFAULT)

     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me

        Switch EXE_ID

           Case 001
              flag=AskYesNo("Example D","Do you really want to change the value of this checkbox?")
              If flag==@NO
                 ;Set it back to what it was
                 cbval=DialogControlGet(EXE_Handle,EXE_ID,DC_CHECKBOX)  ; get new state
                 DialogControlSet(EXE_Handle,EXE_ID,DC_CHECKBOX,!cbval) ; put back opposite state
              EndIf           

        EndSwitch

        Return(RET_DO_DEFAULT)

   EndSwitch                                                ; EXE_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback EXECallbackProc

;============================================================
;============================================================
;============================================================




EXEFormat=`WWWDLGED,6.1`

EXECaption=`Example E`
EXEX=-01
EXEY=-01
EXEWidth=068
EXEHeight=058
EXENumControls=003
EXEProcedure=`EXECallbackProc`
EXEFont=`Microsoft Sans Serif|7373|70|34`
EXETextColor=`0|0|128`
EXEBackground=`DEFAULT,128|255|255`

EXE001=`004,004,056,011,CHECKBOX,MyCheckBox,"&Confirm Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXE002=`004,022,056,011,CHECKBOX,MyOtherCheckBox,"&But not me",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXE003=`015,039,032,011,PUSHBUTTON,DEFAULT,"&OK",1,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("EXE")

Message("CheckBox Values are",StrCat("EXE001=",MyCheckBox,@CRLF,"EXE002=",MyOtherCheckBox))

In this example we have added an additional checkbox and re-arranged the dialog slightly.
EXE001=`004,004,056,011,CHECKBOX,MyCheckBox,"&Confirm Me",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXE002=`004,022,056,011,CHECKBOX,MyOtherCheckBox,"&But not me",1,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
EXE003=`015,039,032,011,PUSHBUTTON,DEFAULT,"&OK",1,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Shows the three controls in the dialog. EXE001 and EXE002 are checkboxes, and EXE003 is the OK button.

In addition, not broken out here, the Message statement at the end has been modified to display the values of both of the checkboxes on exit.

Most importantly, though, are the changes to the MSG_CHECKBOX case in the main Dialog Procedure switch statement.

     Case MSG_CHECKBOX                                     ; ID 001  MyCheckBox Click Me

        Switch EXE_ID

           Case 001
              flag=AskYesNo("Example D","Do you really want to change the value of this checkbox?")
              If flag==@NO
                 ;Set it back to what it was
                 cbval=DialogControlGet(EXE_Handle,EXE_ID,DC_CHECKBOX)  ; get new state
                 DialogControlSet(EXE_Handle,EXE_ID,DC_CHECKBOX,!cbval) ; put back opposite state
              EndIf           

        EndSwitch

        Return(RET_DO_DEFAULT)
Note that an entirely new switch statement was added *inside* the case. The idea here is that you can have a separate sub-case for each different checkbox you are interested it - and easily ignore the other ones. Please note how the case 001 in the new switch statement relates to the EXE001 Check box control.




Exercise E

You should have this figured out by now. Grab the above code, dump it into WinBatch Studio, run it a few times. Change it. See what happens. Try changing the "case 001" to "case 002" and see what happens.







An Extra Credit Assignment

A different sort of Dynamic Dialog follows. Copy the code into WinBatch and try it a few times. See how it works. This one is for you to figure out.
;============================================================
;============================================================
;============================================================




#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 Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   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      ; -1=Get Current otherise new title

   ;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
   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

   ;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

   ;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 ExtraCallbackProc(Extra_Handle,Extra_Message,Extra_ID,rsvd1,rsvd2)
   InitDialogConstants()                                    ; Initialize Dialog Constants
   Switch Extra_Message                                     ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(Extra_Handle,MSG_TIMER,1000)
         DialogProcOptions(Extra_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(Extra_Handle,MSG_EDITBOX,@TRUE)
         Return(RET_DO_DEFAULT)

     Case MSG_BUTTONPUSHED
        Switch Extra_ID
           Case 003                                        ; ID 003  Browse
                     fname=AskFilename("Choose a FileName", "", "All Files|*.*", "*.*", 1 )
                     DialogControlSet(Extra_Handle,002,DC_EDITBOX,fname)
                     :CANCEL
                     Return(-2)  ; don't exit


              Return(RET_DO_DEFAULT)

;           case 004                                        ; ID 004  OK
;              return(RET_DO_DEFAULT)

;           case 005                                        ; ID 005  Cancel
;              return(RET_DO_DEFAULT)

;        endswitch                                          ; Extra_ID
;        return(RET_DO_DEFAULT)

;     case MSG_EDITBOX                                      ; ID 002  MyFileName
;        return(RET_DO_DEFAULT)

   EndSwitch                                                ; Extra_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback ExtraCallbackProc

;============================================================
;============================================================
;============================================================







ExtraFormat=`WWWDLGED,6.1`

ExtraCaption=`Extra Credit Assignment`
ExtraX=-1
ExtraY=-1
ExtraWidth=254
ExtraHeight=082
ExtraNumControls=005
ExtraProcedure=`ExtraCallbackProc`
ExtraFont=`DEFAULT`
ExtraTextColor=`DEFAULT`
ExtraBackground=`DEFAULT,255|128|0`

Extra001=`009,006,043,009,STATICTEXT,DEFAULT,"FileName:",DEFAULT,1,DEFAULT,"Microsoft Sans Serif|7373|70|34","0|0|128",DEFAULT`
Extra002=`007,020,192,014,EDITBOX,MyFileName,"",DEFAULT,2,DEFAULT,"Microsoft Sans Serif|7373|70|34","0|0|128","255|128|0"`
Extra003=`209,020,035,014,PUSHBUTTON,DEFAULT,"Browse",2,3,DEFAULT,"Microsoft Sans Serif|7373|70|34","0|0|128","255|128|64"`
Extra004=`033,054,035,014,PUSHBUTTON,DEFAULT,"OK",1,4,DEFAULT,"Microsoft Sans Serif|7373|70|34","0|0|128","255|128|64"`
Extra005=`126,054,034,014,PUSHBUTTON,DEFAULT,"Cancel",0,5,DEFAULT,"Microsoft Sans Serif|7373|70|34","0|0|128","255|128|64"`

ButtonPushed=Dialog("Extra")

Message("Selected Filename is",MyFileName)

Exit
So that's the end of this tutorial. Dynamic Dialogs are lots of fun, and give a lot of extra power to your WinBatch dialogs.
Article ID:   W16781
File Created: 2014:07:18:13:13:06
Last Updated: 2014:07:18:13:13:06