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
Solved

How to get a transparent rectangle in a view

Posted on 2008-06-25
4
1,073 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 142
countEvens challenge 2 111
only14 challenge 19 81
child constructor and parent constructor, overriding and overloading 6 88
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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