Writing Clipboard To File

This is a discussion on Writing Clipboard To File within the C++ Programming forums, part of the General Programming Boards category; Hi all, ran into a little trouble. I'm trying to write a bitmap from the clipboard to a file, but ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    13

    Writing Clipboard To File

    Hi all, ran into a little trouble.

    I'm trying to write a bitmap from the clipboard to a file, but I can't seem to be able to. I've tried a few different methods and doing some google searches has led me this far, but I can't seem to be able to get the bitmap data from the clipboard...
    Code:
    FILE *pFile = fopen("test.bmp", "wb");
            BITMAPFILEHEADER bmfh;
            int nBitsOffset = sizeof(BITMAPFILEHEADER) + BMIH.biSize; 
            LONG lImageSize = BMIH.biSizeImage;
            LONG lFileSize = nBitsOffset + lImageSize;
            bmfh.bfType = 'B'+('M'<<8);
            bmfh.bfOffBits = nBitsOffset;
            bmfh.bfSize = lFileSize;
            bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
            UINT nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile); //Write the bitmap file header
            UINT nWrittenInfoHeaderSize = fwrite(&BMIH, 1, sizeof(BITMAPINFOHEADER), pFile);  //And then the bitmap info header
    UINT nWrittenDIBDataSize = fwrite(bitmapData, 1, lImageSize, pFile); //Finally, write the image data itself
    Any help?? Thanks

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    I don't think creating a bmp-file is so straight-forward...
    Maybe you should start by reading some info on the bmp-file format? And learn how to create it properly based on the data stored in the BITMAPFILEHEADER structure?

    Googling for 2 minints I have found for example this link: http://atlc.sourceforge.net/bmp.html
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21