scomet1
August 13th, 2004, 11:38 AM
I'm having some trouble with using bitmaps I think. Below I have code from my paint function. It draws the text, but when it does the portion of the drawing rectangle above the text is black - even if I fill the background with a white brush and there is a constant flicker. I've tried double buffering with the main window but it still flickers the same. So I'm thinking maybe my bitmap size is off or something? Another thing is that if I comment out the text drawing and run it again - many times the text still shows up! Is something not being cleared correctly???
//hdc has been passed in
HDC memdc = CreateCompatibleDC(hdc);
// determine size for bitmap - this is my window size
RECT blankRc;
rcMyBounds.left = 0;
rcMyBounds.top = 30;
rcMyBounds.right = 240;
rcMyBounds.bottom = 100;
// create the bitmap of the right size
const int width = rcMyBounds.right-rcMyBounds.left;
const int height = rcMyBounds.bottom-rcMyBounds.top;
HBITMAP textBmp = CreateCompatibleBitmap( hdc, width, height );
// load the bitmap in and draw the text onto it
HBITMAP oldBmp = (HBITMAP)SelectObject(memdc, textBmp);
CComBSTR text("example");
tx = text;
DrawText(memdc, tx, -1, &blankRc, DT_LEFT);
SelectObject(memdc, oldBmp);
DeleteDC(memdc);
//now blit it to the main screen
memdc = CreateCompatibleDC(hdc);
SelectObject(memdc, textBmp);
BitBlt(hdc, rcMyBounds.left,rcMyBounds.top, width, height, memdc, blankRc.left,0, SRCCOPY);
SelectObject(memdc, HBITMAP(NULL));
DeleteDC(memdc);
//hdc has been passed in
HDC memdc = CreateCompatibleDC(hdc);
// determine size for bitmap - this is my window size
RECT blankRc;
rcMyBounds.left = 0;
rcMyBounds.top = 30;
rcMyBounds.right = 240;
rcMyBounds.bottom = 100;
// create the bitmap of the right size
const int width = rcMyBounds.right-rcMyBounds.left;
const int height = rcMyBounds.bottom-rcMyBounds.top;
HBITMAP textBmp = CreateCompatibleBitmap( hdc, width, height );
// load the bitmap in and draw the text onto it
HBITMAP oldBmp = (HBITMAP)SelectObject(memdc, textBmp);
CComBSTR text("example");
tx = text;
DrawText(memdc, tx, -1, &blankRc, DT_LEFT);
SelectObject(memdc, oldBmp);
DeleteDC(memdc);
//now blit it to the main screen
memdc = CreateCompatibleDC(hdc);
SelectObject(memdc, textBmp);
BitBlt(hdc, rcMyBounds.left,rcMyBounds.top, width, height, memdc, blankRc.left,0, SRCCOPY);
SelectObject(memdc, HBITMAP(NULL));
DeleteDC(memdc);