Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BitBlt

0 views
Skip to first unread message

Timothy V

unread,
Jan 6, 2003, 8:50:04 AM1/6/03
to
Hi,
When I use the BitBlt() function to copy a DC to another DC, it is always in
monochrome. How do I stop this?

This is the function I'm using:
BitBlt(memDC, 0, 0, 500, 500, hdc, 0, 0, SRCCOPY)


Thanks in advance,

Timothy.


Jeff Partch

unread,
Jan 6, 2003, 9:39:38 AM1/6/03
to
"Timothy V" <tri...@msn.com> wrote in message
news:#luJ7pYtCHA.2588@TK2MSFTNGP12...

> Hi,
> When I use the BitBlt() function to copy a DC to another DC, it is
always in
> monochrome. How do I stop this?

Usually this is caused by using the memory dc to CreateCompatibleBitmap
the bitmap that will then be selected into it. The bitmap selected into
the memory dc should be based on the source dc.

--
Jeff Partch [VC++ MVP]


Timothy V

unread,
Jan 6, 2003, 10:11:57 AM1/6/03
to
Yup, that was it. Thanks. I do have another question tho... Sometimes
when I draw a line in the window, the rectangle that i specified in the
BitBlt() function is filled with black. Do you know why this is? I'll
include my WndProc function and WinMain function below. (this problem
exists in the WM_MOUSEMOVE procedure.

memDC and memBM are global.

LRESULT CALLBACK wndprocMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
lParam) {

HDC hdc;

static POINT points[1];

static int index = 0;

switch(uMsg) {

case WM_CREATE:

return 0;

case WM_PAINT:

hdc = GetDC(hwnd);

BitBlt(hdc, 0, 0, 500, 500, memDC, 0, 0, SRCCOPY);

ReleaseDC(hwnd, hdc);

break;

case WM_LBUTTONDOWN: {

if (index == 0) {

// Get first point

points[index].x = LOWORD(lParam);

points[index].y = HIWORD(lParam);

index++;

} else {

// Get second point

points[index].x = LOWORD(lParam);

points[index].y = HIWORD(lParam);

HPEN hpen = CreatePen(PS_SOLID, 4, RGB(255, 0, 0));

hdc = GetDC(hwnd);

SelectObject(hdc, hpen);

// Draw line

MoveToEx(hdc, points[0].x, points[0].y, NULL);

LineTo(hdc, points[1].x, points[1].y);

// Save DC

BitBlt(memDC, 0, 0, 500, 500, hdc, 0, 0, SRCCOPY);

ReleaseDC(hwnd, hdc);

DeleteObject(hpen);

index = 0;

}

break;

}

case WM_MOUSEMOVE: {

if (index == 1) {

HPEN hpen = CreatePen(PS_SOLID, 4, RGB(255, 0, 0));

hdc = GetDC(hwnd);

SelectObject(hdc, hpen);

BitBlt(hdc, 0, 0, 500, 500, memDC, 0, 0, SRCCOPY);

MoveToEx(hdc, points[0].x, points[0].y, NULL);

LineTo(hdc, LOWORD(lParam), HIWORD(lParam));

ReleaseDC(hwnd, hdc);

DeleteObject(hpen);

}

break;

}

case WM_DESTROY:

PostQuitMessage(0);

break;

}

return DefWindowProc(hwnd, uMsg, wParam, lParam);

}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpCmdLine, int nCmdShow) {

MSG msg;

HWND hwnd;

HDC hdc;

if (!loadResources(hInstance))

return GetLastError();

if (!createWindow(hInstance, nCmdShow, hwnd))

return GetLastError();

hdc = GetDC(hwnd);

memDC = CreateCompatibleDC(hdc);

memBM = CreateCompatibleBitmap(hdc, 500, 500);

SelectObject(memDC, memBM);

ReleaseDC(hwnd, hdc);

while (GetMessage(&msg, NULL, NULL, NULL)) {

TranslateMessage(&msg);

DispatchMessage(&msg);

}

DeleteObject(memBM);

DeleteDC(memDC);

return (int)msg.wParam;

}

Daniel Yerushalmi

unread,
Jan 6, 2003, 10:38:04 AM1/6/03
to
I susspect that before drawing the line you need to inittalize the dc to
some color (by doing FillRect on it)

"Timothy V" <tri...@msn.com> wrote in message
news:uUhvtXZtCHA.2648@TK2MSFTNGP09...

Jeff Partch

unread,
Jan 6, 2003, 12:30:36 PM1/6/03
to
"Timothy V" <tri...@msn.com> wrote in message
news:uUhvtXZtCHA.2648@TK2MSFTNGP09...

> Yup, that was it. Thanks. I do have another question tho...
Sometimes
> when I draw a line in the window, the rectangle that i specified in
the
> BitBlt() function is filled with black. Do you know why this is?
I'll
> include my WndProc function and WinMain function below. (this problem
> exists in the WM_MOUSEMOVE procedure.

In addition to the suggestion to initialize your memDC, a few other
things you should consider are: 1) Use BeginPaint/EndPaint in your
WM_PAINT handler, 2) Create your static POINT point[1] as static POINT
point[2], 3) Save the old HPEN when you SelectObject your red pen, and
SelectObject it back in before you do your DeleteObject. 4) I don't
understand how your createWindow function is supposed to work -- it
looks like it should take an HWND*, but you pass it an HWND instead.

0 new messages