PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: AfxChooseColorDialog  (Read 75 times)

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
AfxChooseColorDialog
« on: September 03, 2017, 12:52:06 PM »

Hi Jose, the AfxChooseColorDialog code found in AfxWin.inc may need a little tweak. I am using the function to allow WinFBE users to select a custom color. Works perfectly but if the dialog is cancelled it returns a value of 0 which is of course a valid color (black).

So, maybe instead of having the function return a COLORREF, probably change that to a LONG (unsigned valued) so we can return a value of -1 to indicate that the dialog was closed.

Code: [Select]
' ========================================================================================
' Displays the choose color dialog.
' - hParent = Handle to the parent window or null.
' - rgbDefaultColor = Optional. Initial default color.
' - lpCustColors = Optional. A pointer to an array of 16 values that contain red, green,
'   blue (RGB) values for the custom color boxes in the dialog box. If the user modifies
'   these colors, the system updates the array with the new RGB values.
' Return value: The selected color.
' ========================================================================================
PRIVATE FUNCTION AfxChooseColorDialog (BYVAL hParent AS HWND, BYVAL rgbDefaultColor AS COLORREF = 0, BYVAL lpCustColors AS COLORREF PTR = NULL) AS LONG
   DIM ColorSpec AS CHOOSECOLORW, lCustomColor(15) AS LONG
   ColorSpec.lStructSize  = SIZEOF(ColorSpec)
   ColorSpec.hwndOwner    = hParent     ' // Handle of owner window.  If 0, dialog appears at top/left.
   IF lpCustColors = NULL THEN
      FOR lCounter AS LONG = 0 TO 15
         lCustomColor(lCounter) = BGR(0, lCounter * 16, (15 - lCounter) * 16)
      NEXT
      ColorSpec.lpCustColors = VARPTR(lCustomColor(0))
   ELSE
      ColorSpec.lpCustColors = lpCustColors
   END IF
   ColorSpec.rgbResult = rgbDefaultColor
   ColorSpec.Flags = ColorSpec.Flags OR CC_RGBINIT OR CC_FULLOPEN
   Function =  Iif( ChooseColorW(@ColorSpec), Colorspec.rgbResult, -1)
End Function
' ========================================================================================

I have implemented this change with my set of includes and it works perfectly.



Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master FireFly Member
  • *****
  • Posts: 2732
    • Josť Roca Software
Re: AfxChooseColorDialog
« Reply #1 on: September 03, 2017, 01:08:19 PM »

No problem. I have changed it.