Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Colors and Fonts : Allowing the user to change colors and fonts : Color dialog box example
 
Color dialog box example
The i-cdial1.p procedure opens the dialog box that allows you to change its own foreground or background colors.
i-cdial1.p
DEFINE VARIABLE BackColor AS INTEGER NO-UNDO INITIAL 17.
DEFINE VARIABLE ColorSelect AS INTEGER NO-UNDO INITIAL 16
  VIEW-AS RADIO-SET RADIO-BUTTONS "Foreground", 16, "Background", 17
  HORIZONTAL.
DEFINE VARIABLE FrontColor AS INTEGER NO-UNDO INITIAL 16.
DEFINE VARIABLE status-ok AS LOGICAL NO-UNDO.

DEFINE BUTTON bCANCEL LABEL "CANCEL".
DEFINE BUTTON bOK LABEL "OK".

IF COLOR-TABLE:NUM-ENTRIES < 18 THEN
  COLOR-TABLE:NUM-ENTRIES = 18.

status-ok = COLOR-TABLE:SET-DYNAMIC(16, TRUE).
IF NOT status-ok THEN DO:
  MESSAGE "Cannot make color 16 dynamic.".
  RETURN.
END.

status-ok = COLOR-TABLE:SET-DYNAMIC(17, TRUE).
IF NOT status-ok THEN DO:
  MESSAGE "Cannot make color 17 dynamic.".
  RETURN.
END.

COLOR-TABLE:SET-RGB-VALUE(16,RGB-VALUE(0,0,0)).
COLOR-TABLE:SET-RGB-VALUE(17,RGB-VALUE(128,128,128)).

FORM
  SKIP(0.5) SPACE(0.5) ColorSelect SPACE(2) bOK SPACE(2) bCANCEL
  SPACE(0.5) SKIP(0.5)
  WITH FRAME fColor TITLE "Choose frame colors ..." FGCOLOR FrontColor
    BGCOLOR BackColor VIEW-AS DIALOG-BOX.

ON CHOOSE OF bOK IN FRAME fColor DO:
  ASSIGN ColorSelect.
  SYSTEM-DIALOG COLOR ColorSelect.
END.

ON CHOOSE OF bCANCEL IN FRAME fColor STOP.

ENABLE ColorSelect bOK bCANCEL WITH FRAME fColor.

WAIT-FOR WINDOW-CLOSE OF FRAME fColor.
When you run this procedure on Windows, the following frame appears:
If you click OK, a color dialog box appears (see Figure 30) to assign a new system color to the specified color number. Clicking CANCEL terminates the procedure without any further color changes.