// XPanel.cpp : Implementation of CXPanel #include "stdafx.h" #include "ATLPanel.h" #include "XPanel.h" ///////////////////////////////////////////////////////////////////////////// // CXPanel /////////////////////////////////////////////////////////// added below STDMETHODIMP CXPanel::InitNew() { if (m_bInitialized) return E_UNEXPECTED; m_bstrCaption = "Distributed Objects"; m_clrBorderColor = 0x008800; m_clrShadowColor = 0x004400; m_clrHighlightColor = 0x00ff00; m_lBorderWidth = 20; m_bInitialized = true; return S_OK; } STDMETHODIMP CXPanel::Load(LPSTREAM pStm) { if (m_bInitialized) return E_UNEXPECTED; else { m_bInitialized = true; return IPersistStreamInitImpl::Load(pStm); } } // HRESULT CXPanel::OnDraw(ATL_DRAWINFO& di) { USES_CONVERSION; RECT& rcBounds = *(RECT*)di.prcBounds; HRESULT hr; hr= GetAmbientBackColor(m_clrBackColor); COLORREF clrFace; OleTranslateColor( m_clrBackColor, NULL, &clrFace); COLORREF clrHilite; OleTranslateColor( m_clrHighlightColor, NULL, &clrHilite); COLORREF clrShadow; OleTranslateColor( m_clrShadowColor, NULL, &clrShadow); COLORREF clrBorder; OleTranslateColor( m_clrBorderColor, NULL, &clrBorder); // color face HBRUSH hBrush, hOldBrush; hBrush = ::CreateSolidBrush( clrFace ); hOldBrush = (HBRUSH)::SelectObject(di.hdcDraw,hBrush); Rectangle( di.hdcDraw, rcBounds.left, rcBounds.top, rcBounds.right, rcBounds.bottom ); // draw border hBrush = CreateSolidBrush( clrBorder ); ::SelectObject(di.hdcDraw,hBrush); HPEN hBorderPen, hOldPen; hBorderPen = ::CreatePen( PS_SOLID, 2 , clrBorder ); hOldPen = (HPEN)::SelectObject(di.hdcDraw,hBorderPen); Rectangle( di.hdcDraw, rcBounds.left, rcBounds.top, rcBounds.right, rcBounds.top + m_lBorderWidth + 3 ); Rectangle( di.hdcDraw, rcBounds.left, rcBounds.top, rcBounds.left + m_lBorderWidth + 3, rcBounds.bottom ); Rectangle( di.hdcDraw, rcBounds.right - m_lBorderWidth - 2, rcBounds.top, rcBounds.right, rcBounds.bottom ); Rectangle( di.hdcDraw, rcBounds.left, rcBounds.bottom - m_lBorderWidth - 2, rcBounds.right, rcBounds.bottom ); // ::SelectObject(di.hdcDraw,hOldBrush); ::SelectObject(di.hdcDraw,hOldPen); HPEN hHilitePen, hShadowPen; hHilitePen = ::CreatePen( PS_SOLID, 2 , clrHilite ); hShadowPen = ::CreatePen( PS_SOLID, 2 , clrShadow ); // draw highlighted area hOldPen = (HPEN)::SelectObject(di.hdcDraw,hHilitePen); MoveToEx( di.hdcDraw, rcBounds.left + 2 , rcBounds.top + 2, NULL ); LineTo( di.hdcDraw, rcBounds.right - 2 , rcBounds.top + 2 ); MoveToEx( di.hdcDraw, rcBounds.left + 2 , rcBounds.top + 2, NULL ); LineTo( di.hdcDraw, rcBounds.left + 2 , rcBounds.bottom - 2 ); // // draw shadow ::SelectObject(di.hdcDraw,hShadowPen); MoveToEx( di.hdcDraw, rcBounds.right - 2 , rcBounds.bottom - 2, NULL ); LineTo( di.hdcDraw, rcBounds.right - 2 , rcBounds.top + 2 ); MoveToEx( di.hdcDraw, rcBounds.right - 2 , rcBounds.bottom - 2, NULL ); LineTo( di.hdcDraw, rcBounds.left + 2 , rcBounds.bottom - 2 ); MoveToEx( di.hdcDraw, rcBounds.left + m_lBorderWidth + 4 , rcBounds.top + m_lBorderWidth + 4, NULL ); LineTo(di.hdcDraw, rcBounds.right - m_lBorderWidth - 4 , rcBounds.top + m_lBorderWidth + 4 ); MoveToEx( di.hdcDraw, rcBounds.left + m_lBorderWidth + 4 , rcBounds.top + m_lBorderWidth + 4, NULL ); LineTo( di.hdcDraw, rcBounds.left + m_lBorderWidth + 4 , rcBounds.bottom - m_lBorderWidth - 4 ); // ::SelectObject(di.hdcDraw,hHilitePen); MoveToEx( di.hdcDraw, rcBounds.right - m_lBorderWidth - 4 , rcBounds.bottom - m_lBorderWidth - 4, NULL ); LineTo( di.hdcDraw, rcBounds.right - m_lBorderWidth - 4 , rcBounds.top + m_lBorderWidth + 4 ); MoveToEx( di.hdcDraw, rcBounds.right - m_lBorderWidth - 4 , rcBounds.bottom - m_lBorderWidth - 4, NULL ); LineTo( di.hdcDraw, rcBounds.left + m_lBorderWidth + 4, rcBounds.bottom - m_lBorderWidth - 4 ); ::SelectObject(di.hdcDraw,hOldPen); OLE_COLOR ocAmbientFC; COLORREF clrTxt; GetAmbientForeColor( ocAmbientFC ); OleTranslateColor(ocAmbientFC, NULL, &clrTxt ); // draw text SetTextColor( di.hdcDraw, clrTxt ); SetBkColor( di.hdcDraw , clrFace ); DrawText( di.hdcDraw, OLE2T(m_bstrCaption.m_str), -1, &rcBounds, DT_CENTER | DT_VCENTER | DT_SINGLELINE ); return S_OK; } /////////////////////////////////////////////////////////// added above // STDMETHODIMP CXPanel::get_BorderWidth(long *pVal) { *pVal = m_lBorderWidth; // added return S_OK; } STDMETHODIMP CXPanel::put_BorderWidth(long newVal) { ///////////////////////////////////////////////////////// added m_lBorderWidth = newVal; FireViewChange(); SetDirty(true); SendOnDataChange(); ///////////////////////////////////////////////////////// added return S_OK; } STDMETHODIMP CXPanel::get_BorderColor(OLE_COLOR *pVal) { *pVal = m_clrBorderColor; // added return S_OK; } STDMETHODIMP CXPanel::put_BorderColor(OLE_COLOR newVal) { ///////////////////////////////////////////////////////// added m_clrBorderColor = newVal; FireViewChange(); SetDirty(true); SendOnDataChange(); ///////////////////////////////////////////////////////// added return S_OK; } STDMETHODIMP CXPanel::get_ShadowColor(OLE_COLOR *pVal) { *pVal = m_clrShadowColor; // added return S_OK; } STDMETHODIMP CXPanel::put_ShadowColor(OLE_COLOR newVal) { ///////////////////////////////////////////////////////// added m_clrShadowColor = newVal; FireViewChange(); SetDirty(true); SendOnDataChange(); ///////////////////////////////////////////////////////// added return S_OK; } STDMETHODIMP CXPanel::get_HighlightColor(OLE_COLOR *pVal) { *pVal = m_clrHighlightColor; // added return S_OK; } STDMETHODIMP CXPanel::put_HighlightColor(OLE_COLOR newVal) { ///////////////////////////////////////////////////////// added m_clrHighlightColor = newVal; FireViewChange(); SetDirty(true); SendOnDataChange(); ///////////////////////////////////////////////////////// added return S_OK; }