Hi all,

below is the draft of tomorrow's scripting class examples.

we'll be finishing with UIDesign for now, by discussing creating a dialog
using it, and what you need to add to your .vbs code to support the use of a
dialog.  There's no way we can cover anything except basic dialog concepts,
so if we should ever need to, we can come back to this topic and cover it in
detail.

Chip




' draft of Scripting class 14 (6/5/2011)

'-------
' notes:
' in your XML file, each language section may have:
' * one menu for the "Apps" menu entry
' * any number of dialogs 
' * one "strings" section
' (all of these are optional)

' each dialog may have:
' * one (optional) menu bar, with any number of menus and menu items
' * one group (which can contain any number of nested groups and other XML
controls, except menus/menu bars)

'--------

' example 1:

' this shows a very basic skeleton of a dialog event handler, which you
could use to create your own 
' (see the App Developer Reference manual, the "Designing Custome User
Interfaces" chapter)

' note that this is not generated for you by WE Script Framework, nor is the
code to display your dialog.

'  your dialog event handler should detect which control
' was manipulated, and then determine which type of event happened to that
control.
' There are some additional events that we're interested in which don't come
from a
' control, but rather comes from the dialog itself, and that's the event
that indicates
' the dialog was created (which is used to initialize all your controls),
and when it's closing.


Function DialogEventHandler(dObj, dEvent, dId, dControl)
' return "true" if your code handled the event, and false if it did not

DialogEventHandler = False

' test on the name of the control involved in this event by examining the
"dId" parameter

Select Case dId

Case "your control ID"
' now see what was done with this control by examining the "dEvent"
parameter
  If dEvent = buttonClicked Then
' it's now often the time to do something because this control was clicked
' your code to do something goes here ...

    DialogEventHandler = True
    Exit Function
  End If

' now create a "Case" similar to the above for each control in your dialog,
and keep adding them somewhere before the "Case Else" line

Case "ok" ' assumes you have an "ok" button with an ID of "ok"
' now see what was done with this control by examining the "dEvent"
parameter
  If dEvent = buttonClicked Then
' it's now often the time to save options because this control was clicked
' and so your code to do this goes here, using a "queue" command
  queue "saveOptions"
' now cause the dialog to start closing
  dObj.close

    DialogEventHandler = True
    Exit Function
  End If

' note that the case for your "cancel" button is often identical to that of
the "ok" button, except for saving options



        Case Else
' no control ID was recognized
' in this portion we test on events not related to a specific control

  If dEvent = dialogCreated Then
' this event happens before all others, and is the dialog being created
' now initialize your various controls in the dialog

    DialogEventHandler = True
    ExitFunction

  ElseIf dEvent = dialogClosing Then
' something caused this dialog to close, and now it's closing, set your
global variable for this dialog or whatever else you need to do

    DialogEventHandler = True
    ExitFunction
  End If
End Select

End Function



' end of example 1



' example 2:
' this shows a sub used to launch your dialog; it uses a global variable to
hold the dialog object while it's open
' (and also to indicate that the dialog is open), and it uses a global
variable holding the name of the XML file.

Sub displayMyDialog()
' used to display your dialog, you should call this using a "queue" command.

If MyDialog Is Nothing Then
  Set MyDialog = Dialog(myXMLFile, "your dialog ID", "DialogEventHandler")

Else
' already open, so just activate it in case it got behind some other window
  MyDialog.window.Activate
End If

End Sub

' end of example 2



' also see the user interfaces wiki article at:
' http://www.gwmicro.com/mediawiki/index.php/User_Interface_Techniques


Reply via email to