1. WIN32LIB getColorDialog

Hi again !

Now, a question about the popup getColorDialog() : 
How to specify 'in advance' the 16 users specified's colors ?
I use very often some personalised colors, so I don't want to re-specify 
them each time I run my prog.

Gwen

new topic     » topic index » view message » categorize

2. Re: WIN32LIB getColorDialog

Hi Gwen,
> Now, a question about the popup getColorDialog() :
> How to specify 'in advance' the 16 users specified's colors ?
> I use very often some personalised colors, so I don't want to re-specify
> them each time I run my prog.
>

This is good enhancement idea and easy to implement. I'll add this to the
next version and send you an advanced updated if you like.

------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

new topic     » goto parent     » topic index » view message » categorize

3. Re: WIN32LIB getColorDialog

Hi Gwen,
here is some code you can use.

Replace the getColorDialog() function in your win32lib with these two
functions....

--/topic Dialogs
--/func getCustomColors( )
--/desc Gets the user defined custom colors set by the standard Color dialog
--/ret Sequence: A 16-element list of colors.
--The standard Windows color dialog reserves places for 16 custom defined
-- colors. This function returns whatever they are currently set to. This
-- is usually done immediately after calling getColorDialog() to save
-- any colors that may have been defined by the user.
--
-- Example:
--
--/code
--          -- get the custom colors.
--          sequence ccolors
--          ccolors = getCustomColors( )
--/endcode
with trace
global function getCustomColors()
    sequence colors

    trace(1)
    colors = repeat(0, 16)

    for i = 1 to 16 do
        colors[i] = peek4u(customColors + (i - 1) * 4)
    end for

    return colors
end function

-
--/topic Dialogs
--/func getColorDialog( integer window, object defaultcolor )
--/desc "Get Color" Dialog
--/ret Selected color, or default color if nothing selected.
-- Calling this function brings up the modal "Select Color" dialog, allowing
-- the user to select a color from the default color list, or add a color to
-- the custom color list.
--
-- If /b defaultcolor is an atom, it represents the
-- default color to select. Passing -1 specifies that
-- the color black (#000000) is the default color.
--
-- /b defaultcolor can also be a sequence. The first element is the defaul
color
-- and the second element is a list of up to 16 colors. These are used to
set the
-- customer color list used by the dialog. Note, if any of these 16 colors
in
-- this parameter is #FFFFFFFF, then the corresponding custom color is not
-- changed.
--
-- Example:
--
--/code
--          -- get a color; red is the default
--          atom color
--          color = getColorDialog( Window, Red )
--
--          -- get a color; red is the default
--          atom color
--          sequence grays
--          grays = repeat(0, 16)
--          for i = 1 to 16 do
--              grays[i] = rgb(i*16, i*16, i*16)
--          end for
--          color = getColorDialog( Window,
--                   {Red, grays} )
--/endcode
global function getColorDialog(atom id, object defaultColor )

    atom mem, result, color

    if id = 0 then
        id = mainWindow
    end if

    if atom(defaultColor) then
        defaultColor = {defaultColor, repeat(#FFFFFFFF, 16)}
    end if

    for i = 1 to length(defaultColor[2]) do
        if defaultColor[2][i] != #FFFFFFFF then
            poke4(customColors + (i - 1) * 4, defaultColor[2][i])
        end if
        if i = 16 then
            exit
        end if
    end for

    -- Allocate memory for the dialog
    mem = acquire_mem(0, SIZEOF_COLORDLG )

    -- set up
    store( mem, COLORDLG_lStructSize, SIZEOF_COLORDLG )
    store( mem, COLORDLG_hwndOwner, getHandle(id) )
    store( mem, COLORDLG_lpCustColors, customColors )

-- NEW! 0.45m always use default color
    -- default color
    store( mem, COLORDLG_Flags, CC_RGBINIT )
    store( mem, COLORDLG_rgbResult, defaultColor[1] )

    -- call the routine
    result = w32Func(xColorDlg, {mem})
    if result then
        -- fetch the color
        color = fetch( mem, COLORDLG_rgbResult )

    else
-- NEW! 0.45m return default color instead of -1
        -- cancelled
        color = defaultColor[1]

    end if

    -- release the buffer
    release_mem( mem )

    return color

end function

-----------------------

As you can see, there is a getCustomColors() function. This returns the set
of 16 custom defined colors. You can save these to disk and use them next
time you run the program.

The other change is to getColordialog() function. The second parameter can
now be a sequence in the form {Defaultcolor, DefaultCustomerColors} where
the default custom colors is a sequence of (up to 16) color values.

For example...

   thecolor = getColorDialog(mywin, {Red, SavedColors})
where SavedColors is a sequence of 16 color values retrieved from disk after
saving the colors returned by getCustomerColors() function.

------
Derek Parnell
Melbourne, Australia
"To finish a job quickly, go slower."

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu