Saving 2 documents in 1 file

Posted on 1999-07-22
Medium Priority
Last Modified: 2013-11-20
How can I save to different doctuments in one file. To be more spicific, I want to save a bitmap file in a file followed by some other data of different kind. Now, the saving is not the problem, since I can copy the bitmap to a new file and append my data to the end of the new file. The problem is when I read the file. Since the end of bitmap is not indicated by the end of file flag (because I added my data,) how could I determine the end of the bitmap. And how could this "mixed" file work with MFC's "open document" functions, such as, for example, LoadBitmap()?
Thank you.
Question by:Zainal062797

Expert Comment

ID: 1311000
I would try to come up with some separator (a character sequence you pick), write the bitmap, the separator, and then the file.

You would definitely have to override the open and close documents to get this to work.

Another idea?  Store the bitmap as a link (a path to the bitmap) in the file.  Retrieve that link and then open up the rest of the file.

I'll stay tuned for other ideas

Expert Comment

ID: 1311001
you could try CAB files, they will also compress the contecnt and encrypt them

Expert Comment

ID: 1311002
i think add a tag to every block you write to file is a good idea.

   int type;
   int length;
in write precedure , write the tag first and then write the data block.
when you read , you can read the tag first and then judge what type the next data is.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Expert Comment

ID: 1311003
try to study the struct bitmapheaderinfo. you can find the width, height, pixels(how many bits per pixel). then you can calculate the length of the bitmap file(width*height*pixels + length of header). then you can read the data by your own function.

Author Comment

ID: 1311004
I was thinking of doing that myself, but I was hopping I could avoid this tedious manual method.

Accepted Solution

speedup earned 400 total points
ID: 1311005
but you have to do that.
or try this:
create a memfile of the bitmap section of your mixed file.
and you can load your bitmap as if it's a pure bitmap file.

Author Comment

ID: 1311006
How can I make a memefiel? And how about writing to it? Can you elaborate a little bit More please?

Thank you

Expert Comment

ID: 1311007
sample codes go here:
      if(hfile==INVALID_HANDLE_VALUE) return NULL;
      // Create a file mapping
      HANDLE hmapping;
      hmapping=CreateFileMapping(hfile, NULL, PAGE_READONLY, 0, 0, NULL);

      // Close file handle since we don't need it anymore

      // Map file mapping object to memory image
      void *baseaddr;
      DWORD length = width*height*pixels;//NOTE:the size of the bmp file.
      if(baseaddr==NULL) {
            return NULL;
      const void *lpvBits = (const void *)baseaddr;
      HBITMAP hBitmap = CreateBitmap( width, height, cPlanes, cBitsPerPel, lpvBits);
      // Close file mapping


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…

607 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