home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dtime / data.1 / PushPin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-08  |  2.0 KB  |  93 lines

  1. /*
  2. Module : PUSHPIN.H
  3. Purpose: Implementation of a push pin button 
  4.          (as seen on X-Windows & property dialogs in VC 4)
  5. Created: PJN / DATE/1 / 04-04-1996
  6. History: None
  7.  
  8. Copyright (c) 1996 by PJ Naughter.  
  9. All rights reserved.
  10. */
  11.  
  12.  
  13. /////////////////////////////////  Includes  //////////////////////////////////
  14. #include "stdafx.h"
  15. #include "win32sup.h"
  16. #include "PushPin.h"
  17.  
  18.  
  19.  
  20.  
  21. //////////////////////////////////  Macros  ///////////////////////////////////
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #define new DEBUG_NEW
  26. #endif
  27.  
  28.  
  29. #ifndef _WINDOWS
  30. #pragma message("This module should be included in builds for Windows only")
  31. #endif
  32.  
  33.  
  34. ////////////////////////////////// Implementation /////////////////////////////
  35. BEGIN_MESSAGE_MAP(CPushPinButton, CBitmapButton)
  36.   //{{AFX_MSG_MAP(CPushPinButton)
  37.   #ifdef _WIN32
  38.     ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
  39.   #endif
  40.   //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43.  
  44. CPushPinButton::CPushPinButton()
  45. {
  46.   m_bPinned = FALSE;
  47. }
  48.  
  49.  
  50. CPushPinButton::~CPushPinButton()
  51. {
  52. }
  53.  
  54.  
  55. void CPushPinButton::DrawItem(LPDRAWITEMSTRUCT lpDIS) 
  56. {
  57.   ASSERT(lpDIS != NULL);
  58.   
  59.   // must have up and down bitmaps loaded before calling DrawItem
  60.   ASSERT(m_bitmap.m_hObject != NULL);     // required
  61.   ASSERT(m_bitmapSel.m_hObject != NULL);  // required
  62.  
  63.   //select the bitmap
  64.   CBitmap* pBitmap;
  65.   if (m_bPinned)
  66.     pBitmap = &m_bitmapSel;
  67.   else
  68.     pBitmap = &m_bitmap;
  69.   
  70.   // draw the whole button
  71.   CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  72.   CDC memDC;
  73.   memDC.CreateCompatibleDC(pDC);
  74.   CBitmap* pOld = memDC.SelectObject(pBitmap);
  75.   if (pOld == NULL)
  76.     return;     // destructors will clean up
  77.  
  78.   CRect rect;
  79.   rect.CopyRect(&lpDIS->rcItem);
  80.   pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
  81.     &memDC, 0, 0, SRCCOPY);
  82.   memDC.SelectObject(pOld);
  83. }
  84.  
  85.  
  86. void CPushPinButton::OnClicked() 
  87. {
  88.   m_bPinned = !m_bPinned;  //toggle the pin option
  89.   Invalidate();            //force a redraw
  90. }
  91.  
  92.  
  93.