Thread: Writing Clipboard To File

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

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, 10:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09: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, 10:46 AM