' draft of Scripting class 13 ( for 5/29/2011)

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



' While the remainder of this class will be used to cover the XML dialog
facility,
' here are some short examples showing the various other options for
interfacing an app with the user.

' Example 1:

' example showing hot key and speech as the interface technique:

Set registeredKey = Keyboard.RegisterHotKey("Control-Shift-Windows-R",
"SpeakHelloWorld")

Sub SpeakHelloWorld()
' called when the user presses the hotkey
  Speak "Hello world!"
End Sub

' example showing use of the WE object model's built-in commonFileDialog
method
' get a file  name from the user
strFileName = commonFileDialog(True, "Select VBS File", ,
clientInformation.ScriptPath, _
"VBS files,*.vbs", , , cfdfEnableDialogResizing + cfdfHideReadOnlyCheck +
cfdfUseLongFileNames)
speak strFileName
' above speaks the name of the file which the user selected

' an example showing the use of the built-in VBScript commands
strFileName = inputBox ("enter the vbs script file name")
msgBox "the script name was " & strFileName

' example showing use of the GW toolKit
' This example creates a simple dialog with a list box of four items, and
returns
a string of the data associated with the
selected item.
Set myListBox =
SharedObjects("com.GWMicro.GWToolkit.SimpleDialogs").ListBoxDialog
myListBox.AddItem "Red", "Red"
myListBox.AddItem "Green", "Green"
myListBox.AddItem "Blue", "Blue"
Speak myListBox.ChooseItem("Select a color") 
' above line speaks the resulting choice the user makes


' end of example 1



' Example 2:


' The above examples cover *all* of your choices (pretty much) for creating
interfaces to interact with the user.
' If they won't do what you need, then you must learn to use the XML dialog
feature of Window-Eyes.


' You can see this feature in use, when the WE Script Framework wizard
generates an app with a menu entry for it in the WE control panel "Apps"
menu.
' The code below is added to the .vbs generated app to cause the menu to be
displayed, and it's one choice for "help" to be handled:

dim myMenu, myXMLFile

myXMLFile = "test.xml"
Set myMenu = Menu(myXMLFile, "my_script_menu", "MenuProc")
' the "menu" function above reads the definition of the menu from the XML
file, causes it to be added to the WE control panel "Apps" menu, and
arranges the event handler for it


Function MenuProc(menuObj, id)
' this is the event handler for the menu (it acts just like any event
handler)     

MenuProc = False
    Select Case id
            Case "menu_help"
            Queue "ScriptHelp"
            MenuProc = True
            Exit Function
            End Select

End Function

Sub ScriptHelp()
' this causes the standard help dialog from the GW Toolkit to be displayed
' (earlier, it has been stored into the SO_StandardHelpDialog global
variable)

    SO_StandardHelpDialog.Show

End Sub

' end of example 2


Reply via email to