home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / repease / rep_blk.c < prev    next >
C/C++ Source or Header  |  1995-08-14  |  6KB  |  192 lines

  1. /*==============================================================================
  2.    REP_BLK.C
  3.    Report Ease clipboard functions.
  4.  
  5.    ReportEase Plus
  6.    Sub Systems, Inc.
  7.    ReportEase Plus, Copyright (c) 1993, Sub Systems, Inc. All Rights Reserved.
  8.    159 Main Street, #8C, Stoneham,  MA 02180 
  9.    (617) 438-8901.
  10.  
  11.    Software License Agreement  (1993)              
  12.    ----------------------------------
  13.    This license agreement allows the purchaser the right to modify the 
  14.    source code to incorporate in their application.
  15.    The target application must not be distributed as a standalone report writer
  16.    or a mail merge product.
  17.    Sub Systems, Inc. reserves the right to prosecute anybody found to be 
  18.    making illegal copies of the executable software or compiling the source
  19.    code for the purpose of selling there after.
  20.  
  21. ===============================================================================*/
  22. #include "windows.h"
  23.  
  24. #if defined (_WIN32)
  25.    #if !defined(WIN32)
  26.      #define WIN32
  27.    #endif
  28. #endif
  29. #if !defined(WIN32) 
  30.   #include "print.h"
  31. #endif
  32.  
  33. #include "stdio.h"
  34. #include "stdlib.h"
  35. #include "ctype.h"
  36. #include "fcntl.h"
  37. #include "io.h"
  38. #include "sys\types.h"
  39. #include "sys\stat.h"
  40. #include "string.h"
  41. #include "setjmp.h"
  42.  
  43. #include "rep.h"
  44.  
  45. #define  PREFIX extern
  46. #include "rep1.h"
  47.  
  48. /******************************************************************************
  49.     PictureFromClipboard:
  50.     Routine to copy a picture in the BITMAP format the current cursor
  51.     location.
  52. *******************************************************************************/
  53. PictureFromClipboard()
  54. {
  55.     HANDLE hClip;
  56.     int    pict;
  57.  
  58.     //**** open and access the clipboard ***********************************
  59.     
  60.     if (!OpenClipboard(hFrWnd)) {        // open buffer 
  61.         MessageBox(hFrWnd,"Clipboard in use by another application","Not Available",MB_OK);
  62.         return FALSE;
  63.     }
  64.  
  65.     if (NULL==(hClip=GetClipboardData(CF_BITMAP))) {
  66.         MessageBox(hFrWnd,"Clipboard does not contain a Picture Bitmap Data","Not Available",MB_OK);
  67.         CloseClipboard();
  68.         return FALSE;
  69.     }
  70.  
  71.     if ((pict=FrCreateDIB(hClip))==-1) { // create a device independent bitmap 
  72.         CloseClipboard();
  73.         return FALSE;
  74.     }
  75.  
  76.     if (!FrXlateDIB(hFrDC,pict)) {       // translate DIB to device bitmap 
  77.         CloseClipboard();
  78.         return FALSE;
  79.     }
  80.  
  81.     // END COPY
  82.     CloseClipboard();
  83.  
  84.     NewPict=pict;                        // update the global variable
  85.     return TRUE;
  86. }
  87.  
  88. /******************************************************************************
  89.     PictureFromFile:
  90.     This routine asks for a bitmap file name.  It load the bitmap
  91.     in the font table and saves the font table index in a global variable.
  92. *******************************************************************************/
  93. PictureFromFile()
  94. {
  95.     LPSTR  pImage;
  96.     LPBITMAPINFOHEADER pInfo;
  97.     int    pict,height,width;
  98.     char   name[128];
  99.     WORD   BmSign;
  100.     HFILE  iFile=HFILE_ERROR;
  101.     BITMAPFILEHEADER hdr;
  102.     DWORD ImageSize,InfoSize,FileSize;
  103.  
  104.     if ((pict=FindOpenSlot())==-1) return FALSE;  // ran out of picture table 
  105.  
  106.     // get the file name from the user and open the bitmap file
  107.     name[0]=0;
  108.     while (iFile==HFILE_ERROR) {
  109.         if (!GetFileName(TRUE,name,"Bitmap Files(*.BMP)|*.BMP|")) return FALSE;
  110.         
  111.         FileSize=GetFileLength(name);             // get the file length
  112.  
  113.         if (HFILE_ERROR==(iFile=_lopen(name,OF_READ))) {
  114.            MessageBox(hFrWnd,"Can not Open the Bitmap File",NULL,MB_OK);
  115.            continue;
  116.         }
  117.         if (_lread(iFile,&hdr,sizeof(BITMAPFILEHEADER))!=sizeof(BITMAPFILEHEADER) ) {
  118.            MessageBox(hFrWnd,"Can not Read the Bitmap File",NULL,MB_OK);
  119.            _lclose(iFile);
  120.            iFile=HFILE_ERROR;
  121.            continue;
  122.         }
  123.         BmSign=(((WORD)'M')<<8)|'B';    // signature of the bitmap file 
  124.         if (hdr.bfType!=BmSign) {
  125.            MessageBox(hFrWnd,"Invalid Bitmap File",NULL,MB_OK);
  126.            _lclose(iFile);
  127.            iFile=HFILE_ERROR;
  128.            continue;
  129.         }
  130.     }
  131.  
  132.     //************ calculate image and info structure sizes **
  133.     InfoSize=hdr.bfOffBits-sizeof(BITMAPFILEHEADER);
  134.     ImageSize=FileSize-sizeof(BITMAPFILEHEADER)-InfoSize;
  135.  
  136.     //************ Allocate Space for image and info *********
  137.     if  (NULL==(FrFont[pict].hImage=GlobalAlloc(GMEM_MOVEABLE,ImageSize))
  138.       || NULL==(FrFont[pict].hInfo=GlobalAlloc(GMEM_MOVEABLE,InfoSize))
  139.       || NULL==(pImage=GlobalLock(FrFont[pict].hImage)) 
  140.       || NULL==(pInfo=(LPBITMAPINFOHEADER)GlobalLock(FrFont[pict].hInfo)) ) {
  141.           MessageBox(hFrWnd,"Ran Out of Memory",NULL,MB_OK);
  142.           InitFrObject(pict);
  143.           _lclose(iFile);
  144.           return FALSE;
  145.     }
  146.     
  147.     //********** Read image and info data *******************
  148.     if (!FrFarRead(iFile,InfoSize,(LPSTR)pInfo)
  149.      || !FrFarRead(iFile,ImageSize,pImage) ) {
  150.         MessageBox(hFrWnd,"Ran Out of Memory",NULL,MB_OK);
  151.         InitFrObject(pict);
  152.         _lclose(iFile);
  153.         return FALSE;
  154.     }
  155.     
  156.     if (pInfo->biSize!=sizeof(BITMAPINFOHEADER)) {
  157.        MessageBox(hFrWnd,"Unrecognized Bitmap File Format!",NULL,MB_OK);
  158.         InitFrObject(pict);
  159.         _lclose(iFile);
  160.         return FALSE;
  161.     }
  162.  
  163.     //******** initialize other FrFont variables **********
  164.     height=(int)(pInfo->biHeight);                       // dimensions in pixel units
  165.     width=(int)(pInfo->biWidth);
  166.     
  167.     FrFont[pict].InUse=TRUE;
  168.     FrFont[pict].PictHeight=(UINT)((DWORD)(height)*72L/(DWORD)ResY); // dimension in point sizes 
  169.     FrFont[pict].PictWidth=(UINT)((DWORD)(width)*72L/(DWORD)ResX);
  170.     FrFont[pict].ImageSize=ImageSize;
  171.     FrFont[pict].InfoSize=InfoSize;
  172.     FrFont[pict].IsPict=TRUE;
  173.  
  174.     GlobalUnlock(FrFont[pict].hImage);
  175.     GlobalUnlock(FrFont[pict].hInfo);
  176.  
  177.     //***************** translate into device bitmap *********************
  178.     if (!FrXlateDIB(hFrDC,pict)) {     // translate DIB to device bitmap 
  179.         InitFrObject(pict);
  180.         _lclose(iFile);
  181.         return FALSE;
  182.     }
  183.  
  184.     // end of routine 
  185.     _lclose(iFile);
  186.  
  187.     NewPict=pict;                         // update the global variable for output
  188.     
  189.     return TRUE;
  190. }
  191.  
  192.