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 6027763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:38:24+00:00 2026-05-23T04:38:24+00:00

I am just starting with MFC so please be tolerant ;). I have wrote

  • 0

I am just starting with MFC so please be tolerant ;).
I have wrote (it was mostly generated to be honest) a simple application which should do the Paint chores: drawing lines, rectangulars, ellipses, changing a color of object to be drawn etc.

I need to save what has been drawn on the screen into a bmp file. Any ideas how can I achieve this ?

I do not know if that’s relevant but I am drawing objects on the screen without the use of any CBitmaps or things like that. Here is a part of code responsible for drawing :

CPaintDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
Anchor.x=point.x;
Anchor.y=point.y;
OldPoint.x=Anchor.x;
OldPoint.y=Anchor.y;
if(pDoc->shapeCount>=MAX_SHAPES) return;
pDoc->shapeCount++;

if(bFreehand)
    {
    pDoc->m_shape[pDoc->shapeCount-1] = new Shape;
    pDoc->m_shape[pDoc->shapeCount-1]->shape = ePoint;
    }
if(bLine)
    {
    pDoc->m_shape[pDoc->shapeCount-1] = new CLine;
    pDoc->m_shape[pDoc->shapeCount-1]->shape = eLine;
    }
if(bRectangle)
    {
    pDoc->m_shape[pDoc->shapeCount-1] = new CRectangle;
    pDoc->m_shape[pDoc->shapeCount-1]->shape = eRectangle;
    }
if(bEllipse)
    {
    pDoc->m_shape[pDoc->shapeCount-1] = new CEllipse;
    pDoc->m_shape[pDoc->shapeCount-1]->shape=eEllipse;
    }
pDoc->m_shape[pDoc->shapeCount-1]->x=point.x;
pDoc->m_shape[pDoc->shapeCount-1]->y=point.y;
pDoc->m_shape[pDoc->shapeCount-1]->x2=point.x;
pDoc->m_shape[pDoc->shapeCount-1]->y2=point.y;
pDoc->m_shape[pDoc->shapeCount-1]->Pen=CurrentPen;
pDoc->m_shape[pDoc->shapeCount-1]->Brush=CurrentBrush;
bButtonDown=true;
SetCapture();

I have found this way to do it but I don’t know how to obtain screen width and height to fill it in the CreateBitmap parameter’s list

        CBitmap *bitmap;
    bitmap.CreateBitmap(desktopW, desktopH, 1, 32, rgbData);
    CImage image;
    image.Attach(bitmap);
    image.Save(_T("C:\\test.bmp"), Gdiplus::ImageFormatBMP);
  • 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-05-23T04:38:25+00:00Added an answer on May 23, 2026 at 4:38 am

    The CreateBitmap call only requires the desktop width and height if the image you wish to save is actually the entire size of the screen. If that’s indeed your intent, you can use CWnd::GetDesktopWindow() to get a CWnd object that you can query for its width and height:

    http://msdn.microsoft.com/en-us/library/bkxb36k8(v=VS.80).aspx

    That gets dodgy in general…if for no other reason than multi-monitor scenarios…so I’d recommend against it unless you really feel like writing a screen capture app.

    What you probably want to do isn’t to take a full screen shot, but just save the contents of your program’s window. Typically you’d do this by breaking out the drawing logic of your program so that in the paint method you call a helper function that is written to take a CDC device context. Then you can either call that function on the window-based DC you get in the paint call or on a DC you create from the bitmap to do your save. Note that you can use a CBitmap in CDC::SelectObject:

    http://msdn.microsoft.com/en-us/library/432f18e2(v=VS.71).aspx

    (Though let me pitch you on not using MFC. Try Qt instead. Way better.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just starting out, this should be a simple one but I haven't been able
Just starting using the Firebug console. I have a test script which I'll post
Just starting out in asp.net. Have just created a login.aspx page in my site
Just starting out with subversion, have set up repos for 3 current projects and
Just starting out with an iPhone application using xcode 4.2. I understand that it
Just starting out with C#, so this may be overly simple that I keep
Just starting out with my first commercial app for the iStore but dont have
Just starting my way with Roboguice for android. Tried implementing this simple context injection
Just starting to use Ruby on Rails to see what its like. I have
Just starting out on android developing. To start off, I'm building an app which

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.