Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Giving color for a rectangle drawn on memoryDC

hi,
   i have a rectangle wich is drawn on memoryDC using BitMap. Eventhough i have assigned some color to TBrush, TPenm iam getting a rectangle with black background and white dots over that. How can i get a rectangle with user defined color using bitmap and memorydc?

void OnPaint(){
           
       CPaintDC dc(this);
       CDC dcMem;
       CBitmap bmMem;
       CBitmap* oldBitmap;
       CBrush newbrush;
       CBrush* oldbrush;
       CPen newpen;
       CPen* oldpen;
       CRect rcClient;
       GetClientRect(rcClient);
       dcMem.CreateCompatibleDC(&dcMem);
       bmMem.CreateCompatibleBitmap(&dcMem, rcClient.Width(), rcClient.Height());
       oldBitmap = dcMem.SelectObject(&bmMem);
       dcMem.PatBlt(0, 0, rcClient.Width(), rcClient.Height(), WHITENESS);

       col = RGB(0,0,255);
       newpen.CreatePen (PS_SOLID,1,col);
       oldpen=dcMem.SelectObject (&newpen);
       newbrush.CreateSolidBrush (col);
       oldbrush = dcMem.SelectObject (&newbrush);
       dcMem.Rectangle (r1);

       dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &dcMem, 0, 0, SRCCOPY);

       dcMem.SelectObject(oldbrush);
       dcMem.SelectObject(oldpen);
       dcMem.SelectObject(oldBitmap);
    }

Thanx
0
tgersur
Asked:
tgersur
  • 2
1 Solution
 
williamcampbellCommented:
dcMem.SelectObject(oldbrush);
dcMem.SelectObject(oldpen);
dcMem.SelectObject(oldBitmap);

remove these 3 lines does that help?
0
 
tgersurAuthor Commented:
hi william,
  i removed last 3 lines. Still the problem is not solved.
0
 
keitha1Commented:
You are creating a monocrome DC. Use a NULL argument to CreateCompatibleDC to create a DC that is compatible with your screen.

dcMem.CreateCompatibleDC(NULL);

     
0
 
tgersurAuthor Commented:
Thanx. I will try it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now