This would be handy to have!
Error 1 - "Constant name 'true' cannot share the name of a reserved word or command."
No prob, I just replaced "true" with "1" in the one placed you used it. You never used the constant "false" so I removed it as well.
Error 2 - It's not giving me the correct color. When I pick pure blue, it gives me pure red (FF0000). When I pick pure red, it gives me pure blue (FF). But when I pick green, I get green (FF00). Something about the position of the rgb values? Maybe a big/little endian prob?
I'll try to code a fix and post.
Also - It should be possible to allow editing the custom colors, but if you write them with random values every time you open the picker, that would preclude saving them. I'll check to see if there is a parameter that lets them be saved/edited.
EDIT:
Using this:
result=0xFF000000+memblock byte(mbNo,12)*65536+(memblock byte(mbNo,13)*256)+memblock byte(mbNo,14)
instead of this:
result=memblock dword(mbNo,12)
seems to get the byte order in correct position. So here's what I came up with for the whole thing... except that the DWORD returned is negative, so a "cancel" actually returns a valid color, white. So maybe the color needs to be inverted
after it comes back from the function, so that the function can return -1 on a cancel?
Hmm...
FURTHER EDIT: I just changed it to return a 1 instead of -1 for a cancel, then it works fine.
MORE EDIT: Aha! Declaring "result" as DWORD does the trick, so the function CAN return -1 as a "cancel".
// colour chooser flag constants
#constant cc_anycolor 0x00000100
#constant cc_enablehook 0x00000010
#constant cc_enabletemplate 0x00000020
#constant cc_enabletemplatehandle 0x00000040
#constant cc_fullopen 0x00000002
#constant cc_preventfullopen 0x00000004
#constant cc_rgbinit 0x00000001
#constant cc_showhelp 0x00000008
#constant cc_solidColor 0x00000080
result as DWORD
load dll "comdlg32.dll",1
if dll exist(1)=1
print "comdlg32.dll loaded ok"
else
print "comdlg32.dll loading FAILURE!!"
wait key
end
endif
result=ChooseColour()
if result<>1
ink result, 0
box 100,100,200,200
ink 0xFFFFFFFF
print str$(result)+" "+hex$(result)
else
print "Cancelled"
endif
wait key
delete dll 1
end
function ChooseColour()
// Syntax
` typedef struct {
` DWORD lStructSize;
` HWND hwndOwner;
` HWND hInstance;
` COLORREF rgbResult;
` COLORREF *lpCustColors;
` DWORD Flags;
` LPARAM lCustData;
` LPCCHOOKPROC lpfnHook;
` LPCTSTR lpTemplateName;
` CHOOSECOLOR, *LPCHOOSECOLOR;
`
` see http://msdn.microsoft.com/en-us/library/ms646830(v=vs.85).aspx for more info
` declare varbs
local mbNo as integer : mbNo=find free memblock()
local curPos as integer : curPos=0
local colRefArrayPtr as integer : colRefArrayPtr=0
` create memblock to use as struct
make memblock mbNo,36
` create an array to store the custom palette
dim colRefArray(15) `as dword
` fill the custom palette - needs set alpha command to correctly store colour values
for a=0 to 15
` just fill with randoms atm
colRefArray(a)=set alpha(rgb(rnd(255),rnd(255),rnd(255)),0)
next a
` get the array pointer
colRefArrayPtr=get array item ptr(colRefArray(),0)
` set somes flags - see constants list above
flags=cc_anycolor+cc_rgbinit+cc_fullopen
` fill memblock with data
write memblock dword mbNo,curPos,36 : inc curPos,4
write memblock dword mbNo,curPos,get dbpro window() : inc curPos,4
write memblock dword mbNo,curPos,0 : inc curPos,4
write memblock dword mbNo,curPos,set alpha(rgb(255,0,0) ,0) : inc curPos,4
write memblock dword mbNo,curPos,colRefArrayPtr : inc curPos,4
write memblock dword mbNo,curPos,flags : inc curPos,4
write memblock dword mbNo,curPos,0 : inc curPos,4
write memblock dword mbNo,curPos,0 : inc curPos,4
write memblock dword mbNo,curPos,0 : inc curPos,4
lpColorChooser=get memblock ptr(mbNo)
` reqResult=0 if cancelled; or 1 if OK
reqResult=call dll(1,"ChooseColorA",lpColorChooser)
` set output depending if cancelled (-1) or ok (selected colour)
if reqResult=0
` cancelled
result=1
else
` ok
result=0xFF000000+memblock byte(mbNo,12)*65536+(memblock byte(mbNo,13)*256)+memblock byte(mbNo,14)
endif
` clean up
delete memblock mbNo
undim colRefArray()
endfunction result
For the custom colors...
lpCustColors
COLORREF
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. To preserve new custom colors between calls to the ChooseColor function, you should allocate static memory for the array. To create a COLORREF color value, use the RGB macro.
Well, I've no clue how to allocate static memory. Maybe declaring the array of 16 colors
outside of the function, and restoring them when the function is called?