怎样创建 HBITMAP?

解决方案 »

  1.   

    是指创建一个位图吗?
    用:
    HBITMAP CreateBitmap(
      int nWidth,         // bitmap width, in pixels
      int nHeight,        // bitmap height, in pixels
      UINT cPlanes,       // number of color planes used by device
      UINT cBitsPerPel,   // number of bits required to identify a color
      CONST VOID *lpvBits // pointer to array containing color data
    );
      

  2.   

    HBITMAP hBitmap;
    hBitmap=LoadBitmap(...);
      

  3.   

    CBitmap::CreateBitmap 
    BOOL CreateBitmap( int nWidth, int nHeight, UINT nPlanes, UINT nBitcount, const void* lpBits );Return ValueNonzero if successful; otherwise 0.ParametersnWidthSpecifies the width (in pixels) of the bitmap.nHeightSpecifies the height (in pixels) of the bitmap.nPlanesSpecifies the number of color planes in the bitmap.nBitcountSpecifies the number of color bits per display pixel.lpBitsPoints to a short-integer array that contains the initial bitmap bit values. If it is NULL, the new bitmap is left uninitialized.
    CreateBitmapThe CreateBitmap function creates a bitmap with the specified width, height, and color format (color planes and bits per pixel).Const OBJ_BITMAP = 7
    Const OBJ_BRUSH = 2
    Const OBJ_FONT = 6
    Const OBJ_PAL = 5
    Const OBJ_PEN = 1
    Const OBJ_EXTPEN = 11
    Const OBJ_REGION = 8
    Const OBJ_DC = 3
    Const OBJ_MEMDC = 10
    Const OBJ_METAFILE = 9
    Const OBJ_METADC = 4
    Const OBJ_ENHMETAFILE = 13
    Const OBJ_ENHMETADC = 12
    Private Declare Function GetNearestColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    Private Declare Function GetObjectType Lib "gdi32" (ByVal hgdiobj As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Sub Form_Load()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim nDC As Long, nBitmap As Long
        nDC = CreateCompatibleDC(Me.hdc)
        'Create a Black/White bitmap
        nBitmap = CreateBitmap(10, 10, 1, 1, ByVal 0&)
        SelectObject nDC, nBitmap
        'GetObjectType
        Select Case GetObjectType(nBitmap)
            Case OBJ_BITMAP
                MsgBox "Object type: Bitmap"
            Case OBJ_BRUSH
                MsgBox "Object type: Brush"
            Case OBJ_FONT
                MsgBox "Object type: Font"
            Case OBJ_PAL
                MsgBox "Object type: Pal"
            Case OBJ_PEN
                MsgBox "Object type: Pen"
            Case OBJ_EXTPEN
                MsgBox "Object type: ExtPen"
            Case OBJ_REGION
                MsgBox "Object type: Region"
            Case OBJ_DC
                MsgBox "Object type: Device Context"
            Case OBJ_MEMDC
                MsgBox "Object type: Memory Device Context"
            Case OBJ_METAFILE
                MsgBox "Object type: Metafile"
            Case OBJ_METADC
                MsgBox "Object type: Metafile DC"
            Case OBJ_ENHMETAFILE
                MsgBox "Object type: Enhanched Meatfile"
            Case OBJ_ENHMETADC
                MsgBox "Object type: Enhanched Meatfile DC"
        End Select
        MsgBox "Nearest color: " + GetNearestColor(nDC, vbYellow)
        'Clean up
        DeleteDC nDC
        DeleteObject nBitmap
    End Sub
      

  4.   

    http://expert.csdn.net/Expert/topic/2815/2815361.xml?temp=.9968836
      

  5.   

    WORD    wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};     HBITMAP hbm ;
      hbm = ::CreateBitmap ( 8 , 8, 1 , 1 , wHatchBmp ) ;我已经作到以上的代码了,但是只是单色的, 我想显示多色,让hbm显示任意颜色,有谁知道怎么写么上边的代码已经能够显示在CButton上了
    CButton m_btnColor ;
    m_btnColor.SetBitmap ( hbm ) ;我想把COLORREF的颜色放在HBITMAP里边,那位知道
    CreateBitmap的参数怎么设置?CCOLORREF crColor ;急啊 ,为了这个问题我用不同的问法开了好几个贴了
      

  6.   

    HPEN hpen, hpenOld;
        HBRUSH hbrush, hbrushOld;    // Create a green pen.
        hpen = CreatePen(PS_SOLID, 10, RGB(0, 255, 0));
        // Create a red brush.
        hbrush = CreateSolidBrush(RGB(255, 0, 0));    // Select the new pen and brush, and then draw.
        hpenOld = SelectObject(hdc, hpen);
        hbrushOld = SelectObject(hdc, hbrush);
      

  7.   

    The CreateBitmap function creates a device-dependent bitmap. After a bitmap is created, it can be selected into a device context by calling the SelectObject function. However, the bitmap can only be selected into a device context if the bitmap and the DC have the same format.The CreateBitmap function can be used to create color bitmaps. However, for performance reasons applications should use CreateBitmap to create monochrome bitmaps and CreateCompatibleBitmap to create color bitmaps. Whenever a color bitmap returned from CreateBitmap is selected into a device context, the system checks that the bitmap matches the format of the device context it is being selected into. Because CreateCompatibleBitmap takes a device context, it returns a bitmap that has the same format as the specified device context. Thus, subsequent calls to SelectObject are faster with a color bitmap from CreateCompatibleBitmap than with a color bitmap returned from CreateBitmap.If the bitmap is monochrome, zeros represent the foreground color and ones represent the background color for the destination device context.If an application sets the nWidth or nHeight parameters to zero, CreateBitmap returns the handle to a 1-by-1 pixel, monochrome bitmap.When you no longer need the bitmap, call the DeleteObject function to delete it. Windows 95/98/Me: The created bitmap cannot exceed 16MB in size.