home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / appwiz / customwz / paint.cpp < prev    next >
C/C++ Source or Header  |  1998-03-05  |  1KB  |  55 lines

  1. // paint.cpp: helper functions used when drawing bitmaps on the dialogs
  2. //
  3. // Copyright (c) 1985-1998, Microsoft Corporation. All rights reserved.
  4. //
  5.  
  6. #include "stdafx.h"
  7. #include "customwz.h"
  8.  
  9. #ifdef _PSEUDO_DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14.  
  15. // Coordinates for yellow rectangle in dialog-box units
  16. #define RIGHT_YELLOW_DLGU   124
  17. #define BOTTOM_YELLOW_DLGU  197
  18.  
  19. // Draws a background of yellow on the left side of the dialog
  20. void PaintBackground(CPaintDC* pdc, CDialog* pDlg)
  21. {
  22.     //  Get the yellow brush
  23.     CBitmap pattern;
  24.     pattern.LoadBitmap(IDB_YELLOW_PATTERN);
  25.     CBrush brush(&pattern);
  26.  
  27.     // Draw the yellow background
  28.     CRect rect(0, 0, RIGHT_YELLOW_DLGU+1, BOTTOM_YELLOW_DLGU+1);
  29.     pDlg->MapDialogRect(&rect);
  30.     pdc->DPtoLP(&rect);
  31.     pdc->FillRect(&rect, &brush);
  32. }
  33.  
  34. // Draw the specified bitmap at the specified location
  35. void PaintBitmap(UINT nBmp, int x, int y, int nWidth, int nHeight,
  36.     CPaintDC* pdc, CDC* pdcMem)
  37. {
  38.     CBitmap picture;
  39.  
  40.     // Load & select the bitmap into the device-context
  41.     picture.LoadBitmap(nBmp);
  42.     BITMAP bitmap;
  43.     picture.GetObject(sizeof (BITMAP), &bitmap);
  44.     CBitmap* pOldBitmap = pdcMem->SelectObject(&picture);
  45.  
  46.     ASSERT(nWidth == bitmap.bmWidth);
  47.     ASSERT(nHeight == bitmap.bmHeight);
  48.  
  49.     // Draw the bitmap
  50.     pdc->BitBlt(x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY);
  51.  
  52.     // Reselect the previous bitmap object
  53.     pdcMem->SelectObject(pOldBitmap);
  54. }
  55.