Author |
Topic: Colour of brush at startup (Read 473 times) |
|
JB91
New Member
member is offline


Gender: 
Posts: 47
|
 |
Colour of brush at startup
« Thread started on: Nov 17th, 2010, 7:18pm » |
|
I am creating a drawing program, but I want the colour of the brush to be the same when you go on it again. I have created this (part of it):
Code: DIM cc{lStructSize%, hwndOwner%, hInstance%, \
\ rgb{r&,g&,b&,z&}, lpCustColors%, flags%, \
\ lCustData%, lpfnHook%, lpTemplateName%}
DIM cb%(15)
cc.lStructSize% = DIM(cc{})
cc.hwndOwner% = @hwnd%
cc.lpCustColors% = ^cb%(0)
defalut%=0
brushcol% = VAL(FNgetinistring(@dir$+"Drawing Settings.INI", "startup", "brushcol"))
GCOL brushcol%
ON MOUSE PROCmouse(@wparam%):RETURN
REPEAT
MOUSE X%, Y%, B%
IF (B% AND 4) THEN
COLOUR 0, cc.rgb.r&, cc.rgb.g&, cc.rgb.b&
IF Ok% DRAW X%, Y% : Ch% = TRUE
ELSE
Ok% = FALSE
MOVE X%, Y%
ENDIF
UNTIL FALSE
END
DEF PROCmouse(M%)
IF M% = 1 Ok% = TRUE
IF M% = 2 PROCsetcol
ENDPROC
DEF PROCsetcol
SYS "ChooseColor", cc{} TO brushcol%
IF brushcol% COLOUR 1, cc.rgb.r&, cc.rgb.g&, cc.rgb.b&
PROCputinistring(@dir$+"Bryantdraw Settings.INI", "startup", "brushcol", STR$(brushcol%))
GCOL brushcol%
ENDPROC
DEF FNgetinistring(file$, section$, key$)
LOCAL buf%
DIM buf% LOCAL 255
SYS "GetPrivateProfileString", section$, key$, "", buf%, 256, file$
= $$buf%
DEF PROCputinistring(file$, section$, key$, info$)
LOCAL res%
SYS "WritePrivateProfileString", section$, key$, info$, file$ TO res%
IF res% = 0 ERROR 100, "Couldn't write to file "+file$
ENDPROC
The brush colour does not seem to change in PROCsetcol.
Josh.
|
« Last Edit: Nov 17th, 2010, 7:19pm by JB91 » |
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Colour of brush at startup
« Reply #1 on: Nov 17th, 2010, 9:39pm » |
|
on Nov 17th, 2010, 7:18pm, JB91 wrote:The brush colour does not seem to change in PROCsetcol. |
|
You don't actually store the colour in the INI file! All you store is the value of brushcol% which is a Boolean returned from ChooseColor, i.e. it will be 0 (if the user clicked Cancel) or 1 (if the user clicked OK). I suggest you change the name of the variable from brushcol% to something like colok% because that will emphasise what the variable actually does.
To save/restore the colour you will need to store the values of cc.rgb.r& (red), cc.rgb.g& (green) and cc.rgb.b& (blue) in the INI file. You can combine them into one RGB value for convenience, or you can even store the entire cc{} structure in the file using WritePrivateProfileStruct.
Incidentally, don't put your INI file in @dir$ (typically that directory is writable only by an administrator so isn't a suitable place to hold 'user data'). Instead put it in @usr$ or (even better) use FNspecialfolder(26) to get the path to the Application Data folder and store it there.
Richard.
|
|
Logged
|
|
|
|
|