Author Topic: Error with using RGB()  (Read 1590 times)

0 Members and 2 Guests are viewing this topic.

chrisc

  • Guest
Error with using RGB()
« 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


JRS

  • Guest
Re: Error with using RGB()
« Reply #1 on: March 18, 2018, 11:43:50 AM »
rgb is a Windows API macro, not a function.

Arnold

  • Guest
Re: Error with using RGB()
« Reply #2 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

chrisc

  • Guest
Re: Error with using RGB()
« Reply #3 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"

JRS

  • Guest
Re: Error with using RGB()
« Reply #4 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.

Aurel

  • Guest
Re: Error with using RGB()
« Reply #5 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

chrisc

  • Guest
Re: Error with using RGB()
« Reply #6 on: March 18, 2018, 12:43:26 PM »
Thanxx all
i finally found the solution

JRS

  • Guest
Re: Error with using RGB()
« Reply #7 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

Arnold

  • Guest
Re: Error with using RGB()
« Reply #8 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