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: 1106
  • Last Modified:

How to get a transparent rectangle in a view

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
IssacJones
Asked:
IssacJones
  • 2
1 Solution
 
ZoppoCommented:
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
 
IssacJonesAuthor Commented:
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
 
AndyAinscowCommented:
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
 
IssacJonesAuthor Commented:
Hiya Zoppo

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

now that I have it works ok.

John
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