home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 20.ddi / SAMPLES / PALETTE / INIT.C_ / INIT.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  1.5 KB  |  74 lines

  1. /*
  2.     init.c
  3.  
  4.     initialization and error handling code
  5.  
  6. */
  7.  
  8. #include <windows.h>
  9. #include "palette.h"
  10.  
  11.  
  12. /************* first instance initialisation ***************************/
  13.  
  14. BOOL InitFirstInstance(hInstance)
  15. HANDLE hInstance;
  16. {
  17.     WNDCLASS wc;
  18.  
  19.     /* define the class of window we want to register */
  20.  
  21.     wc.lpszClassName    = szAppName;
  22.     wc.style            = CS_HREDRAW | CS_VREDRAW;
  23. //  wc.hCursor            = LoadCursor(NULL, IDC_ARROW);
  24.     wc.hCursor            = LoadCursor(hInstance, "Cursor");
  25.     wc.hIcon            = NULL; // LoadIcon(hInstance,"Icon");
  26.     wc.lpszMenuName        = "Menu";
  27.     wc.hbrBackground    = COLOR_WINDOW+1;
  28.     wc.hInstance        = hInstance;
  29.     wc.lpfnWndProc        = MainWndProc;
  30.     wc.cbClsExtra        = 0;
  31.     wc.cbWndExtra        = 0;
  32.  
  33.     if (! RegisterClass(&wc)) {
  34.         return FALSE; /* Initialization failed */
  35.     }
  36.  
  37.     return TRUE;
  38. }
  39.  
  40. int Error(msg)
  41. LPSTR msg;
  42. {
  43.     MessageBeep(0);
  44.     return MessageBox(hMainWnd, msg, szAppName, MB_OK);
  45. }
  46.  
  47. BOOL bHasPalette(HWND hWnd)
  48. {
  49.     /* returns TRUE if display supports palette elese
  50.     returns FALSE
  51.     */
  52.  
  53.     HDC hDC;
  54.     BOOL bPal;
  55.     WORD wPalSize;
  56.  
  57.     bPal = TRUE; /* ever the optimist */
  58.     hDC = GetDC(hWnd);
  59.     if (!GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE) {
  60.         bPal = FALSE;
  61.     } else {
  62.         wPalSize = GetDeviceCaps(hDC,SIZEPALETTE);
  63.         if (!wPalSize) {
  64.             bPal = FALSE;
  65.         }
  66.     }
  67.     ReleaseDC(hWnd, hDC);
  68.  
  69.     if (bPal) return TRUE;
  70.  
  71.     Error("Display device does not\nsupport a palette");
  72.     return FALSE;
  73. }
  74.