home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / circ / circctl.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  92 lines

  1. // CircCtl.cpp : Implementation of CcircApp and DLL registration.
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. #include "stdafx.h"
  14. #include "circ.h"
  15. #include "CircCtl.h"
  16.  
  17. //const IID IID__CircEvents = {0x19A4FF37,0x9C7E,0x11CD,{0xAE,0xDC,0x00,0xA0,0xC9,0x03,0x48,0x37}};
  18. // {47536F96-F610-11cf-91F0-00A0C903977F}
  19. const GUID CLSID_CCircProps =
  20. { 0x47536f96, 0xf610, 0x11cf, { 0x91, 0xf0, 0x0, 0xa0, 0xc9, 0x3, 0x97, 0x7f } };
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23. //
  24.  
  25. HRESULT CCircCtl::OnDraw(ATL_DRAWINFO& di)
  26. {
  27.     USES_CONVERSION;
  28.     if (di.dwDrawAspect != DVASPECT_CONTENT)
  29.         return E_FAIL;
  30.  
  31.     HDC hdc = di.hdcDraw;
  32.     HDC hic = di.hicTargetDev;
  33.     if (hic == NULL)
  34.         hic = AtlCreateTargetDC(hdc, di.ptd);
  35.     RECT& rc = *(RECT*)di.prcBounds;
  36.  
  37.     HPEN hFore;
  38.     HBRUSH hBack;
  39.     COLORREF colBack,colFore;
  40.     OleTranslateColor(m_clrForeColor, m_hPalette, &colFore);
  41.     OleTranslateColor(m_clrBackColor, m_hPalette, &colBack);
  42.     hFore = CreatePen(PS_SOLID, 2, colFore);
  43.     hBack = CreateSolidBrush(colBack);
  44.     HGDIOBJ hOldBrush = SelectObject(hdc, hBack);
  45.     HGDIOBJ hOldPen = SelectObject(hdc, hFore);
  46.     Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom);
  47.     SetTextColor(hdc, RGB(255, 122, 144));
  48.     SetBkMode(hdc, TRANSPARENT);
  49.     TEXTMETRIC tm;
  50.     GetTextMetrics(hic, &tm);
  51.     LPTSTR szCaption = W2T(m_bstrCaption);
  52.     int cbCaption = lstrlen(szCaption);
  53.     int cHeight = (rc.top > rc.bottom) ? -tm.tmHeight/2 : tm.tmHeight/2;
  54.     HFONT hOldFont = NULL;
  55.     if (m_pFont)
  56.     {
  57.         CComPtr<IFont> pFont;
  58.         m_pFont->QueryInterface(IID_IFont, (void**)&pFont);
  59.         HFONT hfont;
  60.         pFont->get_hFont(&hfont);
  61.         hOldFont = (HFONT) SelectObject(hdc, hfont);
  62.     }
  63.     ExtTextOut(hdc ,
  64.               rc.left + (rc.right - rc.left)/2 - (tm.tmAveCharWidth*cbCaption)/2,
  65.               rc.top + (rc.bottom - rc.top)/2 - cHeight, 0, &rc,
  66.                szCaption, cbCaption, 0);
  67.     SelectObject(hdc, hOldPen);
  68.     SelectObject(hdc, hBack);
  69.     if (hOldFont)
  70.         SelectObject(hdc, hOldFont);
  71.     if (hic != hdc)
  72.         DeleteDC(hic);
  73.     DeleteObject(hFore);
  74.     DeleteObject(hBack);
  75.     return 0;
  76. }
  77.  
  78. STDMETHODIMP CCircCtl::InterfaceSupportsErrorInfo(REFIID riid)
  79. {
  80.     static const IID* arr[] =
  81.     {
  82.         &IID_ICircCtl,
  83.     };
  84.  
  85.     for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  86.     {
  87.         if (InlineIsEqualGUID(*arr[i],riid))
  88.             return S_OK;
  89.     }
  90.     return S_FALSE;
  91. }
  92.