# Really frustrated...

This topic is 3183 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can someone tell me where the heck this code is going wrong. I have some memory with 8 bit values that I want do display in a picture control. IDC_DISPLAY is a picture box set to type Rectangle (although changing it to other types doesn't help). Globally I declare these variables and initialize them as follows:
CWnd *Display;
CDC *dispDC;

Display = new CWnd();
Display = GetDlgItem(IDC_DISPLAY);
dispDC = new CDC();
dispDC = Display->GetWindowDC();


Then when a timer goes off I want to take the values in this temp buffer that have been filled in and display them. Here is what I do:
CDC memDC;
CBitmap bm;
DWORD dwVal;

memDC.CreateCompatibleDC(dispDC);
//dwVal = bm.CreateBitmap(width, height, 1, 8, temp);
//dwVal = bm.SetBitmapBits(width*height, temp);
memDC.SelectObject(bm);
dispDC->BitBlt(0,0,width, height, &memDC, 0,0,SRCCOPY);


Using LoadBitmapA() works fine with predefined bitmap, but SetBitmapBits() returns an error saying it has an invalid handle and CreateBitmap() returns success but the display is blank. Can anyone tell me 1) Why this doesn't work 2) What the best way to do what I'm trying to do is The 8 bit values are grayscale so I'm assuming I have to set up a color palette but I can't even get the stupid basic stuff to work. Thanks, Andrew

##### Share on other sites
Ok here's some more info. I originally thought the temp array could just have the same number of bytes as pixels in my image, but is this correct? Do I have to have 3x the number of pixels for the RGB information?

When I call
dwVal = bm.CreateBitmap(width, height, 1, 8, temp);

then
bm.GetBitmap() everything looks ok except the bmBits pointer which is NULL