home *** CD-ROM | disk | FTP | other *** search
/ Learn 3D Graphics Programming on the PC / Learn_3D_Graphics_Programming_on_the_PC_Ferraro.iso / rwwin / common.c_ / common.bin
Encoding:
Text File  |  1995-11-14  |  4.8 KB  |  152 lines

  1. /**********************************************************************
  2.  *
  3.  * File :     common.c
  4.  *
  5.  * Abstract : Some generally useful functions for Windows applications
  6.  *
  7.  **********************************************************************
  8.  *
  9.  * This file is a product of Criterion Software Ltd.
  10.  *
  11.  * This file is provided as is with no warranties of any kind and is
  12.  * provided without any obligation on Criterion Software Ltd. or
  13.  * Canon Inc. to assist in its use or modification.
  14.  *
  15.  * Criterion Software Ltd. will not, under any
  16.  * circumstances, be liable for any lost revenue or other damages arising
  17.  * from the use of this file.
  18.  *
  19.  * Copyright (c) 1995 Criterion Software Ltd.
  20.  * All Rights Reserved.
  21.  *
  22.  * RenderWare is a trademark of Canon Inc.
  23.  *
  24.  ************************************************************************/
  25. #define INCLUDE_SHELLAPI_H
  26.  
  27. #include <windows.h>
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31.  
  32. #include <rwlib.h>
  33. #include <rwwin.h>
  34.  
  35. /************************************************************************
  36.  *
  37.  *      Function:       AllowStretching()
  38.  *                      
  39.  *      Description:    Test whether to allow WinG or DIBSection stretching
  40.  *                      for this application. The rules that are applied are
  41.  *                      if WinG or DIBSection bitmaps are used AND we are 
  42.  *                      running in 8 bit then allow stretching. For all other
  43.  *                      bitmap types and display depths disallow it.
  44.  *
  45.  *      Return Value:   TRUE if strecthing is allowed, FALSE otherwise
  46.  *
  47.  ************************************************************************/
  48. RwInt32 AllowStretching(HWND window)
  49. {
  50.     RwInt32 Stretching = FALSE;
  51.     DWORD version;
  52.     int   majorVersion;
  53.     int   minorVersion;
  54.     HDC  dc;
  55.     int  depth;
  56.  
  57.     /* find out the current display depth */
  58.  
  59.     dc = GetDC(window);
  60.     depth = GetDeviceCaps(dc, BITSPIXEL);
  61.     ReleaseDC(window, dc);
  62.  
  63.     if (depth == 8)
  64.     {
  65.         /* Check if we're using WING first */
  66.  
  67.         RwGetDeviceInfo(rwWINUSINGWING, &Stretching, sizeof(RwInt32));
  68.  
  69.         if (!Stretching)   /* not enabled yet */
  70.         {
  71.             /* Find out which version of Windows we are running on */
  72.  
  73.             version      = GetVersion();
  74.             majorVersion = LOBYTE(LOWORD(version));
  75.             minorVersion = HIBYTE(LOWORD(version));
  76.  
  77.             /* If we are on Windows 95 or NT 3.5 at this point then we must
  78.                be using DibSections if native or DIBS otherwise */
  79.  
  80.             if ((majorVersion == 3) && (minorVersion < 95))
  81.             {
  82.                 if (version < 0x80000000UL)
  83.                 {
  84.                     /* NT */
  85. #ifdef WIN32
  86.                     Stretching = TRUE;
  87. #else
  88.                     Stretching = FALSE;
  89. #endif
  90.                 }
  91.             }
  92.             else
  93.             {
  94.                 /* Windows 95.*/
  95. #ifdef WIN32
  96.                 Stretching = TRUE;
  97. #else
  98.                 Stretching = FALSE;
  99. #endif
  100.             }
  101.         }
  102.     }
  103.     return(Stretching);
  104. }
  105. /************************************************************************
  106.  *
  107.  *      Function:       CheckDisplayDepth()
  108.  *                      
  109.  *      Description:   Check the depth of the display and pop up a 
  110.  *                     warning dialogue if it isn't one of the native
  111.  *                     RenderWare depths.
  112.  *
  113.  *      Parameters:    window - The window for the calling application
  114.  *
  115.  *      Return Value:   The current display depth
  116.  *
  117.  ************************************************************************/
  118. int
  119. CheckDisplayDepth(HWND window)
  120. {
  121.     HDC  dc;
  122.     int  depth;
  123.     char buffer[512];
  124.  
  125.     /*
  126.      * Check the depth of the display. Although RenderWare will operate
  127.      * correctly at all display depths it performs best when the display
  128.      * depth is equal to one of its native render depths (8- or 16-bit).
  129.      * If the display depth is not equal to one of these depths then
  130.      * a message box is displayed recommending the depth of the display
  131.      * is changed.
  132.      */
  133.     dc = GetDC(window);
  134.     depth = GetDeviceCaps(dc, BITSPIXEL);
  135.     ReleaseDC(window, dc);
  136.     if ((depth != 8) && (depth != 16))
  137.     {
  138.         wsprintf(buffer,
  139. "Your video adapter is currently running in %ld color mode.\n"
  140. "Although RenderWare will operate correctly in this mode,\n"
  141. "we recommend that you change the mode of your video adapter\n"
  142. "to 256 color mode (for best performance) or 65536 color mode\n"
  143. "(for highest quality rendering).",
  144.                  (unsigned long)1 << depth);
  145.         MessageBox(window, buffer, "RenderWare(tm) Application",
  146.                    MB_OK | MB_APPLMODAL | MB_ICONINFORMATION);
  147.     }
  148.     return (depth);
  149. }
  150.  
  151.  
  152.