BBC BASIC for Windows
« Colour of brush at startup »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:19pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Colour of brush at startup  (Read 472 times)
JB91
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 47
xx 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 » User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls