I searched both this messageboard and the web for an answer to this question, but i could not find one, so I thought that you nice people might be able to help.;)

I have an array of 32bit colors, pointed to by the DWORD pts.
Its size is given by hei*wid, and I used CreateDIBitmap to convert this array into an HBITMAP, which i then select into a memory dc - mdc. mdc was created from a call to CreateCompatibleDC on hdc, which is the DC for my window's client area. mdc is then BitBlitted onto hdc to display the bitmap on the screen. All of this works fine, except the 32bit bitmap is displayed as a monochrome bitmap. Here is the code pertaining to the CreateDIBitmap

.IF(npts) ;if there are points to display

;fill the BITMAPINFOHEADER struct
mov inf.bmiHeader.biSize,SIZEOF BITMAPINFOHEADER
mov eax,wid
mov inf.bmiHeader.biWidth,eax
mov eax,hei
neg eax ;top down, not bottom up
mov inf.bmiHeader.biHeight,eax
mov inf.bmiHeader.biPlanes,1
mov inf.bmiHeader.biBitCount,32 ;32bit color
mov inf.bmiHeader.biCompression,BI_RGB ;no compression
mov eax,0
mov inf.bmiHeader.biSizeImage,eax
mov inf.bmiHeader.biXPelsPerMeter,eax
mov inf.bmiHeader.biYPelsPerMeter,eax
mov inf.bmiHeader.biClrUsed,eax
mov inf.bmiHeader.biClrImportant,eax

mov inf.bmiColors,NULL

;obmp is the default bitmap. If it exists, it is used to unselect
;the old bitmap. The old bitmap is the deleted and a new one
;is created.

mov eax,obmp
test eax,eax
je lbl1
invoke SelectObject,mdc,obmp
invoke DeleteObject,map
mov ecx,pts
invoke CreateDIBitmap,mdc,ADDR,inf.bmiHeader,CBM_INIT,ecx,ADDR inf,NULL
mov map,eax

invoke SelectObject,mdc,map
.IF(eax!=map) ;if the bitmap selected out was the
mov obmp,eax ;default bitmap, store it in obmp

I would much appreciate it if someone could tell me what is wrong with this code and explain why it creates a monochrome bitmap.
Posted on 2002-03-17 08:32:13 by LOLTH
When you create a DC with CreateCompatibleDC, it has initially a monochrome bitmap (1x1) selected in it. And the CreateDIBitmap reference says that the DDB that is created will match the bit depth of your reference DC. So I think you should select a 32-bit bitmap in mdc before you use CreateDIBitmap, or use CreateDIBSection with DIB_RGB_COLORS in the iUsage parameter.
Posted on 2002-03-17 10:56:05 by micmic
Afternoon, LOLTH.

Have you tried using CreateDIBSection?

Attached is an example of using it. It may be similar to what you're trying to do with CreateDIBitmap.

To reassemble the proggy, run makeit.bat.

Posted on 2002-03-17 15:55:09 by Scronty
All I had to do to solve the problem was to pass the client area DC to CreateDIBitmap instead of passing the memory DC. The client DC has the right color depth already selected. Thanks for the help, micmic and Scronty.
Posted on 2002-03-17 18:55:11 by LOLTH