Tips and Techniques

Dialog and Control Appearance

Many controls support background and foreground colors. Setting the background color to -24 (Transparent) causes the control to appear transparent. Setting a foreground color in some cases depends on the 'Use Visual Style' property. When controls use a visual style, the style may override the explicit foreground color. If color control is important, disable the use of the visual style. Note that visual styles are available only in Windows XP and later, and only if visual styles are enabled in Windows settings.

Graphic buttons and picture box controls draw a transparent image by masking out pixels with the gray color value RGB 192, 192, 192. Any pixels with that color will be masked out when the image is painted.

A control's font setting includes the usual settings for font face, size, and style, however in OpenDCL there is an additional property that determines how the font size is calculated at runtime. The default setting for this property is "Font Size in Pixels". Using the alternative "Font Size Scaled to Monitor" causes font size calculations to be scaled up or down depending on the size of the display. This alternative size algorithm must be used with caution, as it can result in controls too small or too large for the text inside.

Modifying Properties at Runtime

Modifying control and form properties at runtime is a powerful capability that enables OpenDCL applications to literally change their user interface dynamically at runtime. Controls can be enabled and disabled, or even hidden and shown, depending on changes in dialog or application state. This capability even allows distinctly different controls to occupy the same space on a form, allowing runtime code to alternatively show and hide them so that one or the other is visible at a given time.

Most form and control properties are stored in the project data. Such property values persist between invocations of the same form. This is important to remember, because in some cases the previous dialog state needs to be reset between invocations. To reset the dialog state, the project data could be reloaded from the project file or the persisted properties can be reset directly to their initial values. For example, code that populates a list box during OnInitialize must handle the possibility that the list is already initialized either by checking first, or by simply clearing it every time before repopulating it.

In some cases, it may be useful to write AutoLISP code to automate a series of changes to an existing OpenDCL project, then save the changes back to a file. For example, the following code opens an OpenDCL project, iterates through every control on every form, and sets the font scaling method for each one (note that font scaling is controlled by the sign of the 'FontSize' property), then saves the modified project data to a new file.

(defun SetOdclFontSizeUnscaled (odclfile password newodclpath / project props fontsize)
  (setq project (dcl-Project-Load odclfile))
  (if (not project) (exit))
  (foreach
    form (dcl-Project-GetForms project)
    (foreach
      control (dcl-Form-GetControls form)
      (progn (setq props (dcl-Control-GetProperties control))
        (if (member "FontSize" props)
          (progn (setq fontsize (dcl-Control-GetProperty control "FontSize"))
            (if (> fontsize 0)
              (dcl-Control-SetProperty control "FontSize" (- 0 fontsize))))))))
  (dcl-Project-SaveAs project newodclpath password)
)