void CListSelector::draw(CClientDC &dc, int orgX, int orgY, int width, int height)
{
	
	
	list<CSelectorItem>::iterator iter;
	
	int y0 = orgY;
	int y1 = orgY;
	
	int x0 = orgX;
	int x1 = orgX + width;

	
	//dc.Rectangle(orgX,orgY,orgX + width,orgY + height);
	
	int size=this->itemList.size();

	//dc.LineTo(x1,y1);
	int count=9;
	int start=4;
	int isNeedBreak=FALSE;

	int j=0;

	for(int i= -4 + focusIndex ; 
		i<= 4 + focusIndex;
		i++)
	{

		y0 = orgY + (j)*40;
		y1 = y0 + 40;
		CRect rect2(x0, y0+1, x1, y1);
		dc.Rectangle(&rect2);

		if(i==focusIndex)
		{
			CBrush *p=new CBrush();
			p->CreateSolidBrush(RGB(200,0,000));
			dc.FillRect(&rect2,p);
			dc.SetTextColor(RGB(255,255,255));
			delete p;
		}else{
			dc.SetTextColor(RGB(0,0,0));
		}

		int index = 0;
		if(i<0){
			index = (size*0X100000 + i) % size  ;
		}else{
			index=i % size ;
		}

		CString str(itemList[ index  ].getValue().c_str());		
		dc.DrawText(str,&rect2,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
		j++;
	
	}	
	
}
CSize CBCGPPopupDlg::GetOptimalTextSize (CString str)
{
	if (str.IsEmpty ())
	{
		return CSize (0, 0);
	}

	CRect rectScreen;

	CRect rectDlg;
	GetWindowRect (rectDlg);

	MONITORINFO mi;
	mi.cbSize = sizeof (MONITORINFO);
	if (GetMonitorInfo (MonitorFromPoint (rectDlg.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi))
	{
		rectScreen = mi.rcWork;
	}
	else
	{
		::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
	}

	CClientDC dc (this);

	CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
	ASSERT_VALID (pOldFont);

	int nStepY = globalData.GetTextHeight ();
	int nStepX = nStepY * 3;

	CRect rectText (0, 0, nStepX, nStepY);

	for (;;)
	{
		CRect rectTextSaved = rectText;

		int nHeight = dc.DrawText (str, rectText, DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX);
		int nWidth = rectText.Width ();

		rectText = rectTextSaved;

		if (nHeight <= rectText.Height () ||
			rectText.Width () > rectScreen.Width () ||
			rectText.Height () > rectScreen.Height ())
		{
			rectText.bottom = rectText.top + nHeight + 5;
			rectText.right = rectText.left + nWidth + 5;
			break;
		}

		rectText.right += nStepX;
		rectText.bottom += nStepY;
	}

	dc.SelectObject (pOldFont);
	return rectText.Size ();
}
Exemple #3
0
//////////////////
// text changed: resize window to fit
//
LRESULT CPopupText::OnSetText(WPARAM wp, LPARAM lp)
{
	UNREFERENCED_PARAMETER (wp);

	CClientDC dc = this;
	CFont* pOldFont = dc.SelectObject(&m_font);
	CRect rc;
	GetWindowRect(&rc);
	int x = (m_nStyle & JUSTIFYRIGHT) ? rc.right : rc.left;
	int y = rc.top;
	dc.DrawText(CString((LPCTSTR)lp), &rc, DT_CALCRECT);
	rc.InflateRect(m_szMargins);
	if (m_nStyle & JUSTIFYRIGHT)
		x -= rc.Width();
	SetWindowPos(NULL,x,y,rc.Width(),rc.Height(), SWP_NOZORDER|SWP_NOACTIVATE);
	dc.SelectObject (pOldFont);

	return Default();
}
Exemple #4
0
STDMETHODIMP CMyCom1::DrawOffset(unsigned long m_pDC, unsigned long m_pOffset, double m_Scale, unsigned long m_pGraphInfo, BOOL scale_flag, BOOL m_active_flag)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	// TODO: Add your implementation code here
	CClientDC * pDC = (CClientDC*) m_pDC;
	GraphInfo * pGraphInfo;

	//设置
	if ( m_pGraphInfo != NULL )
	{
		pGraphInfo = (GraphInfo*)m_pGraphInfo;
		m_GraphInfo.SetGraphInfo(*pGraphInfo);
	}
	else
		pGraphInfo = &m_GraphInfo;
	
		
	//计算偏移量
	if ( m_pOffset != NULL )
	{
		CPoint * offset = (CPoint *)m_pOffset;
		OffsetRgn((unsigned long)offset);
	}

	//设置激活标志
	isActive = m_active_flag;

	double scale = 0;
	m_scale_flag = scale_flag;
	if ( m_scale_flag )
		scale = m_Scale;
	else
		scale = 1;

	CFont * sysFont = pDC->SelectObject(&(pGraphInfo->font));
	CPen * pen = new CPen( pGraphInfo->normal_penStyle, pGraphInfo->normal_linewidth, pGraphInfo->normal_linecolor );	//构造画笔
	CPen * sysPen = pDC->SelectObject(pen);
	CBrush * normalBrush = new CBrush( pGraphInfo->normal_regioncolor );	//普通显示的画刷
	CBrush * activeBrush = new CBrush( pGraphInfo->active_regioncolor );	//激活后的画刷
	CBrush * blackBrush = new CBrush( BLACKBRUSHCOLOR );
	
	CRgn outRgn;
	outRgn.CreateRectRgn(0, 0, 5, 5);
	CRect smallRect;
	
	//判断是否激活了,如果激活,添加outRect
	if ( isActive )	//激活
	{
		if ( m_scale_flag )	//如果是在modelview区域
		{
			//选中后,在外边画一个方框
			outRgn.CombineRgn(&upRgn, &downRgn, RGN_OR);
			outRgn.GetRgnBox(&outRect);
			outRect.InflateRect(5, 5);
			
			pDC->MoveTo(outRect.left, outRect.top);
			pDC->LineTo(outRect.right, outRect.top);
			pDC->LineTo(outRect.right, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.top);

			//画出upRgn, downRgn, 和连线
			//pDC->FillRgn(&upRgn, normalBrush);
			CRect upRect;
			upRgn.GetRgnBox(upRect);
			pDC->Rectangle(upRect);
			pDC->MoveTo(upPoints[2]);
			pDC->LineTo(upPoints[5]);

			pDC->MoveTo(topPoint);
			pDC->LineTo(bottomPoint);
			pDC->MoveTo(leftPoint);
			pDC->LineTo(rightPoint);
			pDC->FillRgn(&downRgn, normalBrush);

			inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y);
			pDC->SetTextColor(pGraphInfo->textcolor);
			pDC->DrawText(m_name, inRect, TEXTOUTFOMAT);	//|DT_END_ELLIPSIS);
						
			//在矩形的角上,画四个小矩形,5*5象素
			smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
		}
		else	//如果是在comview区域
		{
			//选中后,在外边画一个方框
			downRgn.GetRgnBox(&outRect);
			outRect.InflateRect(5, 5);

			pDC->MoveTo(outRect.left, outRect.top);
			pDC->LineTo(outRect.right, outRect.top);
			pDC->LineTo(outRect.right, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.bottom);
			pDC->LineTo(outRect.left, outRect.top);

			//画出downRgn
			pDC->FillRgn(&downRgn, normalBrush);

			//在矩形的角上,画四个小矩形,5*5象素
			smallRect.SetRect(outRect.left, outRect.top, outRect.left+5, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.top, outRect.right, outRect.top+5);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.right-5, outRect.bottom-5, outRect.right, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
			smallRect.SetRect(outRect.left, outRect.bottom-5, outRect.left+5, outRect.bottom);
			pDC->FillRect(smallRect, blackBrush);
		}
	}
	else	//未激活
	{
		if ( m_scale_flag )	//如果是在modelview区域
		{
			//画出upRgn, downRgn, 和连线
			//pDC->FillRgn(&upRgn, normalBrush);
			CRect upRect;
			upRgn.GetRgnBox(upRect);
			pDC->Rectangle(upRect);
			pDC->MoveTo(upPoints[2]);
			pDC->LineTo(upPoints[5]);

			pDC->MoveTo(topPoint);
			pDC->LineTo(bottomPoint);
			pDC->MoveTo(leftPoint);
			pDC->LineTo(rightPoint);
			pDC->FillRgn(&downRgn, normalBrush);

			inRect.SetRect(upPoints[0].x, upPoints[0].y, upPoints[2].x, upPoints[2].y);
			pDC->SetTextColor(pGraphInfo->textcolor);
			pDC->DrawText(m_name, inRect, TEXTOUTFOMAT);	//|DT_END_ELLIPSIS);
		}
		else	//如果是在comview区域
		{
			//画出downRgn
			pDC->FillRgn(&downRgn, normalBrush);
		}
	}

		//释放
	pDC->SelectObject(sysFont);
	pDC->SelectObject(sysPen);
	
	delete(pen);
	delete(normalBrush);
	delete(activeBrush);
	delete(blackBrush);
	
	return S_OK;
}
Exemple #5
0
 int measureHeight(const tstring& s) {
   CRect r(clientRect);
   dc.DrawText(s.c_str(), s.length(), r, DT_CALCRECT | DT_WORDBREAK);
   return r.Height();
 }
//*******************************************************************************************
void CLoginBarToolTipCtrl::Track (CRect rect, const CString& strText)
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	if (m_rectLast == rect && m_strText == strText)
	{
		return;
	}

	ASSERT_VALID (m_pWndParent);

	m_rectLast = rect;
	m_strText = strText;

	CClientDC dc (this);

    //ASSERT_VALID(m_pFont);
	CFont* pPrevFont = m_pFont == NULL ?
		(CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) :
		dc.SelectObject (&theApp.m_font);
	ASSERT (pPrevFont != NULL);

	int nTextHeight = rect.Height () ;
	int nTextWidth = rect.Width ();
	if (m_strText.FindOneOf (_T("\n")) != -1)	// multi-line tooltip
	{
		const int nDefaultHeight = globalData.GetTextHeight () ;
		const int nDefaultWidth = 200;
		CRect rectText (0, 0, nDefaultWidth, nDefaultHeight);
 
		nTextHeight = dc.DrawText (m_strText, rectText, DT_LEFT | /*DT_WORDBREAK | */DT_CALCRECT | DT_NOPREFIX);
		nTextWidth = rectText.Width ();
		nTextHeight += 2 * m_nTextMargin ;
		nTextWidth += 2 * m_nTextMargin;
		nTextHeight += (GetLineCount(m_strText) - 1) * m_nTextMargin; //加上行间距
	}
	else
	{
		nTextWidth = dc.GetTextExtent (m_strText).cx + 2 * m_nTextMargin;
	}

	dc.SelectObject (pPrevFont);

	if (m_pWndParent->GetExStyle () & WS_EX_LAYOUTRTL)
	{
		rect.left = rect.right - nTextWidth;
	}
	else
	{
		rect.right = rect.left + nTextWidth;
	}
	rect.bottom = rect.top + nTextHeight;
	if (rect.Height () < m_rectLast.Height ())
	{
		rect.top = m_rectLast.top;
		rect.bottom = m_rectLast.bottom;
	}

	MONITORINFO mi;
	mi.cbSize = sizeof (MONITORINFO);

	CRect rectScreen;

	if (GetMonitorInfo (MonitorFromPoint (rect.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi))
	{
		rectScreen = mi.rcWork;
	}
	else
	{
		::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
	}

	if (rect.Width () > rectScreen.Width ())
	{
		rect.left = rectScreen.left;
		rect.right = rectScreen.right;
	}
	else if (rect.right > rectScreen.right)
	{
		rect.OffsetRect( rectScreen.right - rect.right, 0 );
		//rect.right = rectScreen.right;
		//rect.left = rect.right - nTextWidth;
	}
	else if (rect.left < rectScreen.left)
	{
		rect.OffsetRect( rectScreen.left - rect.left, 0 );
		//rect.left = rectScreen.left;
		//rect.right = rect.left + nTextWidth;
	}

	if (rect.Height () > rectScreen.Height ())
	{
		rect.top = rectScreen.top;
		rect.bottom = rectScreen.bottom;
	}
	else if (rect.bottom > rectScreen.bottom)
	{
		rect.OffsetRect(0,  rectScreen.bottom - rect.bottom);
		//rect.bottom = rectScreen.bottom;
		//rect.top = rect.bottom - nTextHeight;
	}
	else if (rect.top < rectScreen.top)
	{
		rect.OffsetRect(0, rectScreen.top - rect.top);
		//rect.top = rectScreen.top;
		//rect.bottom = rect.bottom + nTextHeight;
	}

	rect.bottom += 3;

	SetWindowPos (&wndTop, rect.left, rect.top, 
		rect.Width (), rect.Height (), SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  
    ShowWindow (SW_SHOWNOACTIVATE);
	Invalidate ();
	UpdateWindow ();

	SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_ARROW));
}