Hi,
I have this code for drawing my custom control. I am going to do my drawing into an off-screen DC and then blit it to the screen DC. However, it won't work. If i pass the screen DC to the Rectangle() function it will draw a rectangle, but when passing the memory DC it will not. I have done this many times before, but I can't get it to work in this particular case. Does it have anything to do with my OO approach?
Edit: What I mean by "won't work" is that seemingly nothing gets drawn to the memory DC. No function calls fail either. I have checked return values and GetLastError(). I can for instance use the BLACKNESS raster operation on the BitBlt function and the control gets painted black.
Code:
LRESULT Button::OnPaint(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
m_hdc = BeginPaint(hwnd,&ps);
OffscreenBitmap(&ps);
EndPaint(hwnd,&ps);
return FALSE;
}
void Button::OffscreenBitmap(PAINTSTRUCT *ps)
{
HDC hdcMem = CreateCompatibleDC(ps->hdc);
HBITMAP hbm = CreateCompatibleBitmap(ps->hdc,m_cx,m_cy);
HBITMAP hbmOld;
hbmOld = (HBITMAP)SelectObject(hdcMem,hbm);
Rectangle(hdcMem,0,0,m_cx,m_cy);
//DrawGradient(hdcMem);
//LightenEdges(hdcMem);
BitBlt(m_hdc,
0,
0,
m_cx,
m_cy,
hdcMem,
m_cx,
m_cy,
SRCCOPY
);
SelectObject(hdcMem,hbmOld);
DeleteObject(hbm);
DeleteDC(hdcMem);
}