BCX_BITMAP function

Purpose:

BCX_BITMAP creates a static control then loads a bitmap from a file and displays the bitmap on the static control.

Syntax:

hCtl = BCX_BITMAP(BitmapFile AS STRING, _
                    hwndParent AS HWND, _
                      CtlID AS INTEGER, _
                       Xpos AS INTEGER, _
                       Ypos AS INTEGER, _
                      Width AS INTEGER, _
                     Height AS INTEGER  _
                     [, Res AS INTEGER] _
                [, WinStyle AS INTEGER] _
              [, ExWinStyle AS INTEGER])

Return Value:

  • Data type: HWND
    hCtl The handle of the static control containing the bitmap, if the control was created. If the function fails, the return value is NULL.
    👉 The returned handle, hCtl, is not a handle of the bitmap; it is to the static control containing the bitmap.

Parameters:

  • Data type: STRING
    BitmapFile The file containing bitmap to be loaded. If the bitmap is to be loaded from a resource then this parameter must be empty ("").
    👉 If a NULL image pointer, (""), is specified without specifying a value for the Res parameter, a HWND control will be returned from the function but with no immediate image being displayed.
  • Data type: HWND
    hwndParent The handle of the window on which the control-bitmap will be placed.
  • Data type: INTEGER
    CtlID The child-window identifier used to notify its parent about events.
  • Data type: INTEGER
    Xpos The horizontal placement of upper left corner of the control-bitmap
  • Data type: INTEGER
    Ypos The vertical placement of upper left corner of the control-bitmap
  • Data type: INTEGER
    Width Sets the width of displayed bitmap. BCX_BITMAP will autosize the bitmap to the size of the control if the Width and Height parameters are both zero.
  • Data type: INTEGER
    Height Sets the height of displayed bitmap. BCX_BITMAP will autosize the bitmap to the size of the control if the Width and Height parameters are both zero.
  • Data type: INTEGER
    Res [OPTIONAL] The bitmap resource identifier, used if the bitmap is to be retrieved as a resource.
  • Data type: INTEGER
    WinStyle [OPTIONAL] If the WinStyle parameter is used, the default Window Style for a BCX_BITMAP control, WS_CHILD | WS_VISIBLE | SS_BITMAP | WS_TABSTOP, is replaced with the value in WinStyle. For more information, visit the Microsoft Static Control Styles webpage and the Microsoft Window Styles webpage
  • Data type: INTEGER
    ExWinStyle [OPTIONAL] The default window Extended Window Style for a BCX_BITMAP control is 0. For more information, visit the Microsoft Extended Window Styles webpage.

Remarks:

An image can be set into such a control at runtime using the SET_BCX_BITMAP2 function.

Example:

Save the example code below as bcx_bitmap.bas. The example will load, into a window, from a resource file, this bitmap:

Click here to download a .zip containing the bcx_bitmap.bmp resource.

Extract it to the same directory as bcx_bitmap.bas.

Save the following batch file, as Build.bat, into the same directory as bcx_bitmap.bas and run Build.bat to compile and run the example.

Build.bat Compilation Batch file:

CALL povars64.bat
bc bcx_bitmap

bcx_bitmap.bas

GUI "BCX_BITMAP"

$IPRINT_OFF

$RESOURCE "$PELLES$\bin\porc.exe"
 
$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"
 
$LINKER "$PELLES$\Bin\polink _
                    -release _
                -machine:X64 _
          -subsystem:windows _
             -OUT:$FILE$.exe _
                  $FILE$.obj _
                  $FILE$__.res"

$ONEXIT "$FILE$.exe"
 
BCX_RESOURCE 500 BITMAP "bcx_bitmap.bmp"

SUB FORMLOAD
  GLOBAL Form1 AS HWND
  GLOBAL Bmp1  AS CONTROL
  Form1 = BCX_FORM("BCX_BITMAP", 0, 0, 130, 115)
  BCX_SET_FORM_COLOR(Form1,QBCOLOR(15))
  Bmp1 = BCX_BITMAP("", Form1, 115, 10, 10, 0, 0, 500)
  CENTER(Form1)
  SHOW(Form1)
END SUB

BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_CLOSE
    IF MSGBOX("Are you sure?", "Quit Program?", MB_YESNO) = IDYES THEN
      DestroyWindow(Form1)
    END IF
    EXIT FUNCTION
  END SELECT
END EVENTS

Remarks:

The default window Style for a BCX_BITMAP control also can be changed by using the MODSTYLE function.

For an example of the BCX_BITMAP function see Demo.bas.


SET_BCX_BITMAP statement

Purpose:

SET_BCX_BITMAP complements the BCX_BITMAP function by allowing the bitmap image of a BCX_BITMAP control to be changed after the control has been created.

Syntax:

SET_BCX_BITMAP(hBitmapDest AS HWND, _
              BitmapFile AS STRING _
                 [, Res AS INTEGER] _
               [, Width AS INTEGER] _
              [, Height AS INTEGER])

Parameters:

  • Data type: HWND
    hBitmapDest The handle of the control, created by BCX_BITMAP, onto which the bitmap is to be set.
  • Data type: STRING
    BitmapFile The filename of bitmap to be placed on the control. This parameter is set to "" if the bitmap is to be retrieved from a resource.
  • Data type: INTEGER
    Res [OPTIONAL] The bitmap resource identifier used if the bitmap is to be retrieved from a resource.
  • Data type: INTEGER
    Width [OPTIONAL] The width to which the bitmap is to be set.
  • Data type: INTEGER
    Height [OPTIONAL] The height to which the bitmap is to be set.

Remarks:

The SET_BCX_BITMAP statement has been written so that either a file based bitmap or a resource based bitmap can be passed to the procedure. The default setting for the optional parameter Res is 0 which means that the bitmap will be retrieved from the file specified in BitmapFile. If the bitmap is to be retrieved from a resource then the integer value of the bitmap resource handle is passed in Res and 0 is used as a parameter value for BitmapFile.

An example demonstrating the use of the SET_BCX_BITMAP is available in the Setbmp directory of the GUI_Demo.zip, downloadable from the BCX BASIC Forum post GUI Demos 2020 at https://bcxbasiccoders.com/smf/index.php?topic=390.0


SET_BCX_BITMAP2 statement

Purpose:

SET_BCX_BITMAP2 complements the BCX_BITMAP function by allowing the image in a BCX_BITMAP control to be changed after the control has been created.

Syntax:

SET_BCX_BITMAP2(hBitmapDest AS HWND, _
                 hBitmap AS HBITMAP _
                  Delete AS INTEGER])

Parameters:

  • Data type: HWND
    hBitmapDest The handle of the control, created by BCX_BITMAP, onto which the bitmap is to be placed.
  • Data type: HWND
    hBitmap The handle of the bitmap which is to be placed on the control.
  • Data type: INTEGER
    Delete [OPTIONAL] parameter Contains, as default, a value of 1. If Delete is set to 0, then the return from the function will be the previous bitmap handle.

BCX_LOADBMP function

Purpose:

BCX_LOADBMP function returns a handle to a bitmap (.bmp) image loaded from a file or loaded as a resource.

Syntax 1:

MyhBmp = BCX_LOADBMP(FileName AS STRING _
                                      0
              [, Transparent AS INTEGER])

Return Value:

  • Data type: HBITMAP
    MyhBmp The HBITMAP The handle, returned by the function.

Parameters:

  • Data type: STRING
    FileName A string specifying the path to and name of a .bmp bitmap file.
  • Data type: INTEGER
    0 Zero must be used to indicate that the bitmap is to be loaded from a file.
  • Data type: INTEGER
    Transparent [OPTIONAL] Set this parameter to 1 to load a bitmap with transparent areas.

Syntax 2:

MyhBmp = BCX_LOADBMP("", _
     Resource AS INTEGER
[, Transparent AS INTEGER])

Return Value:

  • Data type: HBITMAP
    MyhBmp The HBITMAP The handle, returned by the function.

Parameters:

  • Data type: STRING
    "" An empty string must be used to indicate that the bitmap is to be loaded as a resource.
  • Data type: INTEGER
    Resource [OPTIONAL] Value of a bitmap resource identifier.
  • Data type: INTEGER
    Transparent [OPTIONAL] Set this parameter to 1 to load a bitmap with transparent areas.

BCX_BMPHEIGHT function

Purpose:

BCX_BMPHEIGHT function returns the height of a bitmap(.bmp) image.

Syntax:

RetVal = BCX_BMPHEIGHT(hBmp AS HBITMAP)

Return Value:

  • Data type: INTEGER
    RetVal The return value, in pixels, of the the height of a bitmap (.bmp) image.

Parameters:

  • Data type: HBITMAP
    hBmp The handle of the bitmap (.bmp) image from which the height is to be retrieved.

BCX_BMPWIDTH function

Purpose:

BCX_BMPWIDTH function returns the width of a bitmap (.bmp) image.

Syntax:

RetVal = BCX_BMPWIDTH(hBmp AS HBITMAP)

Return Value:

  • Data type: INTEGER
    RetVal The return value, in pixels, of the the height of a bitmap (.bmp) image.

Parameters:

  • Data type: HBITMAP
    hBmp The handle of the bitmap (.bmp) image from which the width is to be retrieved.

BCX_PUT statement

Purpose:

BCX_PUT puts a bitmap on a window.

Syntax:

BCX_PUT(hwndDest AS HWND, _
         hBmp AS HBITMAP, _
     LeftDest AS INTEGER, _
      TopDest AS INTEGER, _
    WidthDest AS INTEGER, _
   HeightDest AS INTEGER  _
   [, RopCode AS INTEGER] _
       [, DrawHDC AS HDC])

Parameters:

  • Data type: HWND
    hwndDest The handle of the window on which the bitmap is to be placed.
    👉 If printing to a hwndDest, the DrawHDC parameter, below, is not used.
  • Data type: HBITMAP
    hBmp The handle of the bitmap to be copied to hwndDest.
  • Data type: INTEGER
    LeftDest horizontal position of upper left corner of destination of bitmap
  • Data type: INTEGER
    TopDest vertical position of upper left corner of destination of bitmap
  • Data type: INTEGER
    WidthDest width of area of destination of bitmap
  • Data type: INTEGER
    HeightDest height of area of destination of bitmap
  • Data type: INTEGER
    RopCode [OPTIONAL] specifies a raster-operation code. These codes define how the color data for the source rectangle is to be combined with the color data for the destination rectangle to achieve the final color. The default code is SRCCOPY. The following list shows some common raster operation codes:
    • BLACKNESS fills the destination rectangle using the color associated with index 0 in the physical palette.(This color is black for the default physical palette.)
    • DSTINVERT inverts the destination rectangle.
    • MERGECOPY merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator.
    • MERGEPAINT merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
    • NOTSRCCOPY copies the inverted source rectangle to the destination.
    • NOTSRCERASE combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
    • PATCOPY copies the specified pattern into the destination bitmap.
    • PATINVERT combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.
    • PATPAINT combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
    • SRCAND combines the colors of the source and destination rectangles by using the Boolean AND operator.
    • SRCCOPY copies the source rectangle directly to the destination rectangle.
    • SRCERASE combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
    • SRCINVERT combines the colors of the source and destination rectangles by using the Boolean XOR operator.
    • SRCPAINT combines the colors of the source and destination rectangles by using the Boolean OR operator.
    • WHITENESS fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
  • Data type: HDC
    DrawHDC [OPTIONAL] 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.
    👉 If printing to an HDC, the hwndDest parameter, above, must be set to 0.