home *** CD-ROM | disk | FTP | other *** search
/ cyber.net 2 / cybernet2.ISO / wing / palanim.c_ / palanim.c
C/C++ Source or Header  |  1994-09-07  |  32KB  |  1,017 lines

  1. /**************************************************************************
  2.  
  3.     PALANIM.C - A palette animation demo for WinG
  4.  
  5.  **************************************************************************/
  6. /**************************************************************************
  7.  
  8.     (C) Copyright 1994 Microsoft Corp.  All rights reserved.
  9.  
  10.     You have a royalty-free right to use, modify, reproduce and 
  11.     distribute the Sample Files (and/or any modified version) in 
  12.     any way you find useful, provided that you agree that 
  13.     Microsoft has no warranty obligations or liability for any 
  14.     Sample Application Files which are modified. 
  15.  
  16.  **************************************************************************/
  17.  
  18. #include <windows.h>
  19. #include <commdlg.h>
  20. #include <wing.h>
  21.  
  22. #include "palanim.h"
  23. #include "..\utils\utils.h"
  24.  
  25. /*----------------------------------------------------------------------------*\
  26. |                                                                              |
  27. |   g l o b a l   v a r i a b l e s                                            |
  28. |                                                                              |
  29. \*----------------------------------------------------------------------------*/
  30. static  char       szAppName[]="WinG Palette Animation App";
  31.  
  32. static  HINSTANCE  hInstApp;
  33. static  HWND       hwndApp;
  34. static  HPALETTE   hpalApp;
  35. static  BOOL       fAppActive;
  36.  
  37. static  HDC        hdcOffscreen;
  38. void far *         gpBits;
  39.  
  40. struct {
  41.   BITMAPINFOHEADER InfoHeader;
  42.   RGBQUAD ColorTable[256];
  43. } gInfo;
  44.  
  45. int  fAnimatePalette = 0;    // Don't animate
  46. int  fIncludeStatic = 0;     // Use the static color entries
  47. enum {Red, Green, Blue}  gWashColor = Red;
  48.  
  49. PALETTEENTRY  aPalette[256];
  50.  
  51. extern HBITMAP  ghBitmapMonochrome;
  52.  
  53. #ifdef WIN32
  54.     #define _export
  55. #endif
  56.  
  57. //*** Setting up SYSPAL_NOSTATIC
  58.  
  59. #define NumSysColors (sizeof(SysPalIndex)/sizeof(SysPalIndex[1]))
  60. #define rgbBlack RGB(0,0,0)
  61. #define rgbWhite RGB(255,255,255)
  62.  
  63. //*** These are the GetSysColor display element identifiers
  64. static int SysPalIndex[] = {
  65.   COLOR_ACTIVEBORDER,
  66.   COLOR_ACTIVECAPTION,
  67.   COLOR_APPWORKSPACE,
  68.   COLOR_BACKGROUND,
  69.   COLOR_BTNFACE,
  70.   COLOR_BTNSHADOW,
  71.   COLOR_BTNTEXT,
  72.   COLOR_CAPTIONTEXT,
  73.   COLOR_GRAYTEXT,
  74.   COLOR_HIGHLIGHT,
  75.   COLOR_HIGHLIGHTTEXT,
  76.   COLOR_INACTIVEBORDER,
  77.  
  78.   COLOR_INACTIVECAPTION,
  79.   COLOR_MENU,
  80.   COLOR_MENUTEXT,
  81.   COLOR_SCROLLBAR,
  82.   COLOR_WINDOW,
  83.   COLOR_WINDOWFRAME,
  84.   COLOR_WINDOWTEXT
  85. };
  86.  
  87. //*** This array translates the display elements to black and white
  88. static COLORREF MonoColors[] = {
  89.   rgbBlack,
  90.   rgbWhite,
  91.   rgbWhite,
  92.   rgbWhite,
  93.   rgbWhite,
  94.   rgbBlack,
  95.   rgbBlack,
  96.   rgbBlack,
  97.   rgbBlack,
  98.   rgbBlack,
  99.   rgbWhite,
  100.   rgbWhite,
  101.   rgbWhite,
  102.   rgbWhite,
  103.   rgbBlack,
  104.   rgbWhite,
  105.   rgbWhite,
  106.   rgbBlack,
  107.  
  108.   rgbBlack
  109. };
  110.  
  111. //*** This array holds the old color mapping so we can restore them
  112. static COLORREF OldColors[NumSysColors];
  113.  
  114.  
  115.  
  116. /*----------------------------------------------------------------------------*\
  117. |                                                                              |
  118. |   f u n c t i o n   d e f i n i t i o n s                                    |
  119. |                                                                              |
  120. \*----------------------------------------------------------------------------*/
  121.  
  122. LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  123. int  ErrMsg (LPSTR sz,...);
  124. LONG AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  125.  
  126. void AppExit(void);
  127. BOOL AppIdle(void);
  128.  
  129. /***************************************************************************
  130.   Internal functions for the animation
  131. */
  132.  
  133. void  CreateWashPalette(void);
  134. void  DibCreateWash(BITMAPINFOHEADER far *Info, void far *pBits);
  135. void  DibHorizontalLine(BITMAPINFOHEADER far *Info, void far *pBits,
  136.                         int y, char unsigned color);
  137.  
  138. /***************************************************************************
  139.   Sample functions from wing.hlp
  140. */
  141.  
  142. HDC   Create100x100WinGDC(void);
  143. void  Destroy100x100WinGDC(HDC hWinGDC);
  144.  
  145. void  AppActivate(BOOL fActive);
  146.  
  147. HPALETTE CreateIdentityPalette(RGBQUAD aRGB[], int nColors);
  148.  
  149. /*----------------------------------------------------------------------------*\
  150. |   AppAbout( hDlg, uiMessage, wParam, lParam )                                |
  151. |                                                                              |
  152. |   Description:                                                               |
  153. |       This function handles messages belonging to the "About" dialog box.    |
  154. |       The only message that it looks for is WM_COMMAND, indicating the use   |
  155. |       has pressed the "OK" button.  When this happens, it takes down         |
  156. |       the dialog box.                                                        |
  157. |                                                                              |
  158. |   Arguments:                                                                 |
  159. |       hDlg            window handle of about dialog window                   |
  160. |       uiMessage       message number                                         |
  161. |       wParam          message-dependent                                      |
  162. |       lParam          message-dependent                                      |
  163. |                                                                              |
  164. |   Returns:                                                                   |
  165. |       TRUE if message has been processed, else FALSE                         |
  166. |                                                                              |
  167. \*----------------------------------------------------------------------------*/
  168. BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  169. {
  170.     switch (msg)
  171.     {
  172.         case WM_COMMAND:
  173.             if (LOWORD(wParam) == IDOK)
  174.             {
  175.                 EndDialog(hwnd,TRUE);
  176.             }
  177.             break;
  178.  
  179.         case WM_INITDIALOG:
  180.             return TRUE;
  181.     }
  182.     return FALSE;
  183. }
  184.  
  185. /*----------------------------------------------------------------------------*\
  186. |   AppInit( hInst, hPrev)                                                     |
  187. |                                                                              |
  188. |   Description:                                                               |
  189. |       This is called when the application is first loaded into               |
  190. |       memory.  It performs all initialization that doesn't need to be done   |
  191. |       once per instance.                                                     |
  192. |                                                                              |
  193. |   Arguments:                                                                 |
  194. |       hInstance       instance handle of current instance                    |
  195. |       hPrev           instance handle of previous instance                   |
  196. |                                                                              |
  197. |   Returns:                                                                   |
  198. |       TRUE if successful, FALSE if not                                       |
  199. |                                                                              |
  200. \*----------------------------------------------------------------------------*/
  201. BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
  202. {
  203.   WNDCLASS  cls;
  204.   int       dx,dy;
  205.   HBITMAP   hbmOffscreen;
  206.   HMENU     hMenu;
  207.   HDC       Screen;
  208.   int         PaletteDevice;
  209.   int         nBitsPixel;         
  210.   int         nPlanes;         
  211.   int       nColorDepth;
  212.       
  213.     /* Save instance handle for DialogBoxes */
  214.     hInstApp = hInst;
  215.  
  216.     /* Refuse to run if this is a non-palettized device */
  217.     Screen = GetDC(0);
  218.  
  219.     if (Screen)
  220.     {
  221.       PaletteDevice = GetDeviceCaps(Screen, RASTERCAPS) & RC_PALETTE;
  222.       nBitsPixel = GetDeviceCaps(Screen, BITSPIXEL);         
  223.       nPlanes = GetDeviceCaps(Screen, PLANES);         
  224.