home *** CD-ROM | disk | FTP | other *** search
/ Best Sellers 7: Football Classics 2 / CD1.iso / utils / wing10 / doggie.c_ / doggie.c
C/C++ Source or Header  |  1995-09-20  |  22KB  |  578 lines

  1. /**************************************************************************
  2.  
  3.     DOGGIE.C - a sprite 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 "doggie.h"
  20. #include "mmsystem.h"
  21. #include "..\utils\utils.h"
  22. #include <wing.h>
  23.  
  24. /*----------------------------------------------------------------------------*\
  25. |                                                                              |
  26. |   g l o b a l   v a r i a b l e s                                            |
  27. |                                                                              |
  28. \*----------------------------------------------------------------------------*/
  29. static  char  szAppName[]="Doggie: WinG Sprite Demo";
  30.  
  31. static  HINSTANCE hInstApp;
  32. static  HWND      hwndApp;
  33. static  HPALETTE  hpalApp;
  34. static  BOOL      fAppActive;
  35.  
  36. typedef struct header
  37. {
  38.   BITMAPINFOHEADER  Header;
  39.   RGBQUAD           aColors[256];
  40. } header;
  41.  
  42. header    BufferHeader;
  43. long      Orientation = 1;     // assume bottom-up DIBs
  44. void far *pBuffer = 0;
  45. HDC       Buffer = 0;
  46.  
  47. char unsigned TransparentColor = 0xf3;
  48.  
  49. typedef struct pal
  50. {
  51.   WORD Version;
  52.   WORD NumberOfEntries;
  53.   PALETTEENTRY aEntries[256];
  54. } pal;
  55.  
  56. pal LogicalPalette =
  57. {
  58.   0x300,
  59.   256
  60. };
  61.  
  62. HBITMAP  gbmOldMonoBitmap = 0;
  63. PDIB     pBitmap;
  64. int      BitmapX, BitmapY;
  65. int      DogX, DogY;
  66. int      dx,dy;
  67.  
  68.  
  69. /*----------------------------------------------------------------------------*\
  70. |                                                                              |
  71. |   f u n c t i o n   d e f i n i t i o n s                                    |
  72. |                                                                              |
  73. \*----------------------------------------------------------------------------*/
  74.  
  75. LONG FAR PASCAL _export  AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  76. LONG  AppCommand (HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
  77.  
  78. void  AppExit(void);
  79. BOOL  AppIdle(void);
  80.  
  81. /*----------------------------------------------------------------------------*\
  82. |   AppAbout( hDlg, uiMessage, wParam, lParam )                                |
  83. |                                                                              |
  84. |   Description:                                                               |
  85. |       This function handles messages belonging to the "About" dialog box.    |
  86. |       The only message that it looks for is WM_COMMAND, indicating the user  |
  87. |       has pressed the "OK" button.  When this happens, it takes down         |
  88. |       the dialog box.                                                        |
  89. |                                                                              |
  90. |   Arguments:                                                                 |
  91. |       hDlg            window handle of about dialog window                   |
  92. |       uiMessage       message number                                         |
  93. |       wParam          message-dependent                                      |
  94. |       lParam          message-dependent                                      |
  95. |                                                                              |
  96. |   Returns:                                                                   |
  97. |       TRUE if message has been processed, else FALSE                         |
  98. |                                                                              |
  99. \*----------------------------------------------------------------------------*/
  100. BOOL FAR PASCAL _export AppAbout(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  101. {
  102.     switch (msg)
  103.     {
  104.         case WM_COMMAND:
  105.       if (LOWORD(wParam) == IDOK)
  106.             {
  107.                 EndDialog(hwnd,TRUE);
  108.             }
  109.             break;
  110.  
  111.         case WM_INITDIALOG:
  112.             return TRUE;
  113.     }
  114.     return FALSE;
  115. }
  116.  
  117. /*----------------------------------------------------------------------------*\
  118. |   AppInit( hInst, hPrev)                                                     |
  119. |                                                                              |
  120. |   Description:                                                               |
  121. |       This is called when the application is first loaded into               |
  122. |       memory.  It performs all initialization that doesn't need to be done   |
  123. |       once per instance.                                                     |
  124. |                                                                              |
  125. |   Arguments:                                                                 |
  126. |       hInstance       instance handle of current instance                    |
  127. |       hPrev           instance handle of previous instance                   |
  128. |                                                                              |
  129. |   Returns:                                                                   |
  130. |       TRUE if successful, FALSE if not                                       |
  131. |                                                                              |
  132. \*----------------------------------------------------------------------------*/
  133. BOOL AppInit(HINSTANCE hInst,HINSTANCE hPrev,int sw,LPSTR szCmdLine)
  134. {
  135.     WNDCLASS cls;
  136.  
  137.     /* Save instance handle for DialogBoxes */
  138.     hInstApp = hInst;
  139.  
  140. // Clear the System Palette so that WinG blting runs at full speed.
  141.     ClearSystemPalette();
  142.  
  143.     if (!hPrev)
  144.     {
  145.         /*
  146.          *  Register a class for the main application window
  147.          */
  148.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  149.         cls.hIcon          = LoadIcon(hInst,"AppIcon");
  150.         cls.lpszMenuName   = "AppMenu";
  151.         cls.lpszClassName  = szAppName;
  152.         cls.hbrBackground  = (HBRUSH) NULL;
  153.         cls.hInstance      = hInst;
  154.         cls.style          = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  155.         cls.lpfnWndProc    = (WNDPROC)AppWndProc;
  156.         cls.cbWndExtra     = 0;
  157.         cls.cbClsExtra     = 0;
  158.  
  159.         if (!RegisterClass(&cls))
  160.             return FALSE;
  161.     }
  162.  
  163.     dx = 400;
  164.     dy = 400;
  165.  
  166.     pBitmap = DibOpenFile("Doggie");      
  167.     
  168.     if (!pBitmap)
  169.       pBitmap = DibOpenFile("doggie2.bmp");
  170.  
  171.     BitmapX = DibWidth(pBitmap);
  172.     BitmapY = DibHeight(pBitmap);
  173.  
  174.     hwndApp = CreateWindow (szAppName,              // Class name
  175.                             szAppName,              // Caption
  176.                             WS_OVERLAPPEDWINDOW,    // Style bits
  177.                             CW_USEDEFAULT, 0,       // Position
  178.                             dx,dy,                  // Size
  179.                             (HWND)NULL,             // Parent window (no parent)
  180.                             (HMENU)NULL,            // use class menu
  181.                             hInst,                  // handle to window instance
  182.                             (LPSTR)NULL             // no params to pass on
  183.                            );
  184.     ShowWindow(hwndApp,sw);
  185.  
  186.     return TRUE;
  187. }
  188.  
  189.  
  190. /*----------------------------------------------------------------------------*\
  191. |   AppExit()                                                                  |
  192. |                                                                              |
  193. |   Description:                                                               |
  194. |     App is just about to exit, cleanup.                                      |
  195. |                                                                              |
  196. \*-----