|
Dernière réponse | |
---|---|
Sujet : [C++/Visual C++] Copier contenu Clipboard dans un fichier | |
Carbon_14 | La fin, squizzée par le serveur (pas plus de trois envois en moins de 10 minutes, je voulais éviter de faire déborder la page en fragmentant :D )
Sauve le fichier au format BMP non RLE encodé sous le nom "FileName" extern HDIB BitmapToDIB(HBITMAP); extern int WriteBitmapFile(const char *, const HANDLE); HANDLE handle; HCURSOR oldCursor; // Demande nom de fichier ... // oldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); handle = BitmapToDIB(BitmapHandle); if (handle != (HANDLE)NULL) { WriteBitmapFile(FileName, handle); GlobalFree(handle); } SetCursor(oldCursor); -------------------------------------------------- -------- WriteBitmapFile() #include <windows.h> #include <malloc.h> #include <dos.h> #include "bitmaps.h" extern LPSTR DIBitmapBits(BITMAPINFO FAR *); /* int WriteBitmapFile( ** const char *filename, name of file to load ** const HANDLE hbm); handle to packed DIB ** ** This function will write the passed packed Device Independant Bitmap ** to the specified file. */ int WriteBitmapFile(const char *filename, const HANDLE hbm) { int file; int rc = -1; int block; long size; char HUGE *ptr; BITMAPFILEHEADER bfHdr; LPBITMAPINFO bmi; OFSTRUCT ofs; /* 1. Open output file */ file = OpenFile((LPSTR)filename, (LPOFSTRUCT)&ofs, OF_CREATE | OF_WRITE); if (file != -1) { /* 2. Lock memory resource */ bmi = (LPBITMAPINFO)GlobalLock(hbm); if (bmi != NULL) { /* 3. Create BITMAPFILEHEADER and write to file */ bfHdr.bfType = ('B' + ('M' << 8)); bfHdr.bfSize = sizeof(BITMAPFILEHEADER) + GlobalSize(hbm); bfHdr.bfReserved1 = 0; bfHdr.bfReserved2 = 0; bfHdr.bfOffBits = sizeof(BITMAPFILEHEADER) + (DWORD)(DIBitmapBits(bmi) - (LPSTR)bmi); if (_lwrite(file, (LPSTR)&bfHdr, sizeof(bfHdr)) == sizeof(bfHdr)) { /* 4. Write out DIB header and packed bits to file */ size = GlobalSize(hbm); ptr = (char HUGE *)bmi; block = 16 * 1024; /* size of chunks to write out */ while (size > 0) { if (size < (long)block) block = (int)size; if (_lwrite(file, (LPSTR)ptr, block) != block) { ErrorBox("WriteBitmapFiile(): Error writing DIB" ); break; } size -= (long)block; ptr += block; } if (size == 0) rc = 0; } else ErrorBox("WriteBitmapFile(): Error writing BITMAPFILEHEADER" ); GlobalUnlock(hbm); } else ErrorBox("WriteBitmapFile(): Error locking bitmap into memory" ); _lclose(file); } else ErrorBox("WriteBitmapFile(): Error opening output file" ); if (rc != 0) unlink(filename); return rc; } |
Vue Rapide de la discussion |
---|