www.pudn.com > VCBOOKSOURCES.zip > AXCTRLCTL.CPP, change:1998-03-06,size:7182b


// AXCtrlCtl.cpp : Implementation of the CAXCtrlCtrl ActiveX Control class. 
 
#include "stdafx.h" 
#include "AXCtrl.h" 
#include "AXCtrlCtl.h" 
#include "AXCtrlPpg.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
 
IMPLEMENT_DYNCREATE(CAXCtrlCtrl, COleControl) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Message map 
 
BEGIN_MESSAGE_MAP(CAXCtrlCtrl, COleControl) 
   //{{AFX_MSG_MAP(CAXCtrlCtrl) 
   ON_WM_LBUTTONUP() 
   //}}AFX_MSG_MAP 
   ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Dispatch map 
 
BEGIN_DISPATCH_MAP(CAXCtrlCtrl, COleControl) 
   //{{AFX_DISPATCH_MAP(CAXCtrlCtrl) 
   DISP_PROPERTY_NOTIFY(CAXCtrlCtrl, "ShowFrame", m_showFrame, OnShowFrameChanged, VT_BOOL) 
   DISP_STOCKPROP_BACKCOLOR() 
   //}}AFX_DISPATCH_MAP 
   DISP_FUNCTION_ID(CAXCtrlCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) 
END_DISPATCH_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Event map 
 
BEGIN_EVENT_MAP(CAXCtrlCtrl, COleControl) 
   //{{AFX_EVENT_MAP(CAXCtrlCtrl) 
   EVENT_STOCK_CLICK() 
   //}}AFX_EVENT_MAP 
END_EVENT_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Property pages 
 
// TODO: Add more property pages as needed.  Remember to increase the count! 
BEGIN_PROPPAGEIDS(CAXCtrlCtrl, 2) 
   PROPPAGEID(CAXCtrlPropPage::guid) 
   PROPPAGEID(CLSID_CColorPropPage) 
END_PROPPAGEIDS(CAXCtrlCtrl) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Initialize class factory and guid 
 
IMPLEMENT_OLECREATE_EX(CAXCtrlCtrl, "AXCTRL.AXCtrlCtrl.1", 
   0xcc31d286, 0xb1b1, 0x11d1, 0x80, 0xfc, 0, 0xc0, 0xf6, 0xa8, 0x3b, 0x7f) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Type library ID and version 
 
IMPLEMENT_OLETYPELIB(CAXCtrlCtrl, _tlid, _wVerMajor, _wVerMinor) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Interface IDs 
 
const IID BASED_CODE IID_DAXCtrl = 
      { 0xcc31d284, 0xb1b1, 0x11d1, { 0x80, 0xfc, 0, 0xc0, 0xf6, 0xa8, 0x3b, 0x7f } }; 
const IID BASED_CODE IID_DAXCtrlEvents = 
      { 0xcc31d285, 0xb1b1, 0x11d1, { 0x80, 0xfc, 0, 0xc0, 0xf6, 0xa8, 0x3b, 0x7f } }; 
 
 
///////////////////////////////////////////////////////////////////////////// 
// Control type information 
 
static const DWORD BASED_CODE _dwAXCtrlOleMisc = 
   OLEMISC_ACTIVATEWHENVISIBLE | 
   OLEMISC_SETCLIENTSITEFIRST | 
   OLEMISC_INSIDEOUT | 
   OLEMISC_CANTLINKINSIDE | 
   OLEMISC_RECOMPOSEONRESIZE; 
 
IMPLEMENT_OLECTLTYPE(CAXCtrlCtrl, IDS_AXCTRL, _dwAXCtrlOleMisc) 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::CAXCtrlCtrlFactory::UpdateRegistry - 
// Adds or removes system registry entries for CAXCtrlCtrl 
 
BOOL CAXCtrlCtrl::CAXCtrlCtrlFactory::UpdateRegistry(BOOL bRegister) 
{ 
   // TODO: Verify that your control follows apartment-model threading rules. 
   // Refer to MFC TechNote 64 for more information. 
   // If your control does not conform to the apartment-model rules, then 
   // you must modify the code below, changing the 6th parameter from 
   // afxRegApartmentThreading to 0. 
 
   if (bRegister) 
      return AfxOleRegisterControlClass( 
         AfxGetInstanceHandle(), 
         m_clsid, 
         m_lpszProgID, 
         IDS_AXCTRL, 
         IDB_AXCTRL, 
         afxRegApartmentThreading, 
         _dwAXCtrlOleMisc, 
         _tlid, 
         _wVerMajor, 
         _wVerMinor); 
   else 
      return AfxOleUnregisterClass(m_clsid, m_lpszProgID); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::CAXCtrlCtrl - Constructor 
 
CAXCtrlCtrl::CAXCtrlCtrl() 
{ 
   InitializeIIDs(&IID_DAXCtrl, &IID_DAXCtrlEvents); 
 
   // TODO: Initialize your control's instance data here. 
 
   m_BitmapNight.LoadBitmap (IDB_BITMAP1); 
   m_BitmapDay.LoadBitmap (IDB_BITMAP2); 
   m_CurrentBitmap = &m_BitmapNight; // initially display the "night" bitmap 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::~CAXCtrlCtrl - Destructor 
 
CAXCtrlCtrl::~CAXCtrlCtrl() 
{ 
   // TODO: Cleanup your control's instance data here. 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::OnDraw - Drawing function 
 
void CAXCtrlCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) 
{ 
   // TODO: Replace the following code with your own drawing code. 
  
   CBrush Brush (TranslateColor (GetBackColor ())); 
   pdc->FillRect (rcBounds, &Brush); 
   
   BITMAP BM; 
   CDC MemDC; 
 
   MemDC.CreateCompatibleDC (NULL); 
   MemDC.SelectObject (*m_CurrentBitmap); 
   m_CurrentBitmap->GetObject (sizeof (BM), &BM); 
   pdc->BitBlt 
      ((rcBounds.right  - BM.bmWidth)  / 2,           
      ( rcBounds.bottom - BM.bmHeight) / 2,            
      BM.bmWidth,   
      BM.bmHeight,  
      &MemDC,       
      0,            
      0,            
      SRCCOPY); 
 
   if (m_showFrame) 
      { 
      CBrush *pOldBrush = (CBrush *)pdc->SelectStockObject (NULL_BRUSH); 
      CPen Pen (PS_SOLID | PS_INSIDEFRAME, 10, RGB (0,0,0)); 
      CPen *pOldPen = pdc->SelectObject (&Pen);       
 
      pdc->Rectangle (rcBounds); 
 
      pdc->SelectObject (pOldPen); 
      pdc->SelectObject (pOldBrush); 
      } 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::DoPropExchange - Persistence support 
 
void CAXCtrlCtrl::DoPropExchange(CPropExchange* pPX) 
{ 
   ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); 
   COleControl::DoPropExchange(pPX); 
 
   // TODO: Call PX_ functions for each persistent custom property. 
   PX_Bool (pPX, _T("ShowFrame"), m_showFrame, FALSE); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::OnResetState - Reset control to default state 
 
void CAXCtrlCtrl::OnResetState() 
{ 
   COleControl::OnResetState();  // Resets defaults found in DoPropExchange 
 
   // TODO: Reset any other control state here. 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl::AboutBox - Display an "About" box to the user 
 
void CAXCtrlCtrl::AboutBox() 
{ 
   CDialog dlgAbout(IDD_ABOUTBOX_AXCTRL); 
   dlgAbout.DoModal(); 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CAXCtrlCtrl message handlers 
 
void CAXCtrlCtrl::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
   // TODO: Add your message handler code here and/or call default 
 
   if (m_CurrentBitmap == &m_BitmapNight) 
      m_CurrentBitmap = &m_BitmapDay; 
   else 
      m_CurrentBitmap = &m_BitmapNight; 
 
   InvalidateControl (); 
    
   COleControl::OnLButtonUp(nFlags, point); 
} 
 
void CAXCtrlCtrl::OnShowFrameChanged()  
{ 
   // TODO: Add notification handler code 
 
   InvalidateControl (); 
 
   SetModifiedFlag(); 
}