?
Solved

Giving color for a rectangle drawn on memoryDC

Posted on 2003-03-13
4
Medium Priority
?
469 Views
Last Modified: 2013-11-20
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
Comment
Question by:tgersur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8131626
dcMem.SelectObject(oldbrush);
dcMem.SelectObject(oldpen);
dcMem.SelectObject(oldBitmap);

remove these 3 lines does that help?
0
 

Author Comment

by:tgersur
ID: 8133679
hi william,
  i removed last 3 lines. Still the problem is not solved.
0
 
LVL 1

Accepted Solution

by:
keitha1 earned 60 total points
ID: 8134669
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
 

Author Comment

by:tgersur
ID: 8141578
Thanx. I will try it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question