Solved

Save and retrieve a graph

Posted on 2000-02-21
3
201 Views
Last Modified: 2010-04-10
How can  I save a graph? The graph is plotted using pDC->MoveTo and LineTo. It has text also which is written using pDC->TextOut command. I'm using AppWIzard for this program. Please guide me through each single step. Thanks.
0
Comment
Question by:kitlee
[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
3 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2542744
You could save the drawing operations using a windows meta file.  

I'm not familiar with the MFC way of dealing with metafiles, but it appears to be done through CMetaFileDC.
0
 
LVL 1

Expert Comment

by:nutsnuts
ID: 2542817
Which graph format do you want to save it as?
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 100 total points
ID: 2544505
If you want to save your graph as a bitmap picture, then create a DIB bitmap (I like 24Bit DIBs as they are easier), select it into a CDC devicec context and then call your OnDraw code to draw onto the bitmap (just make sure your bitmap is big enough and/or that your drawing code is told how big to draw the graph).  Then, when finished, write the bitmap to a file.  This is not directly suported by windows, but there is sample code on the MSKB for how to write out DIB files.

Otherwise, just write out your data by serialising your document (which should be where you keep your data).  Then you can view the data by loading a document into your app.  Even nicer, when you build your app, make it an OLE server.  Then you can do things like embed your graphs in Word documents etc.

PS: For 24Bit DIB bitmaps, I have a class derived from CBitmap.  It has a member function to write the bitmap to a CFile.  This is the code I use...
      // setup file header
      BITMAPFILEHEADER hdr;
      hdr.bfType = 0x4d42;      // 0x42 = "B", 0x4d = "M"
      hdr.bfReserved1 = 0;
      hdr.bfReserved2 = 0;

      BITMAPINFOHEADER bitmapinfoheader;
      GetBITMAPINFOHEADER(bitmapinfoheader);

      // Compute the offset to the array of color indices.
      hdr.bfOffBits = (DWORD) (
            sizeof(BITMAPFILEHEADER) +
            bitmapinfoheader.biSize +
            bitmapinfoheader.biClrUsed * sizeof (RGBQUAD)
      );

      // Compute the size of the entire file.
      hdr.bfSize = hdr.bfOffBits + bitmapinfoheader.biSizeImage;

      bool ok = false;
      TRY {
            // Copy the BITMAPFILEHEADER into the .BMP file.
            file.WriteHuge(&hdr,sizeof(hdr));
            // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
            file.WriteHuge(&bitmapinfoheader,sizeof(bitmapinfoheader) + bitmapinfoheader.biClrUsed * sizeof (RGBQUAD));
            // Copy the array of color indices into the .BMP file.
            file.WriteHuge(m_pBits,bitmapinfoheader.biSizeImage);

            ok = true;
      } CATCH_ALL (e) {
      } END_CATCH_ALL
      return ok;

If you want a graphic formats other than BMP files, then you'll probably need a third party graphics library (or track down some source code).

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

617 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