> So, You Want to Write Windows Apps

Windows programming improvements

Windows programming under Comet has been improved and simplified. Existing programs still compile, but the Comet API now includes new calls to make Windows programming easier.

Windows events, such as a mouse click on an OK button, are now returned to the Internet Basic program as EVENTSUB events. This allows the program to easily determine which event occurred and to process that event accordingly.

The following code segment demonstrates the point. First this program sets the EVENTSUB trap and waits for an event to occur. When an event does occur, the program branches to the EventHandler subroutine. In that subroutine the program calls the CW.ParseEvent subroutine to determine which type of event occurred. Then the control id (in the form of the cosCtlId variable) is used to determine which specific event occurred. The code below tests for two cases: IDOK and IDCANCEL. In each case, the cosCommand variable is tested to see if it equals the value of BN.CLICKED, which indicates that a button was clicked. In the case of IDCANCEL, a flag is set (CW.ExitEvents) to signal that the program should stop the event handler. Finally, the subroutine resets or stops the event handler based on the value of the CW.ExitEvents flag.

Comments in the EventHandler subroutine show where code can be included for processing the IDOK and IDCANCEL events or for other events this program will process.
eventsub EventHandler CW.Event$ CW.Source$
eventwait
.
.
.
EventHandler:
  gosub CW.ParseEvent         ! Determine which type of event occurred

  select case cosCtlId
    case IDOK                 ! User pressed the OK button
      if cosCommand = BN.CLICKED

!       To do: write code to process OK button

      endif

    case IDCANCEL             ! User pressed the CANCEL button
      if cosCommand = BN.CLICKED
        CW.ExitEvents = TRUE  ! Signal that we want to stop the event handler
      endif

! To do: write code for any other cases we expect to process

  endselect

  if CW.ExitEvents = FALSE    ! Either re-establish or cancel event handler
    eventsub EventHandler CW.Event$ CW.Source$
  else
    eventsub
  endif
    return


The above code comes from a demonstration program named WinTemp.ibs (in the DLG directory). This is a template program that you can copy and modify for your own applications. The template program includes an OK button and a Cancel button. You can add your own controls by cutting and pasting code from our library of sample programs. There are numerous comments in the template program that make it easy to see where your code needs to be placed.

The sample library includes programs that show how to create various controls manually without using dialogs. You can access these programs by running the CTLDEMO program (in the DLG directory). These programs parallel the DLGDEMO programs, where each program demonstrates one type of control. This makes it easy to cut and paste code from the sample program into the template program.

For example, if you want to create a radio button manually (without using a dialog), you could cut and paste the appropriate code from the CtlDemo2.ibs source program into the template program. Likewise for the other controls that are supported. For additional details, see below for information about the Windows programming tutorials available on Signature’s web site.

Comet2004 supports the following Windows controls:

  1. static text
  2. radio button
  3. check box
  4. list box
  5. edit control (and validated edit control)
  6. picture pushbutton
  7. tree
  8. tab
  9. list control
  10. date/time picker
  11. calendar
  12. IP address
  13. combo box
  14. slider
  15. scrollbar
  16. progress
  17. spin
  18. bitmap
  19. picture

Other changes:

  1. For programs that create controls manually (without using dialogs), screen positioning is done with “centi units.” With this scheme, each character is divided into 100 units for each dimension. Thus, to position a control at column 5, row 16, you would write:
    cosCol = 500
    cosRow = 1600
    To specify a control that is 18 character positions wide and 1.5 character positions tall, you would write:
    cosWidth = 1800
    cosHeight = 150
    This scheme allows much more control over the positioning and size of Windows controls.

  2. Metafiles no longer required for CometAnywhere
    When using dialogs on a CometAnywhere remote system, metafiles are no longer required. The DLL file is automatically copied to the remote machine.
    Note that the application program still needs to deliver images to the remote machine, if images are used.

  3. CF flags
    The new EventHandling scheme eliminates the need for the programmer to include CF flags for the handlers and initializations such as:
    SET CF.USR.COMMANDHANDLER = 1
    SET CF.USR.NOTIFYHANDLER = 1
    SET CF.USR.COMMANDFILTERINIT = 1
    SET CF.USR.NOTIFYFILTERINIT = 1
    SET CF.USR.DIALOGINIT = 1