home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WBITMAP.ZIP / BMINFO.C < prev    next >
C/C++ Source or Header  |  1991-11-12  |  3KB  |  140 lines

  1. /*
  2. **    $id: ssvcid bminfo.c 1.1 11/12/91  8:38 am$
  3. **        This file contains the information display function to let the user
  4. **    know what is currently happening.
  5. **
  6. **    (C) 1991    Larry Widing
  7. */
  8. #include    <windows.h>
  9. #include    <string.h>
  10. #include    <stdio.h>
  11. #include    "bitmaps.h"
  12. #include    "bmmanip.h"
  13. #include    "icnfile.h"
  14.  
  15. /*
  16. ** void
  17. ** InfoDisplay(void);
  18. **
  19. **    This function displays a message box that lists what type of image is
  20. **    currently loaded (icon, bitmap, nothing) and various attributes of that
  21. **    object.
  22. **
  23. ** Modification History:
  24. ** 09/13/91  LCW  Created
  25. */
  26. void
  27. InfoDisplay(void)
  28. {
  29.     char    text[500];
  30.  
  31.     text[0] = '\0';
  32.  
  33.     if (BitmapHandle != (HBITMAP)NULL)
  34.     {
  35.         /*
  36.         **    Currently displaying a Windows bitmap
  37.         */
  38.         BITMAP    bm;
  39.  
  40.         if (GetObject(BitmapHandle, sizeof(BITMAP), (LPSTR)&bm))
  41.         {
  42.             sprintf(text,
  43.                 "Windows Bitmap\n"
  44.                 "Size: %u by %u\n"
  45.                 "%u color planes\n"
  46.                 "%u bits per pixel",
  47.                 bm.bmWidth, bm.bmHeight, bm.bmPlanes, bm.bmBitsPixel);
  48.         }
  49.         else
  50.         {
  51.             strcpy(text, "Windows Bitmap\nUnable to access BITMAP structure");
  52.         }
  53.     }
  54.     else if (DIBitmapHandle != (HANDLE)NULL)
  55.     {
  56.         /*
  57.         **    Currently displaying a Device Independant Bitmap
  58.         */
  59.         BITMAPINFO FAR    *bmi;
  60.  
  61.         bmi = (BITMAPINFO FAR *)GlobalLock(DIBitmapHandle);
  62.         if (bmi != NULL)
  63.         {
  64.             if (bmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
  65.             {
  66.                 BITMAPCOREINFO FAR *bci = (BITMAPCOREINFO FAR *)bmi;
  67.  
  68.                 sprintf(text,
  69.                     "OS/2 Device Independant Bitmap\n"
  70.                     "Size: %u by %u\n"
  71.                     "Memory: %lu bytes\n"
  72.                     "%u color planes\n"
  73.                     "%u bits per pixel",
  74.                     bci->bmciHeader.bcWidth, bci->bmciHeader.bcHeight,
  75.                     GlobalSize(DIBitmapHandle),
  76.                     bci->bmciHeader.bcPlanes, bci->bmciHeader.bcBitCount);
  77.             }
  78.             else
  79.             {
  80.                 sprintf(text,
  81.                     "Windows 3.0 Device Independant Bitmap\n"
  82.                     "Size: %lu by %lu\n"
  83.                     "Memory: %lu bytes\n"
  84.                     "%u color planes\n"
  85.                     "%u bits per pixel\n"
  86.                     "%u color entries used",
  87.                     bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight,
  88.                     GlobalSize(DIBitmapHandle),
  89.                     bmi->bmiHeader.biPlanes, bmi->bmiHeader.biBitCount,
  90.                     DIBitmapColors(bmi));
  91.  
  92.                 switch (bmi->bmiHeader.biCompression)
  93.                 {
  94.                     case BI_RLE8:
  95.                         strcat(text, "\nCompressed with 8-bit Run Length Encoding");
  96.                         break;
  97.  
  98.                     case BI_RLE4:
  99.                         strcat(text, "\nCompressed with 4-bit Run Length Encoding");
  100.                         break;
  101.                 }
  102.             }
  103.             GlobalUnlock(DIBitmapHandle);
  104.         }
  105.         else
  106.         {
  107.             strcpy(text, "Device Independant Bitmap\nUnable to lock resource");
  108.         }
  109.     }
  110.     else if (IconHandle != (HICON)NULL)
  111.     {
  112.         /*
  113.         **    Currently displaying a Icon
  114.         */
  115.         sprintf(text,
  116.             "Windows Icon\n"
  117.             "Size: %u by %u\n"
  118.             "%u colors\n"
  119.             "%u icons in file",
  120.             CurIcon.width, CurIcon.height, CurIcon.colorCount,
  121.             CurIconFile.icoResourceCount);
  122.     }
  123.  
  124.     if (text[0] != '\0')
  125.     {
  126.         /* Display the formatted text */
  127.         MessageBox(MainWindow, (LPSTR)text, (LPSTR)"Bitmap Demo",
  128.             MB_OK | MB_ICONINFORMATION | MB_TASKMODAL);
  129.     }
  130. }
  131.  
  132. /*
  133. **    Modification History
  134. **    --------------------
  135. **    $lgb$
  136. ** 10/15/91     Larry Widing   Initial version for Win Tech Journal Article.
  137. ** 11/12/91     Larry Widing   Added memory usage to info display for DIBs.
  138. **    $lge$
  139. */
  140.