home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM User 1995 January / CDuser6Jan95.iso / DYNASTY / WING / DOGGIE.C_ / DOGGIE.C
C/C++ Source or Header  |  1994-06-19  |  21KB  |  580 lines

  1. /*
  2.  *    DOGGIE.C
  3.  *
  4.  *    (C) Copyright Microsoft Corp. 1993.  All rights reserved.
  5.  *
  6.  *    You have a royalty-free right to use, modify, reproduce and 
  7.  *    distribute the Sample Files (and/or any modified version) in 
  8.  *    any way you find useful, provided that you agree that 
  9.  *    Microsoft has no warranty obligations or liability for any 
  10.  *    Sample Application Files which are modified. 
  11.  */
  12.  
  13. #include <windows.h>
  14. #include "doggie.h"
  15. #include"mmsystem.h"
  16. #include"dib.h"
  17. #include<wing.h>
  18.  
  19. /*----------------------------------------------------------------------------*\
  20. |                                                                              |
  21. |   g l o b a l   v a r i a b l e s                                            |
  22. |                                                                              |
  23. \*----------------------------------------------------------------------------*/
  24. static    char    szAppName[]="Doggie: WinG Sprite Demo";
  25.  
  26. static  HINSTANCE hInstApp;
  27. static  HWND      hwndApp;
  28. static    HPALETTE  hpalApp;
  29. static    BOOL      fAppActive;
  30.  
  31. typedef struct header
  32. {
  33.     BITMAPINFOHEADER Header;
  34.     RGBQUAD aColors[256];
  35. } header;
  36.  
  37. header BufferHeader;
  38. long Orientation = 1;            // assume bottom-up DIBs
  39. void far *pBuffer = 0;
  40. HDC Buffer = 0;
  41.  
  42. char unsigned TransparentColor = 0xf3;
  43.  
  44. typedef struct pal
  45. {
  46.     WORD Version;
  47.     WORD NumberOfEntries;
  48.     PALETTEENTRY aEntries[256];
  49. } pal;
  50.  
  51. pal LogicalPalette =
  52. {
  53.     0x300,
  54.     256
  55. };
  56.  
  57. HBITMAP gbmOldMonoBitmap = 0;
  58.  
  59. PDIB pBitmap;
  60.  
  61. int BitmapX, BitmapY;
  62.  
  63. int DogX, DogY;
  64.  
  65. int dx,dy;
  66.  
  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 use   |
  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 DialogBoxs */
  138.     hInstApp = hInst;
  139.  
  140.     if (!hPrev)
  141.     {
  142.         /*
  143.          *  Register a class for the main application window
  144.          */
  145.         cls.hCursor        = LoadCursor(NULL,IDC_ARROW);
  146.         cls.hIcon          = LoadIcon(hInst,"AppIcon");
  147.         cls.lpszMenuName   = "AppMenu";
  148.         cls.lpszClassName  = szAppName;
  149.         cls.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  150.         cls.hInstance      = hInst;
  151.         cls.style          = CS_BYTEALIGNCLIENT | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  152.         cls.lpfnWndProc    = (WNDPROC)AppWndProc;
  153.         cls.cbWndExtra     = 0;
  154.         cls.cbClsExtra     = 0;
  155.  
  156.         if (!RegisterClass(&cls))
  157.             return FALSE;
  158.     }
  159.  
  160.     dx = 400;
  161.     dy = 400;
  162.  
  163.     pBitmap = DibOpenFile("Doggie");
  164.      if (!pBitmap)
  165.          pBitmap = DibOpenFile("doggie2.bmp");
  166.  
  167.     BitmapX = DibWidth(pBitmap);
  168.     BitmapY = DibHeight(pBitmap);
  169.  
  170.     hwndApp = CreateWindow (szAppName,    // Class name
  171.                             szAppName,              // Caption
  172.                             WS_OVERLAPPEDWINDOW,    // Style bits
  173.                             CW_USEDEFAULT, 0,       // Position
  174.                 dx,dy,            // Size
  175.                             (HWND)NULL,             // Parent window (no parent)
  176.                             (HMENU)NULL,            // use class menu
  177.                             hInst,                  // handle to window instance
  178.                             (LPSTR)NULL             // no params to pass on
  179.                            );
  180.     ShowWindow(hwndApp,sw);
  181.  
  182.     return TRUE;
  183. }
  184.  
  185.  
  186. /*----------------------------------------------------------------------------*\
  187. |   AppExit()                                       |
  188. |                                                                              |
  189. |   Description:                                                               |
  190. |    app is just about to exit, cleanup                       |
  191. |                                                                              |
  192. \*----------------------------------------------------------------------------*/
  193. void AppExit()
  194. {
  195.     if (Buffer)
  196.     {
  197.         HBITMAP hbm;
  198.  
  199.         //  Retrieve the current WinGBitmap, replace with the original
  200.         hbm = (HBITMAP)SelectObject(Buffer, gbmOldMonoBitmap);
  201.  
  202.         //  And delete the WinGBitmap and WinGDC
  203.         DeleteObject(hbm);
  204.         DeleteDC(Buffer);
  205.     }
  206.  
  207.     if(hpalApp)
  208.     {
  209.         DeleteObject(hpalApp);
  210.     }
  211. }
  212.  
  213. /*----------------------------------------------------------------------------*\
  214. |   WinMain( hInst, hPrev, lpszCmdLine, cmdShow )                              |
  215. |