This code will use user32.dll and comdlg32.dll to call a default font dialog.

SBChooseColor(defaultColor, memCustomColors)
- defaultColors: This is the default selected color in the dialog.
- memCustomColors: In the color, there are 16 custom color boxes. If you specify a memblock number here, the custom colors are saved in this memblock.
The structure is very simple:

byte 0: red
byte 1: green
byte 2: blue
byte 3: 0 (always 0. So this means you can't just write a dword with the rgb() value)
(X16)

Use 0 if you don't want to save custom colors. The function will then search for a free memblock and delete it afterwards.

returns dword:
The functions does return the full color. So using the return value as a color would give no wrong results.

Language: 
Dark Basic Pro
Code: 
do
	color = SBChooseColor(rgb(255, 255, 255), 0)
	ink color, 0
	print "New color"
	wait key
loop
end

function SBChooseColor(defaultColor, memCustomColors)

	`Get handle
	dll = 0
	repeat : inc dll : until dll exist(dll) = 0
	load dll "user32.dll", dll
	handle = call dll(dll, "GetActiveWindow")
	delete dll dll
	
	`Get comdlg
	load dll "comdlg32.dll", dll
	
	`Create memblocks
	mem = 0
	repeat : inc mem : until memblock exist(mem) = 0

	`Flags
	flags = 0x00000100 + 0x00000002 + 0x00000001 : `CC_ANYCOLOR + CC_FULLOPEN + CC_RGBINIT

	`Default 16 colors
	if memCustomColors > 0
		ptr2 = get memblock ptr(memCustomColors)
	else
	
		`Create a new color
		mem2 = mem
		repeat : inc mem2 : until memblock exist(mem2) = 0
		
		make memblock mem2, 16*4
		ptr2 = get memblock ptr(mem2)
	endif

	size = 36
	
	`Create memblock
	make memblock mem, size
	ptr = get memblock ptr(mem)
	write memblock dword mem, 0, size
	write memblock dword mem, 4, handle : `Owner
	write memblock dword mem, 8, 0 : `Instance
	
	write memblock byte mem, 12, rgbr(defaultColor) : `Initial color and result color
	write memblock byte mem, 13, rgbg(defaultColor)
	write memblock byte mem, 14, rgbb(defaultColor)
	write memblock byte mem, 15, 0

	write memblock dword mem, 16, ptr2
	write memblock dword mem, 20, flags

	write memblock dword mem, 24, 0
	write memblock dword mem, 28, 0
	write memblock dword mem, 32, 0

	`Call DLL
	r = call dll(dll, "ChooseColorA", ptr)

	`Get the color
	color = rgb(memblock byte(mem, 12), memblock byte(mem, 13), memblock byte(mem, 14))

	`Delete memblocks
	delete memblock mem
	if memCustomColors = 0 then delete memblock mem2
	
	`Delete dll
	delete dll dll

endfunction color
5
Average: 5 (1 vote)