home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / DESKEXT.ZIP / PATTERN.C < prev    next >
C/C++ Source or Header  |  1990-05-12  |  3KB  |  110 lines

  1. /***************************************************************************\
  2. * PATTERN.C - An example Desktop Picture Reader extension by John Ridges
  3. \***************************************************************************/
  4.  
  5. #define INCL_BITMAPFILEFORMAT
  6. #define INCL_DOSFILEMGR
  7. #define INCL_GPIBITMAPS
  8. #define INCL_WINSYS
  9.  
  10. #include <os2.h>
  11. #include <string.h>
  12.  
  13. char far * far pascal _loadds deskpicextension(HMODULE);
  14. ULONG far pascal _loadds deskpicgetsize(HFILE);
  15. BOOL far pascal _loadds deskpicread(HFILE, SEL, BITMAPINFO far *);
  16. void far pascal _loadds deskpicinfo(char far *, HWND);
  17.  
  18. static USHORT near cx;   /* Width of screen in pels */
  19. static USHORT near cy;   /* Height of screen in pels */
  20. static BITMAPFILEHEADER near filehead;   /* The icon's header */
  21.  
  22. char far * far pascal _loadds deskpicextension(module)
  23. HMODULE module;
  24. {
  25.     module;   /* Reference the argument so we don't get compiler warnings */
  26.     return ".ICO";   /* Tell DESKPIC to look for .ICO extensions */
  27. }
  28.  
  29. ULONG far pascal _loadds deskpicgetsize(hf)
  30. HFILE hf;
  31. {
  32.     USHORT n;
  33.     
  34.     /* Read the icon's header */
  35.     if (DosRead(hf,&filehead,sizeof(BITMAPFILEHEADER),&n) ||
  36.         n != sizeof(BITMAPFILEHEADER)) return 0L;
  37.  
  38.     /* Check that the icon is big enough and has only one color plane */
  39.     if (filehead.bmp.cx < 16 || filehead.bmp.cy < 16 ||
  40.         filehead.bmp.cPlanes != 1 || filehead.bmp.cBitCount > 8) return 0L;
  41.  
  42.     /* Get the screen size */
  43.     cx = (USHORT)WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
  44.     cy = (USHORT)WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
  45.  
  46.     /* Return the amount of memory needed for the whole screen */
  47.     return (ULONG)cy*((cx*filehead.bmp.cBitCount+7>>3)+3&0xfffc);
  48. }
  49.  
  50. BOOL far pascal _loadds deskpicread(hf,sel,cbmi)
  51. HFILE hf;
  52. SEL sel;
  53. BITMAPINFO far *cbmi;
  54. {
  55.     USHORT i,n,y;
  56.     ULONG row;
  57.     BYTE huge *abbitmap;
  58.  
  59.     /* Specify a bitmap the size of the screen */
  60.     cbmi->cbFix = 12;
  61.     cbmi->cx = cx;
  62.     cbmi->cy = cy;
  63.     cbmi->cPlanes = 1;
  64.     cbmi->cBitCount = filehead.bmp.cBitCount;
  65.  
  66.     /* Read in the icon's color table */
  67.     for (i = 0; i < (USHORT)(1<<filehead.bmp.cBitCount); i++)
  68.         if (DosRead(hf,&cbmi->argbColor[i],sizeof(RGB),&n) || n != sizeof(RGB))
  69.             return TRUE;
  70.  
  71.     /* Get a pointer to the bitmap data */
  72.     abbitmap = MAKEP(sel,0);
  73.  
  74.     /* Duplicate the first 16 rows of icon data over every row of the bitmap */
  75.     for (y = 0; y < cy; y++) {
  76.  
  77.         /* Locate the row in the icon data */
  78.         DosChgFilePtr(hf,(LONG)filehead.offBits+
  79.             (LONG)(y%16)*((filehead.bmp.cx*filehead.bmp.cBitCount+7>>3)+3&0xfffc),
  80.             FILE_BEGIN,&row);
  81.  
  82.         /* Locate the row in the bitmap */
  83.         row = (ULONG)y*((cx*filehead.bmp.cBitCount+7>>3)+3&0xfffc);
  84.  
  85.         /* Read the row of icon data */
  86.         for (n = 0; n < filehead.bmp.cBitCount<<1; n++)
  87.             if (DosRead(hf,abbitmap+row+n,1,&i) || i != 1) return TRUE;
  88.  
  89.         /* Duplicate the data over the rest of the bitmap row */
  90.         for (i = 0; i < (cx*filehead.bmp.cBitCount+7>>3)-n; i++)
  91.             abbitmap[row+n+i] = abbitmap[row+i];
  92.     }
  93.  
  94.     /* Return success */
  95.     return FALSE;
  96. }
  97.  
  98. void far pascal _loadds deskpicinfo(filepath,hwnd)
  99. char far *filepath;
  100. HWND hwnd;
  101. {
  102.     char temp[255];
  103.  
  104.     /* Create and display an "about" message */
  105.     strcpy(temp,"PATTERN.DPR - Generates a desktop pattern from a PM 1.1 "
  106.         "Icon.\n\nby John Ridges\n\nCurrent Icon:  ");
  107.     strcat(temp,filepath);
  108.     WinMessageBox(HWND_DESKTOP,hwnd,temp,"DESKPIC",0,MB_OK|MB_NOICON);
  109. }
  110.