Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:12:48+00:00 2026-06-08T17:12:48+00:00

As I am new to Visual C++, this might be a very basic question

  • 0

As I am new to Visual C++, this might be a very basic question related to selecting a GDI object.

The following code snippet draws a light grey circle with no border.

cPen pen(PS_NULL, 0, (RGB(0,0,0)));
dc.SelectObject(& pen);
CBrush brush (RGB (192,192,192));
dc.SelectObject (&brush);
dc.Ellipse(0,0, 100,100);

All I understand from the code snippet is first an Object of Pen is created, and its a NULL Pen which would make the border disappear, the brush then creates a Circle of grey color, but how does dc use pen if it is already using brush? this is a bit confusing.

How does using dc.SelectObject() twice help? If the solid brush object is used to create a circle with grey color, how does creating pen object help, if it is anyway destroyed as brush object is created? how exactly does this thing work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:12:49+00:00Added an answer on June 8, 2026 at 5:12 pm

    SelectObject function is used to select five different types of objects into DC

    1. Pen
    2. Brush
    3. Font
    4. Bitmap and
    5. Region

    The documentation states that
    The newly selected object replaces the previous object of the same type. So it means you can select pen and brush without any problem but you cant select pen twice.

    And moreover to avoid resource leak you need to select the old pen/brush whatever you have selected earlier

    CPen pen(PS_NULL, 0, (RGB(0,0,0)));
    CPen *oldPen = dc.SelectObject(& pen);
    CBrush brush (RGB (192,192,192));
    CBrush *oldBrush = dc.SelectObject (&brush);
    dc.Ellipse(0,0, 100,100);
    
    dc.SelectObject(oldPen);
    dc.SelectObject(oldBrush);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now this might be a dumb question, but I'm still new to using Visual
I'm pretty new to Visual Studio so this might be an easy issue :)
This is a very basic question. I feel kind of silly asking about it
I realize that this might be a duplicate question but this question is very
I'm completely new to Eclipse/Java/Android programming, so this might sound like a dumb question,
I'm new to visual studio, so perhaps this is something easy... but I've had
I've found a new twist on the Visual to RenderTargetBitmap question! I'm rendering previews
In visual studio 2008, when I use something akin to the following snippet: Dim
I am following this tutorial on using the client-object model. And just starting from
This works, and I can't imagine how it might cause problems, but visual studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.