home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_01 / 3n01006b < prev    next >
Text File  |  1991-11-26  |  2KB  |  60 lines

  1.  
  2. /*****************************************************/
  3. /* icon.c                                            */
  4. /* -- Module implements a routine to create an icon. */
  5. /*****************************************************/
  6.  
  7. /*****************************************************/
  8. /* Header files.                                     */
  9. /*****************************************************/
  10. #include <windows.h>
  11. #include "icon.h"
  12.  
  13. /*****************************************************/
  14. /* Routines.                                         */
  15. /*****************************************************/
  16.  
  17. HICON
  18. HicnFromBmpBmp(HBITMAP hbmpColor, HBITMAP hbmpMono)
  19. /******************************************************/
  20. /* -- Given a color and monochrome bitmap with the    */
  21. /*    dimension, create and return a handle to an     */
  22. /*    icon.                                           */
  23. /* -- hbmpColor    : Color bitmap.                       */
  24. /* -- hbmpMono    : Monochrome bitmap.                  */
  25. /******************************************************/
  26.     {
  27.     LPICN   lpicn;
  28.     BITMAP  bmpColor, bmpMono;
  29.     HICON   hicn;
  30.     DWORD   cbColor, cbMono;
  31.  
  32.     /* Get the header info from the bitmaps. */
  33.     GetObject(hbmpMono, sizeof bmpMono, (LPSTR)&bmpMono);
  34.     cbMono = bmpMono.bmWidthBytes * bmpMono.bmHeight;
  35.     GetObject(hbmpColor, sizeof bmpColor, (LPSTR)&bmpColor);
  36.     cbColor = bmpColor.bmWidthBytes * bmpColor.bmHeight;
  37.  
  38.     /* Get some space for the icon. */
  39.     hicn = GlobalAlloc(GMEM_MOVEABLE, sizeof *lpicn -
  40.       sizeof(BYTE) + cbColor + cbMono);
  41.     if (hicn == NULL)
  42.         return hicn;
  43.  
  44.     /* Initialize the icon header info. */
  45.     lpicn = (LPICN)GlobalLock(hicn);
  46.     lpicn->cbLine = bmpMono.bmWidthBytes;
  47.     lpicn->dx = bmpColor.bmWidth;
  48.     lpicn->dy = bmpColor.bmHeight;
  49.     lpicn->ptHot.x = lpicn->ptHot.y = 0;
  50.     lpicn->cpln = bmpColor.bmPlanes;
  51.     lpicn->cbit = bmpColor.bmBitsPixel;
  52.  
  53.     /* Finish the filling the icon with bitmap bits. */
  54.     GetBitmapBits(hbmpMono, cbMono, lpicn->rgb);
  55.     GetBitmapBits(hbmpColor, cbColor,
  56.         lpicn->rgb + cbMono);
  57.     GlobalUnlock(hicn);
  58.     return hicn;
  59.     }
  60.