Esempio n. 1
0
void CDrawHeader::DoDraw(HDC hdc)
{
	int iOldMode = ::SetBkMode(hdc, TRANSPARENT);
	COLORREF clrFore;
	OleTranslateColor(m_pAlmSum->m_clrHeaderFore, 0, &clrFore);
	COLORREF clrOldColor = ::SetTextColor(hdc, clrFore);
	
	HFONT hFont;
	HFONT hOldFont;
	if (m_pAlmSum->m_spHeaderFont != NULL)
	{
		CComPtr<IFont> pFont;
		m_pAlmSum->m_spHeaderFont->QueryInterface(IID_IFont, (void**)&pFont);
		pFont->get_hFont(&hFont);
	}
	else
	{
		hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
	}
	hOldFont = (HFONT)::SelectObject(hdc, hFont);

	//Ìî³äÇ°¾°
	COLORREF clrFill;
	OleTranslateColor(m_pAlmSum->m_clrHeaderBack, 0, &clrFill);
	HBRUSH brush = ::CreateSolidBrush(clrFill);
	::FillRect(hdc, &m_rect, brush);
	::DeleteObject((HGDIOBJ)brush);

	CSimpleValArray<CColumn *>& apColumns = m_pAlmSum->m_apColumns;

	int nFirstColumn = m_pAlmSum->GetFirstVisibleColumn();
	int nCount = apColumns.GetSize();
	RECT rect = m_rect;
	
	BOOL bBreak = FALSE;
	for (int i = nFirstColumn; i < nCount; i++)
	{
		rect.right = rect.left + apColumns[i]->m_nWidth;
		if (rect.right > m_rect.right)
		{
			rect.right = m_rect.right;
			bBreak = TRUE;
		}
			
		apColumns[i]->Draw(hdc, rect, m_nColumnCatpture == i);
		
		if (bBreak)
			break;
		rect.left = rect.right;
	}

	rect.left = rect.right;
	rect.right = m_rect.right;
	DrawEdge(hdc, &rect, BDR_RAISEDINNER, BF_RECT);

	::SetBkMode(hdc, iOldMode);
	::SetTextColor(hdc, clrOldColor);
	::SelectObject(hdc, hOldFont);
}
Esempio n. 2
0
HRESULT CDrawTxt::DoDraw(HDC hdcDest)
{
	USES_CONVERSION;

	// 如果字体宽度小于1,无法绘制
	if (m_dFontWidth > 0 && ROUND(m_dFontWidth) == 0)
		return S_OK;

	//设置背景模式
	int iBkMode = m_bsBackStyle == BackStyleTransparent ? TRANSPARENT : OPAQUE;
	int iOldBkMode = SetBkMode(hdcDest, iBkMode);
//	UINT uOldTextAlignMode = SetTextAlign(hdcDest, m_nTextAlign);
	COLORREF colFore;
	OleTranslateColor(m_clrForeColor, NULL, &colFore);
	COLORREF colOldTextColor = SetTextColor(hdcDest, colFore);

	COLORREF colBack;
	OleTranslateColor(m_clrBackColor, NULL, &colBack);
	COLORREF clrOldBackColor = SetBkColor(hdcDest, colBack);

	HFONT hFont = CreateTextFont(ROUND(m_dFontHeight), ROUND(m_dFontWidth));
	HFONT hOldFont = (HFONT)SelectObject(hdcDest, hFont);

	LPTSTR szCaption = W2T(m_bstrCaption);
	int cbCaption = lstrlen(szCaption);
	RECT rcCaption;
	RECTFToRECT(&m_rcPosition, &rcCaption);
	UINT uFormat = DT_NOPREFIX/* | DT_EXTERNALLEADING*/;
	// 考虑到斜体时可能文本超过外围矩形
	if (m_bAutoSize)
		uFormat |= DT_NOCLIP;
	else if (m_bWordWrap)
		uFormat |= DT_WORDBREAK;
	if (m_nTextAlign == TextAlignCenter)
		uFormat |= DT_CENTER;
	else if (m_nTextAlign == TextAlignRight)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	DrawText(hdcDest, szCaption, cbCaption, &rcCaption, uFormat);

	SelectObject(hdcDest, hOldFont);
	DeleteObject(hFont);

	SetBkMode(hdcDest, iOldBkMode);
//	SetTextAlign(hdcDest, uOldTextAlignMode);
	SetTextColor(hdcDest, colOldTextColor);
	SetBkColor(hdcDest, clrOldBackColor);

	return S_OK;

}
Esempio n. 3
0
void CElementPropPage::UpdateControls(IDMGraphCtrl* pGraphCtrl)
{
    ATLASSERT(pGraphCtrl);
    HRESULT hr;
    CComPtr<IDMGraphElement> spElement;
    hr = GetCurrentElement(pGraphCtrl, &spElement);
    BOOL bEnabled = spElement != NULL;
    const UINT idCtrls[] = { IDC_LINE_COLOR, IDC_POINT_COLOR, IDC_LINE_WIDTH, IDC_POINT_WIDTH, IDC_COMBO_TYPE, IDC_COMBO_SYMBOL,
                             IDC_CHECK_VISIBLE, IDC_CHECK_SOLID, IDC_EDIT_NAME, IDC_DELBUTTON,
                             IDC_TXT_E1, IDC_TXT_E2, IDC_TXT_E3, IDC_TXT_E4, IDC_TXT_E5, IDC_TXT_E6, IDC_TXT_E7, IDC_TXT_E8, 0
                           };
    int i;

    for(i=0; idCtrls[i]; ::EnableWindow(GetDlgItem(idCtrls[i++]), bEnabled));

    if(bEnabled == FALSE)
    {
        return;
    }

    OLE_COLOR color;
    COLORREF col;
    hr = spElement->get_LineColor(&color);
    hr = OleTranslateColor(color, NULL, &col);
    m_btnLineColPicker.SetColor(col);
    hr = spElement->get_PointColor(&color);
    hr = OleTranslateColor(color, NULL, &col);
    m_btnPointColPicker.SetColor(col);
    long width;
    hr = spElement->get_LineWidth(&width);
    SetDlgItemInt(IDC_LINE_WIDTH,width);
    hr = spElement->get_PointSize(&width);
    SetDlgItemInt(IDC_POINT_WIDTH,width);
    LineType type;
    hr = spElement->get_Linetype(&type);
    SendDlgItemMessage(IDC_COMBO_TYPE, CB_SETCURSEL, type);
    SymbolType symbol;
    hr = spElement->get_PointSymbol(&symbol);
    SendDlgItemMessage(IDC_COMBO_SYMBOL, CB_SETCURSEL, symbol);
    VARIANT_BOOL visible;
    hr = spElement->get_Show(&visible);
    CheckDlgButton(IDC_CHECK_VISIBLE, visible ? BST_CHECKED : BST_UNCHECKED);
    VARIANT_BOOL solid;
    hr = spElement->get_SolidPoint(&solid);
    CheckDlgButton(IDC_CHECK_SOLID, visible ? BST_CHECKED : BST_UNCHECKED);
    CComBSTR ids;
    hr = spElement->get_Name(&ids);
    ::SetDlgItemTextW(m_hWnd, IDC_EDIT_NAME, ids);
}
HRESULT CPolyCtl::OnDraw(ATL_DRAWINFO& di)
{
   RECT& rc = *(RECT*)di.prcBounds;
   HDC hdc  = di.hdcDraw;

   COLORREF    colFore;
   HBRUSH      hOldBrush, hBrush;
   HPEN        hOldPen, hPen;

   // Translate m_colFore into a COLORREF type
   OleTranslateColor(m_clrFillColor, NULL, &colFore);

   // Create and select the colors to draw the circle
   hPen = (HPEN)GetStockObject(BLACK_PEN);
   hOldPen = (HPEN)SelectObject(hdc, hPen);
   hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
   hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);

   Ellipse(hdc, rc.left, rc.top, rc.right, rc.bottom);

   // Create and select the brush that will be used to fill the polygon
   hBrush    = CreateSolidBrush(colFore);
   SelectObject(hdc, hBrush);

   CalcPoints(rc);
   Polygon(hdc, &m_arrPoint[0], m_nSides);

   // Select back the old pen and brush and delete the brush we created
   SelectObject(hdc, hOldPen);
   SelectObject(hdc, hOldBrush);
   DeleteObject(hBrush);

   return S_OK;
}
Esempio n. 5
0
void CCDInfo::DrawOffScreen(HDC hdc, RECT rc)
{
	HBITMAP hbmMem, hbmOld;
	HDC     hdcMem;
	RECT    rcDP;

	// First make sure we have the coordinates in device units and we
	// are offset from 0,0

	LPtoDP(hdc, (LPPOINT)&rc, 2);
	rcDP = rc;
	OffsetRect(&rc, -rc.left, -rc.top);

	// Create a DC to draw into
	hdcMem = CreateCompatibleDC(hdc);

	// Create a bitmap big enough for our drawing
	hbmMem = CreateCompatibleBitmap(hdc, rc.right-rc.left, rc.bottom-rc.top);

	// Select the bitmap into our new DC
	hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem);

	// If we can get the ambient background color from the container then we
	// will use it.

	CComVariant var;
	if (SUCCEEDED(m_spAmbientDispatch.GetProperty(DISPID_AMBIENT_BACKCOLOR,
			&var)))
	{
		LOGBRUSH    logbrush;
		COLORREF    col;
		logbrush.lbStyle = BS_SOLID;
		OleTranslateColor(var.lVal, m_hPalette, &col);
		logbrush.lbColor = col;
		HBRUSH hBrush = CreateBrushIndirect(&logbrush);
		FillRect(hdcMem, &rc, hBrush);
		DeleteObject(hBrush);
	}

	RECT rcEllipse = rc;
	ReduceRect(&rcEllipse);
	DrawCD(hdcMem, rcEllipse);

	// Now we can blt our offscreen bitmap onto the passed DC.
	BitBlt(hdc,
		   rcDP.left, rcDP.top,
		   rcDP.right-rcDP.left, rcDP.bottom-rcDP.top,
		   hdcMem,
		   0, 0,
		   SRCCOPY);

	// Clean up our stuff
	SelectObject(hdcMem, hbmOld);
   DeleteObject(hbmMem);
   DeleteDC(hdcMem);
}
Esempio n. 6
0
void CGrid::DoDraw(HDC hdcDest, RECT& rect)
{
    if (::IsRectEmpty(&rect))
        return;

    if (m_bShowHorizontal)
    {
        COLORREF clrHorizontalColor;
        OleTranslateColor(m_clrHorizontalColor, NULL, &clrHorizontalColor);

        HPEN hHorPen = ::CreatePen(m_enumHorizontalStyle, m_nWidth, clrHorizontalColor);
        HGDIOBJ hOldPen = ::SelectObject(hdcDest, hHorPen);

        float fDY = float(rect.top - rect.bottom) / (m_lNumberOfVerticalLines);
        for (int i = 1; i < m_lNumberOfVerticalLines + 1; i++)
        {
            ::MoveToEx(hdcDest, rect.left, ROUND(rect.bottom + i * fDY), NULL);
            ::LineTo(hdcDest, rect.right, ROUND(rect.bottom + i * fDY));
        }

        ::SelectObject(hdcDest, hOldPen);
        ::DeleteObject(hHorPen);
    }

    if (m_bShowVertical)
    {
        COLORREF clrVerticalColor;
        OleTranslateColor(m_clrVerticalColor, NULL, &clrVerticalColor);

        HPEN hVerPen = ::CreatePen(m_enumVerticalStyle, m_nWidth, clrVerticalColor);
        HGDIOBJ hOldPen = ::SelectObject(hdcDest, hVerPen);

        float fDX = float(rect.right - rect.left) / m_lNumberOfHorizontalLines;
        for (int i = 1; i < m_lNumberOfHorizontalLines + 1; i++)
        {
            ::MoveToEx(hdcDest, ROUND(rect.left + i * fDX), rect.top, NULL);
            ::LineTo(hdcDest, ROUND(rect.left + i * fDX), rect.bottom);
        }

        ::SelectObject(hdcDest, hOldPen);
        ::DeleteObject(hVerPen);
    }
}
Esempio n. 7
0
QColor OLEColorToQColor(uint col)
{
#if defined(Q_OS_WINCE)
    return QColor(GetBValue(col),GetGValue(col),GetRValue(col));
#else
    COLORREF cref;
    OleTranslateColor(col, QColormap::hPal(), &cref);
    return QColor(GetRValue(cref),GetGValue(cref),GetBValue(cref));
#endif
}
Esempio n. 8
0
// put_TextColor ------------------------------------------------------------
STDMETHODIMP CICodeList::put_TextColor( OLE_COLOR crColor )
{
   ASSERT( m_pCtrl != NULL && ::IsWindow( m_pCtrl->m_hWnd ) );
   if( !::IsWindow( m_pCtrl->GetSafeHwnd() ) )
      return E_POINTER;

   COLORREF cr = {0};
   HRESULT hResult = OleTranslateColor( crColor, NULL, &cr );

   if( SUCCEEDED( hResult ) )
      m_pCtrl->SendMessage( LVM_SETTEXTCOLOR, 0, (LPARAM)cr );

   return hResult;
}
Esempio n. 9
0
STDMETHODIMP CGraphAnnotation::put_LabelColor(OLE_COLOR newVal)
{
	HRESULT hr;
	COLORREF col;
	hr = OleTranslateColor(newVal, NULL, &col);

	if(m_Color == col)
		return S_FALSE;

	m_Color = col;

	if(m_pCtrl)
		m_pCtrl->Refresh(FALSE);
	return S_OK;
}
Esempio n. 10
0
void CColorPicker::DrawListItem(LPDRAWITEMSTRUCT di)
{
	HDC hdc = di->hDC;
	RECT &rcItem = di->rcItem;

	FillRect(hdc, &di->rcItem, GetSysColorBrush(COLOR_BTNFACE)); 

	RECT rc;
	int i = (int)(di->itemData);
	
	::CopyRect(&rc, &rcItem);	
	rc.right = rc.left + rc.bottom - rc.top;
	::InflateRect(&rc, -1, -1);
	
	COLORREF clr;
	OleTranslateColor(m_SystemColors[i].clr, 0, &clr);
	
	COLORREF clrBack = ::GetBkColor(hdc);
	COLORREF clrText = ::GetTextColor(hdc);

	HBRUSH hBr = ::CreateSolidBrush(clr);
	HBRUSH hOldBrush = (HBRUSH)::SelectObject(hdc, hBr);

	FillRect(hdc, &rc, hBr); 
	DrawEdge(hdc, &rc, BDR_SUNKENINNER, BF_RECT);

	::SelectObject(hdc, hOldBrush);
	::DeleteObject(hBr);
	
	::CopyRect(&rc, &rcItem);
	rc.left += rc.bottom - rc.top;
	if(di->itemState & ODS_SELECTED)
	{
		::SetBkColor(hdc, ::GetSysColor(COLOR_HIGHLIGHT));
		::SetTextColor(hdc, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
	}
	else
	{
		::SetBkColor(hdc, ::GetSysColor(COLOR_BTNFACE));
		::SetTextColor(hdc, ::GetSysColor(COLOR_HIGHLIGHT));
	}
	
	::ExtTextOut(hdc, rc.left, rc.top, ETO_OPAQUE | ETO_CLIPPED, &rc,
			m_SystemColors[i].text, lstrlen(m_SystemColors[i].text), 0);
	
	::SetBkColor(hdc, clrBack);
	::SetTextColor(hdc, clrText);
}	
Esempio n. 11
0
STDMETHODIMP CGraphElement::put_PointColor(OLE_COLOR newVal)
{

    HRESULT hr;
    COLORREF col;
    hr = OleTranslateColor(newVal, nullptr, &col);

    if(m_PointColor == col)
    {
        return S_FALSE;
    }

    m_PointColor = col;

    if(m_pCtrl)
    {
        m_pCtrl->Refresh(TRUE);
    }
    return S_OK;
}
Esempio n. 12
0
void CTimeAxis::DoDraw(HDC hdcDest)
{
	USES_CONVERSION;

	if (m_bShowAxis != VARIANT_TRUE || ::IsRectEmpty(&m_rect))
		return;

	COLORREF clrTitle;
	OleTranslateColor(m_clrTitle, NULL, &clrTitle);
	COLORREF clrAxis;
	OleTranslateColor(m_clrAxis, NULL, &clrAxis);

	COLORREF clrOldText = ::SetTextColor(hdcDest, clrTitle);

	HFONT hFont;
	HFONT hOldFont;
	if (m_spTitleFont != NULL)
	{
		CComPtr<IFont> pFont;
		m_spTitleFont->QueryInterface(IID_IFont, (void**)&pFont);
		pFont->get_hFont(&hFont);
	}
	else
	{
		hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
	}
	hOldFont = (HFONT)::SelectObject(hdcDest, hFont);

	RECT rect = m_rect;
	rect.bottom -= 4;
	rect.top = rect.bottom - GetFontHeight(m_spTitleFont) - 2;

	if (m_bShowTitle == VARIANT_TRUE)
		::DrawText(hdcDest, W2T(m_bstrTitle), -1, &rect, DT_SINGLELINE | DT_CENTER| DT_VCENTER);

	::SetTextColor(hdcDest, clrAxis);

	if (m_spTickFont != NULL)
	{
		CComPtr<IFont> pFont;
		m_spTickFont->QueryInterface(IID_IFont, (void**)&pFont);
		pFont->get_hFont(&hFont);
	}
	else
	{
		hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
	}
	::SelectObject(hdcDest, hFont);

	HPEN hPen = ::CreatePen(PS_SOLID, 1, clrAxis);
	HGDIOBJ hOldPen = ::SelectObject(hdcDest, hPen);

	::MoveToEx(hdcDest, m_rect.left, m_rect.top, NULL);
	::LineTo(hdcDest, m_rect.right, m_rect.top);

	BOOL bInvert = (m_pChart->m_enumScrollDirection == ScrollDirectionRight);
	int nX = !bInvert ? m_rect.right : m_rect.left;
	
	int nY = m_rect.top;
	float fDX = float(m_rect.right - m_rect.left ) / (m_lNumTicks - 1);

	rect.top = m_rect.top + 8;
	rect.bottom = m_rect.bottom;
	
	int nHalfTickWidth = 32;

	for (int i = 0; i < m_lNumTicks; i++)
	{
		int n = i;
		if (bInvert)
			n = -i;

		int xPos = ROUND(nX - fDX * n);
		if ((!bInvert && xPos < m_rect.left) || (bInvert && xPos > m_rect.right))
			break;

		COleDateTime dtWhen(m_dMaxVal - i * (m_dMaxVal - m_dMinVal) / (m_lNumTicks - 1));
		CString strText = dtWhen.Format(OLE2T(m_bstrDisplayFormat));

		int iIndex = strText.Find(_T("\\换行"));
		if (iIndex != -1)
		{
			CString str = strText.Mid(iIndex + 5);

			if (i == 0)
			{
				SIZE sz;
				::GetTextExtentPoint32(hdcDest, str, str.GetLength(), &sz);	
				nHalfTickWidth = sz.cx / 2;
			}

			str += '\n';

			CString strT = strText.Left(iIndex);
			str += strT;

			if (i == 0)
			{
				SIZE sz;
				::GetTextExtentPoint32(hdcDest, strT, strT.GetLength(), &sz);
				if (nHalfTickWidth < sz.cx / 2)
					nHalfTickWidth = sz.cx / 2;
			}

			strText = str;
		}
		else
		{
			if (i == 0)
			{
				SIZE sz;
				::GetTextExtentPoint32(hdcDest, strText, strText.GetLength(), &sz);	
				nHalfTickWidth = sz.cx / 2;
			}
		}

		nHalfTickWidth += 2;
		rect.left = xPos - nHalfTickWidth;
		rect.right = xPos + nHalfTickWidth;
		
		UINT nFormat = DT_CENTER;

		if (rect.left < m_rect.left)
		{
			OffsetRect(&rect, m_rect.left - 2 - rect.left, 0);
			nFormat = DT_LEFT;
		}
		else if (rect.right > m_rect.right)
		{
			OffsetRect(&rect, m_rect.right + 2 - rect.right , 0);
			nFormat = DT_RIGHT;
		}

		::IntersectRect(&rect, &rect, &m_rect);
		::DrawText(hdcDest, strText, strText.GetLength(), &rect, nFormat);

		::MoveToEx(hdcDest, xPos, nY, NULL);
		::LineTo(hdcDest, xPos, nY + 6);
	}
	
	::SelectObject(hdcDest, hOldPen);
	::DeleteObject(hPen);

	::SetTextColor(hdcDest, clrOldText);
	::SelectObject(hdcDest, hOldFont);
}
Esempio n. 13
0
void CValueAxis::DoDraw(HDC hdcDest)
{
	USES_CONVERSION;

	if (!m_bShowAxis)
		return;

	double dViewMinValue = fabs(m_dViewMinVal - DBL_MAX) < 1E-6 ? m_dMinVal : m_dViewMinVal;
	double dViewMaxValue = fabs(m_dViewMaxVal + DBL_MAX) < 1E-6 ? m_dMaxVal : m_dViewMaxVal;

	if (::IsRectEmpty(&m_rect))
		return;

	COLORREF clrAxis;
	OleTranslateColor(m_clrAxis, NULL, &clrAxis);
	COLORREF clrOldText = ::SetTextColor(hdcDest, clrAxis);
	
	HFONT hFont;
	HFONT hOldFont;
	if (m_spTickFont != NULL)
	{
		CComPtr<IFont> pFont;
		m_spTickFont->QueryInterface(IID_IFont, (void**)&pFont);
		pFont->get_hFont(&hFont);
	}
	else
	{
		hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
	}
	hOldFont = (HFONT)::SelectObject(hdcDest, hFont);

	TEXTMETRIC tm;
	::GetTextMetrics(hdcDest, &tm);
	int nHalfTickHeight = (tm.tmHeight + tm.tmExternalLeading) / 2;
		
	HPEN hPen = ::CreatePen(PS_SOLID, 1, clrAxis);
	HGDIOBJ hOldPen = ::SelectObject(hdcDest, hPen);

	TCHAR szBuf[16];

	::MoveToEx(hdcDest, m_rect.right, m_rect.top, NULL);
	::LineTo(hdcDest, m_rect.right, m_rect.bottom);

	int nX = m_rect.right;
	int nY;
	float fDY = float(m_rect.bottom - m_rect.top) / (m_lNumTicks - 1);
	
	double dDY = (dViewMaxValue - dViewMinValue) / (m_lNumTicks - 1); 
	
	RECT rect;
	rect.left = m_rect.left;
	rect.right = m_rect.right - 8;

	for (int i = 0; i < m_lNumTicks; i++)
	{
		nY = ROUND(m_rect.bottom - fDY * i);
		rect.top = nY - nHalfTickHeight;
		rect.bottom = nY + nHalfTickHeight;

		::MoveToEx(hdcDest, nX, nY, NULL);
		::LineTo(hdcDest, max(nX - (i % 2 == 0 ? 7 : 5), m_rect.left), nY);

		double dY = dViewMinValue + i * dDY;

		sprintf(szBuf, OLE2T(m_bstrDisplayFormat), dY);
		::DrawText(hdcDest, szBuf, strlen(szBuf), &rect, DT_SINGLELINE | DT_RIGHT | DT_VCENTER);
	}

	if (m_bShowTitle)
	{
		COLORREF clrTitle;
		OleTranslateColor(m_clrTitle, NULL, &clrTitle);
		::SetTextColor(hdcDest, clrTitle);
		
		if (m_spTitleFont != NULL)
		{
			CComPtr<IFont> pFont;
			m_spTitleFont->QueryInterface(IID_IFont, (void**)&pFont);
			pFont->get_hFont(&hFont);
		}
		else
		{
			hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
		}
		::SelectObject(hdcDest, hFont);

		rect = m_rect;
		rect.bottom = rect.top - nHalfTickHeight;
		rect.top = m_pChart->m_rect.top;
				
		::DrawText(hdcDest, W2T(m_bstrTitle), -1, &rect, DT_SINGLELINE | DT_RIGHT| DT_BOTTOM);
	}
	
	::SelectObject(hdcDest, hOldPen);
	::DeleteObject(hPen);

	::SetTextColor(hdcDest, clrOldText);
	::SelectObject(hdcDest, hOldFont);
}
Esempio n. 14
0
STDMETHODIMP CBar::Attach(OLE_HANDLE hWndParentIn)
{
	if (m_bStartedToolBars)
		return NOERROR;

	HWND hWndParent = (HWND)hWndParentIn;
	if (!IsWindow(hWndParent))
		hWndParent = GetDockWindow();
	else
	{
		m_fInPlaceActive = TRUE;
		m_bUserMode = 1;
		m_hWndDock = m_hWndParent = hWndParent;
		// Create an ActiveBar Window
		CRect rc;
		GetClientRect(hWndParent, &rc);
		m_Size = rc.Size();
		if (NULL == m_hWnd)
			CreateInPlaceWindow(0, 0, FALSE);
		else
			SetWindowPos(m_hWnd, NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_SHOWWINDOW|SWP_NOACTIVATE);
	}

	if (!hWndParent)
		return E_FAIL;

	if (AmbientUserMode() && IsWindow(hWndParent))
		DragAcceptFiles(hWndParent, TRUE);

	if (GetAmbientProperty(DISPID_AMBIENT_BACKCOLOR, VT_I4, &m_ocAmbientBackColor))
		OleTranslateColor(m_ocAmbientBackColor, NULL, &m_crAmbientBackColor);

	void* pPrevBar;
	HWND hWndMdi;
	TCHAR szBuffer[_MAX_PATH];
	DWORD dwResult = GetModuleFileName(NULL, szBuffer, 255);

	if (dwResult > 0 && lstrlen(szBuffer) > 12 && 0 == lstrcmpi(szBuffer + lstrlen(szBuffer) - 12, _T("iexplore.exe")))
		m_bIE = TRUE;

	const int nLen = 15;
	TCHAR szClassName[nLen];
	if (AmbientUserMode())
	{
		hWndMdi = ::GetWindow(hWndParent, GW_CHILD);
		if (hWndMdi)
		{
			MAKE_TCHARPTR_FROMWIDE(szWindowClass, m_bstrWindowClass);
			GetClassName(hWndMdi, szClassName, nLen);
			if (0 == lstrcmpi(szClassName, szWindowClass))
			{
				//
				// Hook into the MDIClient Form
				//

				m_eAppType = eMDIForm;
				m_hWndMDIClient = hWndMdi;

				IOleControlSite* pControlSite;
				HRESULT hResult = m_pClientSite->QueryInterface(IID_IOleControlSite, (void**)&pControlSite);
				if (SUCCEEDED(hResult))
				{
					LPDISPATCH pDispatch;
					hResult = pControlSite->GetExtendedControl(&pDispatch);
					pControlSite->Release();
					if (SUCCEEDED(hResult))
					{
						VARIANT vWidth;
						vWidth.vt = VT_I4;
						vWidth.lVal = 0;
						hResult = PropertyPut(pDispatch, L"Width", vWidth);
						pDispatch->Release();
					}
				}

				if (AmbientUserMode())
					DragAcceptFiles(m_hWndMDIClient, TRUE);

				if (GetGlobals().m_pmapBar->Lookup((LPVOID)m_hWndMDIClient, pPrevBar))
				{
					TRACE2(1, _T("Window handle already entered Bar: %X hWnd: %X\n"), 
						   this, 
						   m_hWndMDIClient);
					return NOERROR;
				}
				GetGlobals().m_pmapBar->SetAt((LPVOID)m_hWndMDIClient,(LPVOID)this);

				m_pMDIClientProc = (WNDPROC)GetWindowLong(m_hWndMDIClient, GWL_WNDPROC);
				SetWindowLong(m_hWndMDIClient, GWL_WNDPROC, (LONG)MDIClientWindowProc);
				
				CacheSmButtonSize();
				
				CRect rcWin;
				::GetWindowRect(m_hWndMDIClient, &rcWin);
				m_nNewCustomizedFloatBandCounter = 0;
				m_ptNewCustomizedFloatBandPos.x = rcWin.left + 16;
				m_ptNewCustomizedFloatBandPos.y = rcWin.top + 16;
			}
		}
	}
	else
	{
		//
		// If we are in design mode check if we are on an MDI Form or not
		//

		GetClassName(hWndParent, szClassName, nLen);
		if (0 == lstrcmpi(szClassName, _T("ThunderMDIForm")))
			m_eAppType = eMDIForm;
	}

	if (eMDIForm == m_eAppType)
	{
		//
		// Check if two activebars are present
		//

		if (GetGlobals().m_pmapBar->Lookup((LPVOID)hWndParent, pPrevBar))
		{
			TRACE2(1, _T("Window handle already entered Bar: %X hWnd: %X\n"), 
				   this, 
				   hWndParent);
			return NOERROR;
		}

		//
		// Set the map and subclass the window procedure 
		//

		GetGlobals().m_pmapBar->SetAt((LPVOID)hWndParent,(LPVOID)this);
		TRACE2(1, _T("Window handle entered Bar: %X hWnd: %X\n"), 
			   this, 
			   hWndParent);

		m_pMainProc = (WNDPROC)GetWindowLong(hWndParent, GWL_WNDPROC);
		SetWindowLong (hWndParent, GWL_WNDPROC, (LONG)FrameWindowProc);
	}
	else
	{
		if (VARIANT_TRUE == bpV1.m_vbAlignToForm)
		{
			m_eAppType = eSDIForm;

			//
			// Check if two activebars are present
			//

			if (GetGlobals().m_pmapBar->Lookup((LPVOID)hWndParent, pPrevBar))
			{
				TRACE2(1, _T("Window handle already entered Bar: %X hWnd: %X\n"), 
					   this, 
					   hWndParent);
				return NOERROR;
			}

			//
			// Set the map and subclass the window procedure 
			//

			GetGlobals().m_pmapBar->SetAt((LPVOID)hWndParent,(LPVOID)this);
			TRACE2(1, _T("Window handle entered Bar: %X hWnd: %X\n"), 
				   this, 
				   hWndParent);

			m_pMainProc = (WNDPROC)GetWindowLong(hWndParent, GWL_WNDPROC);
			SetWindowLong (hWndParent, GWL_WNDPROC, (LONG)FormWindowProc);

			CRect rcClient;
			if (GetClientRect(hWndParent, &rcClient) && m_pInPlaceSite)
				m_pInPlaceSite->OnPosRectChange(&rcClient);
		}
		else
			m_eAppType = eClientArea;

		CRect rcWin;
		GetWindowRect(hWndParent, &rcWin);
		m_nNewCustomizedFloatBandCounter = 0;
		m_ptNewCustomizedFloatBandPos.x = rcWin.left + 64;
		m_ptNewCustomizedFloatBandPos.y = rcWin.top + 64;
	}
	LPVOID pTmp;
	if (!GetGlobals().m_pmapAccelator->Lookup((LPVOID)hWndParent, (void*&)pTmp))
		GetGlobals().m_pmapAccelator->SetAt(hWndParent, (LPVOID)this);
	m_bStartedToolBars = TRUE;
	return NOERROR;
}