Oxygen Basic

Programming => Problems & Solutions => Topic started by: chrisc on March 18, 2018, 11:02:11 AM

Title: Error with using RGB()
Post by: chrisc on March 18, 2018, 11:02:11 AM
Hello

i have encounter error compiling codes with rgb -- it flag out as an undefined array ?
at this line
hBrush = CreateSolidBrush(rgb(228, 250, 238 - lOnBand))

appreciate and thanxx for any help on this


partial code is
Code: [Select]
! WindowFromDC lib "user32.dll" (sys hDc) as sys
! CreateSolidBrush lib "GDi32.dll" (byte COLORREF crColor)





' draws with color gradient
SUB DrawGradient (BYVAL hDC AS DWORD)
   LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE, hBrush AS DWORD, lOnBand AS LONG
   GetClientRect WindowFromDC(hDC), rectClient
   fStep = rectClient.bottom / 200

   FOR lOnBand = 0 TO 199
      SetRect rectFill, 0, lOnBand * fStep, rectClient.right + 1, (lOnBand + 1) * fStep
      ' paint the background -- change the first 2 colors R and G
      ' to vary the color gradient
      hBrush = CreateSolidBrush(rgb(228, 250, 238 - lOnBand))
      Fillrect hDC, rectFill, hBrush
      DeleteObject hBrush
   NEXT

END SUB

Title: Re: Error with using RGB()
Post by: JRS on March 18, 2018, 11:43:50 AM
rgb is a Windows API macro, not a function.
Title: Re: Error with using RGB()
Post by: Arnold on March 18, 2018, 11:54:48 AM
Hi Chris,

did you apply:
use corewin
If yes, you should already be able to use the (unprototyped) functions.
rgb is not built-in with OxygenBasic. You could use a function or a macro like this:

macro RGB(r,g,b) {r+(g << 8)+(b << 16)}   (This smiley should read "8")

If using the macro, I am not sure if (238-lOnBand) will work. Maybe there must be created an extra variable for this expression.

Roland
Title: Re: Error with using RGB()
Post by: chrisc on March 18, 2018, 12:09:53 PM
i have applied use corewin but still not able to compile

see the attechment,  when compile it says "unrecognized procedure or array rgb"
Title: Re: Error with using RGB()
Post by: JRS on March 18, 2018, 12:27:25 PM
Quote
(This smiley should read "8")

In Attachments and other options there is an option to disable smiles in your post.
Title: Re: Error with using RGB()
Post by: Aurel on March 18, 2018, 12:33:58 PM
You can try this small function:

Code: [Select]
Function RGB(sys red,green,blue) as sys
  sys color
  color = red
  color = color + green*256
  color = color + blue*65536
  Return color
End Function
Title: Re: Error with using RGB()
Post by: chrisc on March 18, 2018, 12:43:26 PM
Thanxx all
i finally found the solution
Title: Re: Error with using RGB()
Post by: JRS on March 18, 2018, 01:15:29 PM
Code: OxygenBasic
  1. macro RGB(r,g,b) {r+(g << 8)+(b << 16)}
  2.  

Nice!

Are you ready to try RGBA yet?  :D
Title: Re: Error with using RGB()
Post by: Arnold on March 18, 2018, 01:58:42 PM
Hi John,

thank you. I did not remember to use  the code section.
Charles has evaluated RGBA several times e.g. examples\Basics\Types.o2bas or examples\Image\StudyRaw.o2bas.

Roland