Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get a transparent rectangle in a view

Posted on 2008-06-25
4
Medium Priority
?
1,104 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
[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 31

Accepted Solution

by:
Zoppo earned 500 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 45

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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