BCX_PSET function

Purpose: BCX_PSET sets the pixel located at X% (horizontal) Y% (vertical) to the color represented by the RGB color code in Pen.


Syntax:

 RetVal% = BCX_PSET(hWnd, X%, Y% [, Pen, DrawHDC])

Parameters:

  • hWnd Identifies the window where drawing takes place.
  • Xpos% X-coordinate of the pixel.
  • Ypos% Y-coordinate of the pixel.
  • Pen [OPTIONAL] integer representing the RGB color code. The default is 0 which is a black pen.
  • DrawHDC [OPTIONAL] HDC (Handle to Device Context) pointing to an already open HDC. This is useful if a device context is to be written to many times. In this case the programmer is responsible for closing the HDC at the appropriate time.

Return Value:

  • RetVal%, the return value, is the RGB value to which the function sets the pixel. This value may differ from the color specified by PEN. That can happen when an exact match for the specified color cannot be found. If the function fails, the return value is -1.

Example:


 GUI "BCXStarField"
  
 CONST StarCount  = 200
 CONST FactorX    =  -1
 CONST FactorY    =   0
 CONST DirectionX =  -1
 CONST DirectionY =   0
  
 SUB FORMLOAD
   GLOBAL Form1 AS HWND
   GLOBAL Max_X
   GLOBAL Max_Y
   Form1 = BCX_FORM("BCX Star Field", 0, 0, 300, 250)
   BCX_SET_FORM_COLOR(Form1, 0)
   CENTER(Form1)
   SHOW(Form1)
 END SUB
  
 BEGIN EVENTS
   SELECT CASE CBMSG
  
   CASE WM_CREATE
     Max_X = 639
     Max_Y = 479
     CALL INIT_STARS
     EXIT FUNCTION
  
   CASE WM_SIZE
     Max_X =  LOWORD(lParam)
     Max_Y =  HIWORD(lParam)
     CALL INIT_STARS
     EXIT FUNCTION
  
   CASE WM_PAINT
     ProcessPlane(  1, StarCount * 0.333, 1)
     ProcessPlane( 71, StarCount * 0.666, 2)
     ProcessPlane(141, StarCount, 3)
     EXIT FUNCTION
  
   END SELECT
 END EVENTS
  
 SUB INIT_STARS
   DIM RAW I,Tmp
   GLOBAL  X [StarCount+1]
   GLOBAL  Y [StarCount+1]
   FOR I  = 0 TO StarCount
     Tmp  = RND * Max_X
     X[I] = Tmp
     Tmp  = RND * Max_Y
     Y[I] = Tmp
   NEXT
 END SUB
  
 SUB ProcessPlane(Start1, End1, Speed1)
   DIM LOCAL I, Tmp, Tmp1, Tmp2, T, Kol
   SLEEP(20)
   FOR I  = Start1 TO End1
     Tmp1 = X[I]
     Tmp2 = Y[I]
     T    =  FactorX * Speed1
     Kol  = RND * QBCOLOR(0)
     BCX_PSET(Form1, Tmp1, Tmp2, Kol)
     Tmp  = X[I]
     INCR Tmp,T
     T    =  FactorY * Speed1
     X[I] =  Tmp
     Tmp  = Y[I]
     INCR Tmp,T
     Y[I] =  Tmp
     Tmp = X[I]
     IF Tmp <=  -1 THEN
       X[I]  =  Max_X
       Tmp   =  RND * Max_Y
       Y[I]  =  Tmp
     END IF
     Tmp = X[I]
     IF Tmp >=  Max_X + 1 THEN
       X[I]  =  0
       Tmp   =  RND * Max_Y
       Y[I]  =  Tmp
     END IF
     Tmp = Y[I]
     IF Tmp <=  -1 THEN
       Y[I]  =  Max_Y
       Tmp   =  RND * Max_X
       X[I]  =  Tmp
     END IF
     Tmp = Y[I]
     IF Tmp >=  Max_Y THEN
       Y[I]  =  0
       Tmp   =  RND * Max_X
       X[I]  =  Tmp
     END IF
     Tmp1 = X[I]
     Tmp2 = Y[I]
     Kol  = RND * QBCOLOR(15)
     BCX_PSET(Form1, Tmp1, Tmp2, Kol)
   NEXT
 END SUB

See also BCX_GRAFX_DEMO.bas