home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / physco.zip / PHYSCOLO.C < prev    next >
C/C++ Source or Header  |  1993-08-24  |  4KB  |  132 lines

  1. /* PHYSCOLO.C -- Program to display the physical screen colors */
  2. /* Version 2.0 */
  3.  
  4. /* This program is Copyright (c) 1992, 1993 by Raja Thiagarajan and
  5.    Peter Nielsen. However, you may freely use it for any non-commercial
  6.    purpose. You can contact us at sthiagar@nickel.ucs.indiana.edu
  7.    or pnielsen@finabo.abo.fi respectively.*/
  8.  
  9. /* Many thanks to Peter for significantly speeding this program up for
  10.    OS/2 2.1. My apologies to him for destroying his pretty indentation
  11.    style and his variable-naming conventions.*/
  12.  
  13. #define INCL_GPI
  14. #define INCL_WIN
  15. #include <os2.h>
  16.  
  17. #define MAX_PAL_SIZE 256
  18.  
  19. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2);
  20.  
  21. static HAB hab;
  22.  
  23. #define clientClass "PhysColor"
  24.  
  25. VOID main (VOID)
  26. {
  27.    HMQ   hmq;
  28.    QMSG  qmsg;
  29.    HWND  hwndFrame, hwndClient;
  30.  
  31.    ULONG createFlags =  FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER
  32.                         | FCF_MINMAX | FCF_SHELLPOSITION |  FCF_TASKLIST;
  33.  
  34.    hab = WinInitialize (0);
  35.    hmq = WinCreateMsgQueue (hab, 0);
  36.  
  37.    WinRegisterClass (hab, clientClass, (PFNWP)ClientWndProc,
  38.                      CS_SIZEREDRAW, 0);
  39.  
  40.    hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE, &createFlags,
  41.                                    clientClass, "", 0, 0, 0,
  42.                                    &hwndClient);
  43.  
  44.  
  45.    while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
  46.       WinDispatchMsg (hab, &qmsg);
  47.  
  48.    WinDestroyWindow (hwndFrame);
  49.    WinDestroyMsgQueue (hmq);
  50.    WinTerminate (hab);
  51. }
  52.  
  53. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  54. {
  55.    static ULONG cWidth, cHeight;
  56.    static LONG     colorsToShow, colorsAvail;
  57.    static HPAL    hpal = NULLHANDLE;
  58.    register    i;
  59.  
  60.    switch (msg) {
  61.       case WM_CREATE:
  62.          {
  63.          HDC   hdc;
  64.          LONG  addlGraphics;
  65.          PSZ   title;
  66.  
  67.          hdc = WinOpenWindowDC (hwnd);
  68.  
  69.          DevQueryCaps (hdc, CAPS_COLORS, 1L, &colorsAvail);
  70.          DevQueryCaps (hdc, CAPS_ADDITIONAL_GRAPHICS, 1,
  71.                        &addlGraphics);
  72.  
  73.  
  74.          if (addlGraphics & CAPS_PALETTE_MANAGER) {
  75.             ULONG table [MAX_PAL_SIZE];
  76.             colorsToShow = colorsAvail;
  77.             if (colorsToShow > MAX_PAL_SIZE)
  78.                colorsToShow = MAX_PAL_SIZE;
  79.  
  80.             for (i = 0; i < colorsToShow; i++)
  81.                table [i] = (PC_EXPLICIT << 24) + i;
  82.  
  83.             hpal = GpiCreatePalette (hab, 0L, LCOLF_CONSECRGB,
  84.                                      colorsToShow, table);
  85.  
  86.             title = "Physical Color Viewer";
  87.          } else
  88.             title = "Color Viewer";
  89.  
  90.          WinSetWindowText (WinQueryWindow (hwnd, QW_PARENT), title);
  91.          }
  92.          break;
  93.       case WM_SIZE:
  94.          cWidth  = (ULONG)SHORT1FROMMP (mp2);
  95.          cHeight = (ULONG)SHORT2FROMMP (mp2);
  96.          break;
  97.       case WM_ERASEBACKGROUND:
  98.          return (MRESULT)TRUE;
  99.       case WM_PAINT:
  100.          {
  101.          POINTL   ptlA, ptlB;
  102.      ULONG    temp = colorsToShow;
  103.          HPS       hps;
  104.  
  105.          hps = WinBeginPaint (hwnd, NULLHANDLE, NULL);
  106.  
  107.          GpiSelectPalette (hps, hpal);
  108.          WinRealizePalette (hwnd, hps, &temp);
  109.  
  110.          ptlA.y = 0;
  111.          ptlB.y = cHeight;
  112.          i = 0;
  113.          while (i < cWidth) {
  114.             ptlA.x = ptlB.x = i;
  115.             GpiSetColor (hps, (++i * colorsToShow) / cWidth);
  116.             GpiMove (hps, &ptlA);
  117.             GpiLine (hps, &ptlB);
  118.          }
  119.  
  120.          WinEndPaint (hps);
  121.          }
  122.          break;
  123.       case WM_DESTROY:
  124.          if (hpal)
  125.             GpiDeletePalette (hpal);
  126.          break;
  127.       default:
  128.          return (WinDefWindowProc (hwnd, msg, mp1, mp2));
  129.    }
  130.    return ((MRESULT)FALSE);
  131. }
  132.