Using Dialogs

Contributed by INSIDES
Introduction
Dialogs can be quite handy while using your mIRC and creating a custom script, because of the standard GUI they offer. mIRC's scripting language offers a variety of options related to your own custom dialogs. Dialogs can be used for changing the script's settings and/or receiving modal user input. Please note that using dialogs will probably require mIRC version 5.61 or higher. Further more, some dialog items such as menus are supported in version 5.71 only so far. This tutorial requires a some previous knowledge of mIRC scripting.
Supported Controls
So far, the most common controls are supported and can be used as dialog items in your dialogs. For a full list of supported items and style properties, please check mIRC's help file, topic Dialogs. So far supported controls : Text Label, Edit Box, Command Button, Check Box, Radio Box, Frame Box, List Box, Combo Box, Icon (Picture) Box, Link Label, Tab, Menu Item.
The Dialog Table
The dialog table contains all the necessary information concerning the dialog. This means, the list of controls and their properties. It also contains the size & position of the dialog, dialog title, and display options.

The following table describes a simple dialog containing 3 radio boxes grouped within a frame box, 3 check boxes grouped within a frame box, 1 edit box, and 2 command buttons.
dialog sample {
  title "Sample Dialog"
  size -1 -1 115 90
  option dbu

  box "Check Boxes",1,5 5 50 39
  check "Check Box 1",2,8 12 40 11
  check "Check Box 2",3,8 22 40 11
  check "Check Box 3",4,8 32 40 11

  box "Radio Boxes",5,60 5 50 39
  radio "Radio Box 1",6,63 12 40 11
  radio "Radio Box 2",7,63 22 40 11
  radio "Radio Box 3",8,63 32 40 11

  edit "",10,5 50 105 11,autohs,result
  edit "",11,5 62 105 11,autohs

  button "Accept",100,48 75 30 11,ok
  button "Cancel",101,80 75 30 11,cancel
}
Note: The table must be placed in the Script section, not the Aliases section.

Now, for the sections of the dialog table.

The first item <title> contains the dialog title. The second item <size> contains the size & position of the dialog in the format <x y w h>. Using -1 for x and y centers the dialog on the screen. The third item <option> can have the value dbu (default base units) or pixels, which relay on the display option of the end user. Pixels are the default.

On the other hand, all of the controls have a specific definition format :

control type "Caption Text", ID Number , X Y W H , control properties

Sizing controls should be done on site, reviewing their relation with all other controls on the dialog.

The dialog table must have a control whose properties will contain the switch ok or cancel or both. This allows the dialog to close by clicking on either of that controls.

Finally, the beauty of the dialog table is in it's versatility and ability to be used in an infinite number of various dialogs, by just changing the default control properties.
Calling Up Dialogs
mIRC allows two types of dialogs : modeless, created withe the /dialog command, and modal, created with the $dialog() identifier.

The /dialog Command

/dialog -mdtsonkcvie name [table] [x y w h]

For a list of switches please check mIRC's Help File.

Creating a dialog with the given dialog table now requires :
/dialog -m sample sample
This command opens up the dialog using the given dialog table, and sets it as a modeless dialog, which does not halt the script while executing. This type of dialog is quite satisfying for setting script options and reviewing current user status etc.

The $dialog() Identifier

$dialog(name,table,[parent])

Creating a dialog with the given dialog table now requires :
$dialog(sample,sample,-2)
This command opens up the dialog using the given dialog table, and sets it as a modal dialog, which halts the script until it is closed. Unlike the /dialog command dialogs, this type of dialog returns a result and can be used for creating custom input boxes etc.

Note: Because of the specific format this identifier uses, the dialog table must contain a control definition which will have a property result. The value of that control is used as a result for the $dialog() identifier. In our table that is the control edit Box with an ID Number of 10. Please make sure the dialog is of such type for the user is required to enter a value for the result. If the value of the result control is empty, mIRC returns a $null value, which will probably result with an error in your script.
Responding To Dialog Events
mIRC responds to any kind of change that occurs on the dialog, like clicking a Command Button, a List Box, a Combo Box, typing text into an Edit Box, following a Link Label, etc.

Your job is to make sure you have covered all the events a user is able to raise while working on a specific dialog.

The dialog events are covered with the On DIALOG event :

On <level>:DIALOG:<name>:<table>:<event>:<ID>:{ commands }

The supported events are :

Init - This event occurs just before a dialog is displayed, and can be used to initialize the controls and set their properties. ID equals 0.
Edit - This event occurs when text has changed in an Edit Box or in a Combo Box.
Sclick - This event occurs on a single click in a List Box, Combo Box, a check, uncheck of a Radio Box, Check Box, or a click of a Command Button.
Dclick - Identical to previous, but it occurs on a double click.
Menu - A selection of a menu item.

While responding to events, the properties of the dialog can be read by using the dialog identifiers, such as $dname, which contains the name of the dialog, $devent, which contains the name of the dialog event, and the $did identifier, containing the ID of the concerned control.
Reading The Values Of The Dialog Controls
Before responding to events, you must learn to read the dialog properties, and the values of the dialog controls there in. This is done with the expanded $did identifier.

$did($dname,$did)

The supported properties are : text, len, lines, sel, seltext, selstart, selend, edited, state, next, prev, visible, enabled. For a full list of properties and values that can be read by the $did identifier, please check the mIRC Help File.
Setting The Values Of The Dialog Controls
You may want to set some preliminary values to the controls befor the user can choose. This is quite necessary for any type of an option setting dialog. This is done by the /did command.

/did -ftebvhnmcukradiogj name id [n] [text | filename]

For a full list of switches please check the mIRC Help File.
Responding To Events In Our Sample Dialog
Lets suppose that you have set several options using some internall variables which reffer to the given dialog table. The variables and the values are :
%sample.checkone On
%sample.checktwo Off
%sample.checkthree Off
%sample.radio 2
%sample.editone Sample Option 1
%sample.edittwo Sample Option 2
If you have set these variables, we can proceed to the initialization event :
On *:DIALOG:sample:init:0:{
  if (%sample.checkone == On) { did -c sample 2 }
  if (%sample.checktwo == On) { did -c sample 3 }
  if (%sample.checkthree == On) { did -c sample 4 }
  did -c sample $calc(5 + %sample.radio)
  did -a sample 10 %sample.editone
  did -a sample 11 %sample.edittwo
}
Note: Even though you can set the text of the Edit Boxes in the table by simply typing the names of the variables, that option has been quite unpractical, because the absence of the specified variable generates an error in the script.

By now, you should have a dialog with one checked Check Box and one checked Radio Box, and then tho Edit Boxes filled with sample text.

After clicking the OK button, follow the sclick event, which saves the values of the variables for further setting.
On *:DIALOG:sample:sclick:100:{
  if ($did(sample,2).state == 1) { set %sample.checkone On }
  else { set %sample.checkone Off }
  if ($did(sample,3).state == 1) { set %sample.checktwo On }
  else { set %sample.checktwo Off }
  if ($did(sample,4).state == 1) { set %sample.checkthree On }
  else { set %sample.checkthree Off }
  if ($did(sample,6).state == 1) { set %sample.radio 1 }
  elseif ($did(sample,7).state == 1) { set %sample.radio 2 }
  else { set %sample.radio 3 }
  set %sample.editone $did(sample,10).text
  set %sample.edittwo $did(sample,11).text
}
Note: Commands and alias definitions can find their way insides the sclick event, even though you should try to avoid them in order to keep the code clean. You could use the sclick events generated by clicks on Radio & Check Boxes, but they seem to be non-reliable in case the user clicks the Cancel button.

This about finishes this sample options dialog. The full code should look like this :
dialog sample {
  title "Sample Dialog"
  size -1 -1 115 90
  option dbu

  box "Check Boxes",1,5 5 50 39
  check "Check Box 1",2,8 12 40 11
  check "Check Box 2",3,8 22 40 11
  check "Check Box 3",4,8 32 40 11

  box "Radio Boxes",5,60 5 50 39
  radio "Radio Box 1",6,63 12 40 11
  radio "Radio Box 2",7,63 22 40 11
  radio "Radio Box 3",8,63 32 40 11

  edit "",10,5 50 105 11,autohs
  edit "",11,5 62 105 11,autohs

  button "Accept",100,48 75 30 11,ok
  button "Cancel",101,80 75 30 11,cancel
}

On *:DIALOG:sample:init:0:{
  if (%sample.checkone == On) { did -c sample 2 }
  if (%sample.checktwo == On) { did -c sample 3 }
  if (%sample.checkthree == On) { did -c sample 4 }
  did -c sample $calc(5 + %sample.radio)
  did -a sample 10 %sample.editone
  did -a sample 11 %sample.edittwo
}

On *:DIALOG:sample:sclick:100:{
  if ($did(sample,2).state == 1) { set %sample.checkone On }
  else { set %sample.checkone Off }
  if ($did(sample,3).state == 1) { set %sample.checktwo On }
  else { set %sample.checktwo Off }
  if ($did(sample,4).state == 1) { set %sample.checkthree On }
  else { set %sample.checkthree Off }
  if ($did(sample,6).state == 1) { set %sample.radio 1 }
  elseif ($did(sample,7).state == 1) { set %sample.radio 2 }
  else { set %sample.radio 3 }
  set %sample.editone $did(sample,10).text
  set %sample.edittwo $did(sample,11).text
}
All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.