/* An example of FUNCDEF'ing the Windows API to present * a color dialog. */ OPTIONS "C_CALL LABELCHECK WINFUNC NOSOURCE" NUMERIC DIGITS 10 /* ============== FUNCDEF some needed OS functions ============ */ DO /* Define a CHOOSECOLOR struct used with ChooseColor() */ CHOOSECOLOR = "32u, void, void, 32u, 32u[16] *, 32u, 32u, void, void" /* Register the Windows OS function ChooseColor() */ FUNCDEF("ChooseColor", "32u, struct CHOOSECOLOR dual", "comdlg32") CATCH FAILURE CONDITION("M") RETURN END /* ==================== Present the Color dialog ==================== */ /* Initialize the CHOOSECOLOR struct */ ChooseColor. = 0 /* All fields default to 0 */ ChooseColor.1 = 36 /* The size of a CHOOSECOLOR dialog */ /* ChooseColor.2 may be set to the handle of some window that you want * to be the owner of the color dialog. */ /* ChooseColor.4 may be set to the RGB value that you initially want * selected. */ ChooseColor.6 = 1 /* CC_RGBINIT */ /* Present the dialog */ err = ChooseColor(ChooseColor) IF err \== 0 THEN DO /* NOTE: The 16 values of ChooseColor.5.1 to ChooseColor.5.16 will be * the RGB values for the 16 custom colors that the user can create. * The next time that you call ChooseColor, you would probably use the * same REXX variable, and do not reinitialize it. That way, you'll * get the same custom colors as the user set the previous time. */ SAY "RGB value:" ChooseColor.4 SAY "Red value:" C2D(BITAND(D2C(ChooseColor.4, 4), '000000FF'x, ' ')) SAY "Green value:" C2D(BITAND(D2C(ChooseColor.4, 4), '0000FF00'x, ' ')) / 256 SAY "Blue value:" X2D(LEFT(D2X(ChooseColor.4, 8), 4)) END ELSE SAY "ERROR: Presenting Color dialog" RETURN /* ************* ColorsToRGB ****************** * Forms an RGB value out of the passed Red, * Green, and Blue color components. * * rgb = ColorsToRGB(Red, Green, Blue) */ ColorsToRGB: RETURN ARG(1) + (ARG(2) * 256) + (ARG(3) * 65536)