Solved

How to get a transparent rectangle in a view

Posted on 2008-06-25
4
1,078 Views
Last Modified: 2013-11-20
Hiya

I have an MFC SDI application. In the View I want to draw a rectangle with a black border. However, I want the inside of the rectangle to be empty i.e. transparent. That is, I want to be able to put the rectangle over other shapes in the View and they will appear through the rectangle.

I have tried it so far using

pDC->SetBkMode(TRANSPARENT);
pDC->Rectangle(100,-100,400,-400);

and nothing covered in the rectangle comes through.

John
0
Comment
Question by:IssacJones
  • 2
4 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 125 total points
ID: 21867276
Hi IssacJones,

'Rectangle' uses the current selected brush to fill the rectangle. To draw a transparent one do it like this:

> CBrush* pOldBrush = (CBrush*)pDC->SelectStockObject( NULL_BRUSH );
> pDC->Rectangle( 100,-100,400,-400 );
> pDC->SelectObject( pOldBrush );

Hope that helps,

ZOPPO
0
 

Author Comment

by:IssacJones
ID: 21867596
Hi Zoppo

Nope, that doesn't work. The rectangle is complely black.

By the way, the rectangle covers a bitmap. Would that make a difference?

John
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 21868129
You could use a combination of MoveTo (moves cursor to a point without drawing a line) and DrawTo (draws line from where the cursor was up to  the new point).

The advantage of this technique is that it copes with any shape not just rectangles.
0
 

Author Comment

by:IssacJones
ID: 21869030
Hiya Zoppo

Sorry you were right, I didn't use SelectStockObject.

now that I have it works ok.

John
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 79
bigDiff challenge 17 135
post4 challenge 28 113
canBalance challenge 34 105
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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