views:

49

answers:

1

Hi

I am having trouble in CE BltBit from a previously created compatable hdc to device's hdc.

The following code works:

 hdc = pdis->hDC;
 FillRect(hdc, &(pdis->rcItem), (HBRUSH)GetStockObject(BLACK_BRUSH));
 ImageList_Draw(himl, imageIndex, hdc, 15 , 30, ILD_NORMAL);

However the following just draws the black rectangle and does not put the image on top.

        hdc = pdis->hDC;
        hdcmem = CreateCompatibleDC(hdc);
        FillRect(hdc, &(pdis->rcItem), (HBRUSH)GetStockObject(BLACK_BRUSH));
        ImageList_Draw(himl, imageIndex, hdcmem, 0 , 0, ILD_NORMAL);
        BitBlt(hdc, 15, 30, 130, 100, hdcmem, 0, 0, SRCCOPY);

Any ideas most welcome.

Best regards E

+2  A: 

CreateCompatibleDC doesn't do what you think it does. From the linked page:

Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context. This may be done by using CreateCompatibleBitmap to specify the height, width, and color organization required in the function call.

Device contexts are an abstraction. There must be a storage behind them -- a screen or, in your case, a bitmap.

avakar
Haha.. avakar you are dead right. Thank you. I did think that there was a memory block behind a DC. You have answered some other niggles that I have had in my mind. Thanks again.
EndsOfInvention