Hi,
I am having some problems with ChooseColor, using FB1.05, win32. I notice in another post dated 2015 ?? that the headers for this are broken. Is that still the case? Should ChooseColor structure definition and ChooseColor function call work OK?? Code below compiles without errors but program crashes at function call. In FBedit the autocomplete lists CHOOSECOLOR and CHOOSECOLORA - what is the difference? The all capitals of the autocomplete always changes to mixed case for ChooseColor but I note example code from other posters where this is not the case. Also I do not get autocomplete options for the cc fields. Any insights welcome.
Thanks.
As the latest official FreeBasic release is from January 2016 that is even quite likely. <off-topic>Unfortunately many fixes suggest here on the forums are not contributed in form of a patch to the official FreeBasic code and then often forgotten after a while.</off-topic>
Did you try whether the latest headers (e.g. available from here: http://users.freebasic-portal.de/stw/bu ... eaders.zip) change anything? The defintion in the headers looks correct on firsth sight, yet I could easily have missed something.
ring0 wrote:In FBedit the autocomplete lists CHOOSECOLOR and CHOOSECOLORA - what is the difference?
The Win32 API provides ANSI and Unicode versions of many API functions and structures dealing with strings. The former have a "A" suffix, while the latter have a "W" suffix. The name without suffix (if available) redirects to one or the other depending on wheter "UNICODE" is defined (or not). See also https://msdn.microsoft.com/en-us/librar ... 46830.aspx on the bottom.
#Include once "windows.bi"
#Include Once "win/commdlg.bi"
dim as COLORREF customColors(0 to 15)
Dim As ChooseColor cc
cc.lStructSize = SizeOf(cc)
cc.rgbResult = BGR(255,255,255)
cc.lpCustColors = @customColors(0)
cc.Flags = CC_FULLOPEN or CC_RGBINIT
If (ChooseColor(@cc)) Then
print "Color chosen: "; hex(cc.rgbResult)
else
print "cancelled"
EndIf
Your error is probably (concluding from the code excerpt you showed) that you are passing an invalid pointer in the cc.lpCustColors value. The documentation doesn't mention that this value may be NULL.