Help Center

AfxCreateDIBSectionfunction

Creates a DIB section.

WindowsfunctionAfxWin.incdocumented

Syntax

FUNCTION AfxCreateDIBSection (BYVAL hdc AS HDC, BYVAL nWidth AS DWORD, BYVAL nHeight AS DWORD, BYVAL bpp AS LONG = 0, BYVAL ppvBits AS ANY PTR PTR = NULL) AS HBITMAP

Parameters

NameDescription
hdcA handle to the device context.
nWidthThe width of the bitmap, in pixels.
nHeightThe height of the bitmap, in pixels.
bppThe number of bits-per-pixel. If this parameter is 0, the function will use the value returned by GetDeviceCaps(hDC, BITSPIXEL_).
ppvBitsOut, optional. A pointer to a variable that receives a pointer to the location of the DIB bit values. Can be NULL.

Return value

If the function succeeds, the return value is a handle to the newly created DIB, and ppvBits points to the bitmap bit values.

If the function fails, the return value is NULL, and ppvBits is NULL. The function can fail if one or more of the input parameters is invalid.

This function can return the following value: ERROR_INVALID_PARAMETER (One or more of the input parameters is invalid).

Description

Creates a DIB section.

Remarks

You must delete the returned bitmap handle with DeleteObject when no longer needed to avoid memory leaks.

You cannot paste a DIB section from one application into another application.

AfxCreateDIBSection does not use the BITMAPINFOHEADER parameters biXPelsPerMeter or biYPelsPerMeter and will not provide resolution information in the BITMAPINFO structure.

Example

DIM hdcWindow AS HDC, hbmp AS HBITMAP, pvBits AS ANY PTR hdcWindow = GetWindowDC(hwnd) ' where hwnd is the handle of the wanted window or control hbmp = AfxCreateDIBSection(hdcWindow, 10, 10, @pvBits) ReleaseDC(hwnd, hdcWindow)

Reference

  • Include file AfxWin.inc
  • Defined in AfxNova/AfxWin.inc:3743
  • Documented in Windows/Windows Procedures.md
  • Topic: Windows Procedures