⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pptooltip.cpp

📁 获取本机Outlook Express和Outlook2000/XP中通讯薄内容的示例源码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				sz.cx = max(sz.cx, ptCur.x - pt.x);
				m_nLengthLines.Add(ptCur.x - pt.x); //Adds the real length of the lines
				m_nHeightLines.Add(nLineHeight); //Adds the real height of the lines
			}
			ptCur.y += m_nHeightLines.GetAt(nLine) * nParam;
			nLine ++;
			percent.Add(0);
			bFirstOutput = TRUE;
			ptCur.x = pt.x;
			nLineHeight = nHeight;
	//		szLine.cy = nHeight;
			break;
		case CMD_TABULATION:
			//Tabulation
			if (!nParam)
				nParam = 1;
			nParam1 = (ptCur.x - pt.x) % (nWidth * 4);
			if (nParam1)
			{
				//aligns with tab
				ptCur.x += (nWidth * 4) - nParam1;
				nParam --;
			}
			ptCur.x += (nParam * nWidth * 4);
			break;
		}
	}
	
	//Gets real height of the tooltip
	sz.cy = ptCur.y - pt.y;

	pDC->SelectObject(pOldFont);
	font.DeleteObject();

	//Adds the percent's length to the line's length
	for (i = 0; i < percent.GetSize(); i++)
	{
		if (percent.GetAt(i))
			m_nLengthLines.SetAt(i, m_nLengthLines.GetAt(i) + ::MulDiv(percent.GetAt(i), sz.cx, 100));
	}

	return sz;
}

CString CPPToolTip::SearchBeginOfTag(CString & str, int & nIndex)
{
	CString sText = _T("");
	BOOL bTagFound = FALSE;
	
	for (nIndex; nIndex < str.GetLength(); nIndex ++)
	{
		switch (str.GetAt(nIndex))
		{
		case _T('\r'):
			break;
		case _T('<'):
			nIndex ++;
			if ((nIndex < str.GetLength()) && (str.GetAt(nIndex) != _T('<')))
			{
				if (!sText.IsEmpty())
					nIndex --;
				return sText;
			}
			sText += _T('<');
			break;
		case _T('\t'):
		case _T('\n'):
			if (!sText.IsEmpty())
				nIndex--;
			return sText;
		default:
			sText += str.GetAt(nIndex);
			break;
		}
	}
	return sText;
}

void CPPToolTip::SearchEndOfTag(CString & str, int & nIndex)
{
	for (nIndex; nIndex < str.GetLength(); nIndex ++)
	{
		switch (str.GetAt(nIndex))
		{
		case _T('>'):
		case _T('\n'):
		case _T('\t'):
			return;
		}
	}
}

CString CPPToolTip::GetNameOfTag(CString & str, int & nIndex)
{
	CString sText = _T("");
	
	for (nIndex; nIndex < str.GetLength(); nIndex ++)
	{
		switch (str.GetAt(nIndex))
		{
		case _T('\r'): //Pass character
			break;
		case _T('\t'): //It is a tab tag
		case _T('\n'): //It is a new line tag
			if (sText.IsEmpty())
			{
				sText += str.GetAt(nIndex);
//				nIndex ++;
				return sText;
			}
			break;
		case _T(' '):
			if (!sText.IsEmpty())
			{
				nIndex ++;
				return sText;
			}
			break;
		case _T('>'):
		case _T('='):
			return sText;
		default:
			sText += str.GetAt(nIndex);
			break;
		}
	}
	return sText;
}

CString CPPToolTip::GetPropertiesOfTag(CString & str, int & nIndex)
{
	CString sText = _T("");
	
	for (nIndex; nIndex < str.GetLength(); nIndex ++)
	{
		switch (str.GetAt(nIndex))
		{
		case _T('\r'): //Pass characters
		case _T('\t'):
		case _T('\n'):
			break;
		case _T(' '):
			if (!sText.IsEmpty())
			{
				nIndex ++;
				return sText;
			}
			break;
		case _T('>'):
		case _T('='):
			return sText;
		default:
			sText += str.GetAt(nIndex);
			break;
		}
	}
	return sText;
}

CString CPPToolTip::GetStringValue(CString & str, int & nIndex)
{
	CString sText = _T("");
	BOOL bValueFound = FALSE;
	
	for (nIndex; nIndex < str.GetLength(); nIndex ++)
	{
		switch (str.GetAt(nIndex))
		{
		case _T('\r'): //Pass character
		case _T('\t'): //It is a tab tag
		case _T('\n'): //It is a new line tag
			break;
		case _T(' '):
			if (!sText.IsEmpty())
			{
				nIndex ++;
				return sText;
			}
			break;
		case _T('>'):
			return sText;
		case _T('='):
			bValueFound = TRUE;
			break;
		default:
			if (!bValueFound)
				return sText;
			sText += str.GetAt(nIndex);
			break;
		}
	}
	return sText;

}

UINT CPPToolTip::GetUIntValue(CString & str, int & nIndex, UINT nDefValue)
{
	CString sText = GetStringValue(str, nIndex);
	if (!sText.IsEmpty())
		nDefValue = _tcstoul(sText, 0, 0);

	return nDefValue;
}

CSize CPPToolTip::DrawResource(CString sName, CDC * pDC, CPoint pt, int nMaxHeight, CSize szResource, BOOL bCalculate)
{
	CSize sz(0, 0);
	
	int nIndex = FindIdOfResource(sName);
	if (nIndex < 0)
		return sz;

	PPTOOLTIP_NAME_RES nr = m_arrNameRes.GetAt(nIndex);

	if (nr.nID == 0)
		return sz;

	switch (nr.nTypeRes)
	{
	case TYPE_RES_ICON:
		sz = DrawIcon(pDC, pt, nMaxHeight, nr.nID, szResource, bCalculate);
		break;
	case TYPE_RES_BITMAP:
		sz = DrawBitmap(pDC, pt, nMaxHeight, nr.nID, FALSE, nr.crMask, szResource, bCalculate);
		break;
	case TYPE_RES_MASK_BITMAP:
		sz = DrawBitmap(pDC, pt, nMaxHeight, nr.nID, TRUE, nr.crMask, szResource, bCalculate);
		break;
	}

	return sz;
}

CSize CPPToolTip::DrawBitmap(CDC * pDC, CPoint pt, int nMaxHeight, UINT nID, BOOL bUseMask, COLORREF crMask, CSize szBitmap, BOOL bCalculate)
{
	CSize sz(0, 0);
	HBITMAP	hBitmap = GetBitmapFromResources(nID);
	
	int		nRetValue;
	BITMAP	csBitmapSize;
	
	if (hBitmap == NULL)
		return sz;
	
	// Get bitmap size
	nRetValue = ::GetObject(hBitmap, sizeof(csBitmapSize), &csBitmapSize);
	if (nRetValue == 0)
		return sz;
	
	sz.cx = (DWORD)csBitmapSize.bmWidth;
	sz.cy = (DWORD)csBitmapSize.bmHeight;

	if (!szBitmap.cy)
		szBitmap.cy = sz.cy;

	if (!szBitmap.cx)
		szBitmap.cx = sz.cx;

	if (bCalculate)
		return szBitmap;
	
	HDC hSrcDC = ::CreateCompatibleDC(pDC->m_hDC);
	HDC hResDC = ::CreateCompatibleDC(pDC->m_hDC);
	
	HBITMAP hSrcBitmap = ::CreateCompatibleBitmap(pDC->m_hDC, szBitmap.cx, szBitmap.cy);
	HBITMAP hOldSrcBitmap = (HBITMAP)::SelectObject(hSrcDC, hSrcBitmap);
	HBITMAP hOldResBitmap = (HBITMAP)::SelectObject(hResDC, hBitmap);

	//Scales a bitmap if need
	if ((sz.cx != szBitmap.cx) || (sz.cy != szBitmap.cy))
		::StretchBlt(hSrcDC, 0, 0, szBitmap.cx, szBitmap.cy, hResDC, 0, 0, sz.cx, sz.cy, SRCCOPY);
	else
		::BitBlt(hSrcDC, 0, 0, szBitmap.cx, szBitmap.cy, hResDC, 0, 0, SRCCOPY);

	::SelectObject(hResDC, hOldResBitmap);
	::DeleteDC(hResDC);
	::DeleteObject(hOldResBitmap);
	::DeleteObject(hBitmap);

	pt.y += (nMaxHeight - szBitmap.cy);

	if (bUseMask)
	{
		//Draws a bitmap with mask
		::SelectObject(hSrcDC, hOldSrcBitmap);
		CImageList img;
		img.Create(szBitmap.cx, szBitmap.cy, ILC_COLOR32 | ILC_MASK, 1, 1);
		img.Add(CBitmap::FromHandle(hSrcBitmap), crMask);
		DrawIconFromImageList(pDC, pt, szBitmap, img, 0, FALSE);
	}
	else
	{
		//Draws a bitmap without mask
		pDC->BitBlt(pt.x, pt.y, szBitmap.cx, szBitmap.cy, CDC::FromHandle(hSrcDC), 0, 0, SRCCOPY);
		::SelectObject(hSrcDC, hOldSrcBitmap);
	}

	::DeleteDC(hSrcDC);
	::DeleteObject(hOldSrcBitmap);
	::DeleteObject(hSrcBitmap);

	return szBitmap;
}

CSize CPPToolTip::DrawIcon(CDC * pDC, CPoint pt, int nMaxHeight, UINT nID, CSize szIcon, BOOL bCalculate)
{
	CSize sz (0, 0);
	HICON hIcon = GetIconFromResources(nID, szIcon);
	if (hIcon != NULL)
	{
		sz = GetSizeIcon(hIcon);
		if (!bCalculate)
		{
			pt.y += (nMaxHeight - sz.cy);
			pDC->DrawState(pt, sz, hIcon, DSS_NORMAL, (CBrush*)NULL);
		}
	}
	
	if (hIcon)
		::DestroyIcon(hIcon);
	
	return sz;
}

CSize CPPToolTip::DrawIconFromImageList(CDC * pDC, CPoint pt, CSize sz, CImageList & img, int nIndex /* = 0 */, BOOL bCalculate /* = TRUE */)
{
	if (img.GetSafeHandle() == NULL)
		return CSize (0, 0);

	int nCount = img.GetImageCount();
	if (nIndex >= nCount)
		return CSize (0, 0);

	if (bCalculate)
		return sz;
	
	HICON hIcon = img.ExtractIcon(nIndex);
	pDC->DrawState(pt, sz, hIcon, DSS_NORMAL, (CBrush*)NULL);

	if (hIcon)
		DestroyIcon(hIcon);

	return sz;
}

void CPPToolTip::DrawHorzLine(CDC * pDC, int xStart, int xEnd, int y) const
{
	CPen pen(PS_SOLID, 1, pDC->GetTextColor());
	CPen * penOld = pDC->SelectObject(&pen);
	pDC->MoveTo(xStart, y);
	pDC->LineTo(xEnd, y);
	pDC->SelectObject(penOld);
	pen.DeleteObject();
}

void CPPToolTip::FillGradient (	CDC * pDC, CRect rect, 
								COLORREF colorStart, COLORREF colorFinish, 
								BOOL bHorz/* = TRUE*/)
{
    // this will make 2^6 = 64 fountain steps
    int nShift = 6;
    int nSteps = 1 << nShift;

    for (int i = 0; i < nSteps; i++)
    {
        // do a little alpha blending
        BYTE bR = (BYTE) ((GetRValue(colorStart) * (nSteps - i) +
                   GetRValue(colorFinish) * i) >> nShift);
        BYTE bG = (BYTE) ((GetGValue(colorStart) * (nSteps - i) +
                   GetGValue(colorFinish) * i) >> nShift);
        BYTE bB = (BYTE) ((GetBValue(colorStart) * (nSteps - i) +
                   GetBValue(colorFinish) * i) >> nShift);

		CBrush br (RGB(bR, bG, bB));

        // then paint with the resulting color
        CRect r2 = rect;
        if (!bHorz)
        {
            r2.top = rect.top + 
                ((i * rect.Height()) >> nShift);
            r2.bottom = rect.top + 
                (((i + 1) * rect.Height()) >> nShift);
            if (r2.Height() > 0)
                pDC->FillRect(r2, &br);
        }
        else
        {
            r2.left = rect.left + 
                ((i * rect.Width()) >> nShift);
            r2.right = rect.left + 
                (((i + 1) * rect.Width()) >> nShift);
            if (r2.Width() > 0)
                pDC->FillRect(r2, &br);
        }
    }
}

#ifdef PPTOOLTIP_USE_SHADE
void CPPToolTip::SetShade(CRect rect, UINT shadeID /* = 0 */, BYTE granularity /* = 8 */, 
						  BYTE coloring /* = 0 */, COLORREF color /* = 0 */)
{
	long	sXSize,sYSize,bytes,j,i,k,h;
	BYTE	*iDst ,*posDst;
	
	sYSize= rect.Height(); //rect.bottom-rect.top;
	sXSize= rect.Width(); //rect.right-rect.left ;

	m_dh.Create(max(1,sXSize /*-2*m_FocusRectMargin-1*/ ),1,8);	//create the horizontal focus bitmap
	m_dv.Create(1,max(1,sYSize /*-2*m_FocusRectMargin*/),8);	//create the vertical focus bitmap

	m_dNormal.Create(sXSize,sYSize,8);					//create the default bitmap

	COLORREF hicr = m_pToolInfo.crBegin; //GetSysColor(COLOR_BTNHIGHLIGHT);		//get the button base colors
	COLORREF midcr = m_pToolInfo.crMid;  //GetSysColor(COLOR_BTNFACE);
	COLORREF locr = m_pToolInfo.crEnd;   //GetSysColor(COLOR_BTNSHADOW);
	long r,g,b;											//build the shaded palette
	for(i=0;i<129;i++){
		r=((128-i)*GetRValue(locr)+i*GetRValue(midcr))/128;
		g=((128-i)*GetGValue(locr)+i*GetGValue(midcr))/128;
		b=((128-i)*GetBValue(locr)+i*GetBValue(midcr))/128;
		m_dNormal.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b);
		m_dh.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b);
		m_dv.SetPaletteIndex((BYTE)i,(BYTE)r,(BYTE)g,(BYTE)b);
	}
	for(i=1;i<129;i++){
		r=((128-i)*GetRValue(midcr)+i*GetRValue(hicr))/128;
		g=((128-i)*GetGValue(midcr)+i*GetGValue(hicr))/128;
		b=((128-i)*GetBValue(midcr)+i*GetBValue(hicr))/128;
		m_dNormal.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b);
		m_dh.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b);
		m_dv.SetPaletteIndex((BYTE)(i+127),(BYTE)r,(BYTE)g,(BYTE)b);
	}

	m_dNormal.BlendPalette(color,coloring);	//color the palette

	iDst=m_dh.GetBits();		//build the horiz. dotted focus bitmap
	j=(long)m_dh.GetWidth();
	for(i=0;i<j;i++){
//		iDst[i]=64+127*(i%2);	//soft
		iDst[i]=255*(i%2);		//hard
	}

	iDst=m_dv.GetBits();		//build the vert. dotted focus bitmap
	j=(long)m_dv.GetHeight();
	for(i=0;i<j;i++){
//		*iDst=64+127*(i%2);		//soft
		*iDst=255*(i%2);		//hard
		iDst+=4;
	}

	bytes = m_dNormal.GetLineWidth();
	iDst = m_dNormal.GetBits();
	posDst =iDst;
	long a,x,y,d,xs,idxmax,idxmin;

	int grainx2=RAND_MAX/(max(1,2*granularity));
	idxmax=255-granularity;
	idxmin=granularity;

	switch (shadeID)
	{
//----------------------------------------------------
	case PPTOOLTIP_EFFECT_METAL:
		m_dNormal.Clear();
		// create the strokes
		k=40;	//stroke granularity
		for(a=0;a<200;a++){
			x=rand()/(RAND_MAX/sXSize); //stroke postion
			y=rand()/(RAND_MAX/sYSize);	//stroke position
			xs=rand()/(RAND_MAX/min(sXSize,sYSize))/2; //stroke lenght
			d=rand()/(RAND_MAX/k);	//stroke color
			for(i=0;i<xs;i++){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -