home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / audio / idfedit / tridee.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  4KB  |  144 lines

  1. //************************************************************************
  2. //**
  3. //**  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. //**  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  5. //**  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR
  6. //**  A PARTICULAR PURPOSE.
  7. //**
  8. //**  Copyright (C) 1993 - 1997 Microsoft Corporation. All Rights Reserved.
  9. //**
  10. //**  tridee.c
  11. //**
  12. //**  DESCRIPTION:
  13. //**    routines to draw 3d borders
  14. //**
  15. //************************************************************************
  16.  
  17. #include <windows.h>
  18. #include <windowsx.h>
  19.  
  20. #include "res.h"
  21. #include "tridee.h"
  22.  
  23. // declare variables global to this module
  24. //
  25. static COLORREF crFace;
  26. static COLORREF crHilite;
  27. static COLORREF crShadow;
  28.  
  29. static HBRUSH hBrFace = NULL;
  30. static HBRUSH hBrShadow = NULL;
  31. static HBRUSH hBrHilite = NULL;
  32. static BOOL   bIs3D = FALSE;
  33. static int    cUsers = 0;
  34.  
  35. /*+ TrideeCreate
  36.  *
  37.  * Register a new client for the Tridee stuff.
  38.  *
  39.  * on the first client we create the brushes that we will need.
  40.  * on others we just release the useage count.
  41.  *
  42.  * this routine is intended to be called in the WM_CREATE case of the
  43.  * client.
  44.  *
  45.  *-=================================================================*/
  46.  
  47. HBRUSH FAR PASCAL TrideeCreate(HWND hWnd)
  48. {
  49.    hWnd;
  50.  
  51.    if(!cUsers++)
  52.    {
  53.       // create the button face brush, if we fail this,
  54.       // set the use count back to 0 and return failure to
  55.       // the caller.
  56.       //
  57.       crFace = GetSysColor(COLOR_BTNFACE);
  58.       crShadow = GetSysColor(COLOR_BTNSHADOW);
  59.       crHilite = GetSysColor(COLOR_BTNHIGHLIGHT);
  60.  
  61.       hBrFace = CreateSolidBrush(crFace);
  62.       if(!hBrFace)
  63.       {
  64.          cUsers = 0;
  65.          return NULL;
  66.       }
  67.  
  68.       // if the button face color is white, assume we are
  69.       // on a EGA or Mono system, and dont even try to create
  70.       // hilite and shadow brushes.
  71.       bIs3D = (crFace != RGB(255,255,255));
  72.       if (!bIs3D)
  73.          hBrShadow = hBrHilite = NULL;
  74.       else
  75.       {
  76.          // create brushes for the hilite and shadow
  77.          //
  78.          hBrShadow = CreateSolidBrush(crShadow);
  79.          hBrHilite = CreateSolidBrush(crHilite);
  80.       }
  81.    }
  82.  
  83.    return hBrFace;
  84. }
  85.  
  86. /*+ TrideeDestroy
  87.  *
  88.  * DeRegister a client for the tridee stuff.
  89.  *
  90.  * when the count of clients gets to 0, we destroy the brushes.
  91.  *
  92.  * this routine is intended to be used in the WM_DESTROY case of
  93.  * the client.
  94.  *
  95.  *-=================================================================*/
  96.  
  97. BOOL FAR PASCAL TrideeDestroy(HWND hWnd)
  98. {
  99.    hWnd;
  100.  
  101.    if(!--cUsers)
  102.    {
  103.       // free the GDI objects
  104.       if(hBrFace)
  105.          DeleteObject(hBrFace), hBrFace = NULL;
  106.       if(hBrHilite)
  107.          DeleteObject(hBrHilite), hBrHilite = NULL;
  108.       if(hBrShadow)
  109.          DeleteObject(hBrShadow), hBrShadow = NULL;
  110.    }
  111.    return TRUE;
  112. }
  113.  
  114. /*+ TrideeWellShadow
  115.  *
  116.  * draw a well border just inside the supplied rectangle.
  117.  * (a well has a hilite on lower and right edges and shadow
  118.  * on upper and left)
  119.  *
  120.  * this routine does not fill the recangle, it merely paints
  121.  * the 'frame'
  122.  *
  123.  *-=================================================================*/
  124.  
  125. VOID FAR PASCAL TrideeWellShadow(HDC hDC, LPRECT lprc)
  126. {
  127.    // draw the left and upper shadow
  128.    //
  129.    SelectObject(hDC, hBrShadow);
  130.    PatBlt(hDC, lprc->left, lprc->top, 2, 
  131.                      lprc->bottom - lprc->top -2, PATCOPY);
  132.    PatBlt(hDC, lprc->left, lprc->top, 
  133.                      lprc->right - lprc->left, 2, PATCOPY);
  134.  
  135.    // now draw the bottom and right hilite
  136.    //
  137.    SelectObject(hDC, hBrHilite);
  138.    PatBlt(hDC, lprc->right-1, lprc->top+1,
  139.                 1, lprc->bottom - lprc->top -2, PATCOPY);
  140.    PatBlt(hDC, lprc->left+1, lprc->bottom-1,
  141.                 lprc->right -lprc->left-1, 1, PATCOPY);
  142.  
  143. }
  144.