home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------//
- // Implementation of CQuoteCtrl OLE control class //
- // //
- // System: Simple first control. //
- // Developing Applications with OCX //
- // Module: CQuoteCtrl class implementation //
- // Date: 1/11/1994 //
- // Rev: 1.0 //
- // //
- // Author: John Toohey //
- // //
- //------------------------------------------------------------------//
-
- #include "stdafx.h"
- #include "quote.h"
- #include "quotectl.h"
- #include "quoteppg.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
-
- IMPLEMENT_DYNCREATE(CQuoteCtrl, COleControl)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Message map
-
- BEGIN_MESSAGE_MAP(CQuoteCtrl, COleControl)
- //{{AFX_MSG_MAP(CQuoteCtrl)
- ON_WM_LBUTTONDBLCLK()
- //}}AFX_MSG_MAP
- ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
- ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Dispatch map
- //
- BEGIN_DISPATCH_MAP(CQuoteCtrl, COleControl)
- //{{AFX_DISPATCH_MAP(CQuoteCtrl)
- DISP_PROPERTY_NOTIFY(CQuoteCtrl, "ShowAuthor", m_showAuthor, OnShowAuthorChanged, VT_BOOL)
- DISP_STOCKPROP_BACKCOLOR()
- DISP_STOCKPROP_FORECOLOR()
- DISP_STOCKPROP_FONT()
- //}}AFX_DISPATCH_MAP
- DISP_FUNCTION_ID(CQuoteCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
- END_DISPATCH_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Event map
- //
- BEGIN_EVENT_MAP(CQuoteCtrl, COleControl)
- //{{AFX_EVENT_MAP(CQuoteCtrl)
- EVENT_STOCK_DBLCLICK()
- //}}AFX_EVENT_MAP
- END_EVENT_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Property pages
- // Remember to increase the count!
- BEGIN_PROPPAGEIDS(CQuoteCtrl, 3)
- PROPPAGEID(CQuotePropPage::guid)
- PROPPAGEID(CLSID_CColorPropPage)
- PROPPAGEID(CLSID_CFontPropPage)
- END_PROPPAGEIDS(CQuoteCtrl)
-
- /////////////////////////////////////////////////////////////////////////////
- // Initialize class factory and guid
- //
- IMPLEMENT_OLECREATE_EX(CQuoteCtrl, "QUOTE.QuoteCtrl.1",
- 0x7c647080, 0xf1cb, 0x101b, 0x81, 0xec, 0xb2, 0x31, 0x69, 0x42, 0x46, 0x30)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Type library ID and version
- //
- IMPLEMENT_OLETYPELIB(CQuoteCtrl, _tlid, _wVerMajor, _wVerMinor)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Interface IDs
- //
- const IID BASED_CODE IID_DQuote =
- { 0x7c647081, 0xf1cb, 0x101b, { 0x81, 0xec, 0xb2, 0x31, 0x69, 0x42, 0x46, 0x30 } };
- const IID BASED_CODE IID_DQuoteEvents =
- { 0x7c647082, 0xf1cb, 0x101b, { 0x81, 0xec, 0xb2, 0x31, 0x69, 0x42, 0x46, 0x30 } };
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Control type information
- //
- static const DWORD BASED_CODE _dwQuoteOleMisc =
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST |
- OLEMISC_INSIDEOUT |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_RECOMPOSEONRESIZE;
-
- IMPLEMENT_OLECTLTYPE(CQuoteCtrl, IDS_QUOTE, _dwQuoteOleMisc)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::CQuoteCtrlFactory::UpdateRegistry -
- // Adds or removes system registry entries for CQuoteCtrl
- //
- BOOL CQuoteCtrl::CQuoteCtrlFactory::UpdateRegistry(BOOL bRegister)
- {
- if (bRegister)
- return AfxOleRegisterControlClass(
- AfxGetInstanceHandle(),
- m_clsid,
- m_lpszProgID,
- IDS_QUOTE,
- IDB_QUOTE,
- TRUE, // Insertable
- _dwQuoteOleMisc,
- _tlid,
- _wVerMajor,
- _wVerMinor);
- else
- return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Licensing strings
-
- static const TCHAR BASED_CODE _szLicFileName[] = _T("QUOTE.LIC");
-
- static const TCHAR BASED_CODE _szLicString[] =
- _T("Copyright (c) 1994 Tangent Software");
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::CQuoteCtrlFactory::VerifyUserLicense -
- // Checks for existence of a user license
-
- BOOL CQuoteCtrl::CQuoteCtrlFactory::VerifyUserLicense()
- {
- return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
- _szLicString);
-
- BOOL bfound = AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName,
- _szLicString);
-
- if (bfound)
- AfxMessageBox(_T("Found license file"));
- else
- AfxMessageBox(_T("License file NOT found"));
-
- return (bfound);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::CQuoteCtrlFactory::GetLicenseKey -
- // Returns a runtime licensing key
-
- BOOL CQuoteCtrl::CQuoteCtrlFactory::GetLicenseKey(DWORD dwReserved,
- BSTR FAR* pbstrKey)
- {
- if (pbstrKey == NULL)
- return FALSE;
-
- *pbstrKey = SysAllocString(_szLicString);
- return (*pbstrKey != NULL);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::CQuoteCtrl - Constructor
- //
- CQuoteCtrl::CQuoteCtrl()
- {
- InitializeIIDs(&IID_DQuote, &IID_DQuoteEvents);
-
- m_bstrQuote[0] = SysAllocString(_T("If a headline ends in a question mark, the answer is no"));
- m_bstrQuote[1] = SysAllocString(_T("Nothings is ever so bad that it can't get worse"));
- m_bstrQuote[2] = SysAllocString(_T("A crisis is when you can't say, Let's forget the whole thing."));
- m_bstrQuote[3] = SysAllocString(_T("If you mess with a thing long enough, it will break."));
- m_bstrQuote[4] = SysAllocString(_T("It is easier to get forgiveness than permission."));
- m_bstrQuote[5] = SysAllocString(_T("If you can't fix it, feature it"));
-
- m_bstrAuthor[0] = SysAllocString(_T("Davis' Law"));
- m_bstrAuthor[1] = SysAllocString(_T("Murphy"));
- m_bstrAuthor[2] = SysAllocString(_T("Ferguson"));
- m_bstrAuthor[3] = SysAllocString(_T("Schmidt's Law"));
- m_bstrAuthor[4] = SysAllocString(_T("Stewart's Law of Retroaction"));
- m_bstrAuthor[5] = SysAllocString(_T("Last Law of Product Design"));
-
- m_nQID = 0;
-
- SetInitialSize(400,50);
-
- //----
- // Set the default values to the
- // current ambient properties.
- SetForeColor(AmbientForeColor());
- SetBackColor(AmbientBackColor());
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::~CQuoteCtrl - Destructor
- //
- CQuoteCtrl::~CQuoteCtrl()
- {
- for(int i = 0; i < MAXQUOTES;i++)
- {
- SysFreeString(m_bstrQuote[i]);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::OnDraw - Drawing function
- //
- void CQuoteCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
- {
-
- CFont* pOldFont;
-
- //---
- // Get stock properties - foreground & background colour & Font.
-
- CBrush bkBrush(TranslateColor(GetBackColor()));
- pdc->SetTextColor(TranslateColor(GetForeColor()));
- pdc->SetBkColor(TranslateColor(GetBackColor()));
- pOldFont = SelectStockFont(pdc);
- pdc->SetBkMode(TRANSPARENT);
-
-
- pdc->FillRect(rcBounds, &bkBrush);
- if(m_showAuthor)
- {
- CString s = m_bstrQuote[m_nQID];
- s += "\n ";
- s += m_bstrAuthor[m_nQID];
- pdc->DrawText(s,-1,rcBounds,DT_CENTER);
- }
- else
- pdc->DrawText(m_bstrQuote[m_nQID],-1,rcBounds,DT_CENTER|DT_VCENTER);
-
- //---
- // Clean up.
- pdc->SelectObject(pOldFont);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::DoPropExchange - Persistence support
- //
- void CQuoteCtrl::DoPropExchange(CPropExchange* pPX)
- {
- ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
-
- //---
- // Set the default values for our custom properties.
- PX_Bool(pPX, _T("ShowAuthor"), m_showAuthor,TRUE);
-
- COleControl::DoPropExchange(pPX);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::OnResetState - Reset control to default state
- //
- void CQuoteCtrl::OnResetState()
- {
- COleControl::OnResetState(); // Resets defaults found in DoPropExchange
-
- // TODO: Reset any other control state here.
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl::AboutBox - Display an "About" box to the user
- //
- void CQuoteCtrl::AboutBox()
- {
- CDialog dlgAbout(IDD_ABOUTBOX_QUOTE);
- dlgAbout.DoModal();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CQuoteCtrl message handlers
- //
- void CQuoteCtrl::OnShowAuthorChanged()
- {
- //---
- // The ShowAuthor property is persistent.
- SetModifiedFlag();
- InvalidateControl();
- }
- //---------------------------------------------------------------------------
- void CQuoteCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- m_nQID = rand() % MAXQUOTES;
- InvalidateControl();
-
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
-