/////////////////////////////////////////////////////////////////////
// 
// CXInfoTip::GetWindowRegion()
// 
// DESCRIPTION
//     
//		Retrieves the window region
//
// RETURNS
//
//		[BOOL]		- TRUE on success, FALSE on failure
//
// PARAMETERS
//
//		[pDC]		- Pointer to display device context
//		[hRegion]	- Filled with the calculated window region
//		[Size]		- Filled with the calculated window size
//					or NULL.
//     
/////////////////////////////////////////////////////////////////////
BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size /* = NULL */)
{
	CRect	rcWnd;
	POINT	ptLeader[3];
	CRgn	LeaderRegion;
	CRgn	CaptionRegion;
	CFont	*pSysFont;
	
	ASSERT(pDC != NULL);
	ASSERT(hRegion != NULL);

	// Calculate the are for the tip text
	pSysFont = (CFont *)pDC->SelectObject(m_pFont);
	pDC->DrawText(m_szText, &rcWnd, DT_CALCRECT);
	pDC->SelectObject(pSysFont);

	// Adjust for the rounded corners
	rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED);

	// Adjust for icon
	if (m_hIcon != NULL)
		rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN;
	if (rcWnd.Height() < m_IconSize.cy)
		rcWnd.bottom = rcWnd.top + m_IconSize.cy;

	// Calculate the leader triangle coordinates

	ptLeader[0].x	= rcWnd.Width() - CX_ROUNDED;
	ptLeader[0].y	= rcWnd.Height() - CY_ROUNDED;

	ptLeader[1].x	= ptLeader[0].x;
	ptLeader[1].y	= ptLeader[0].y + CY_LEADER;

	ptLeader[2].x	= ptLeader[0].x - CX_LEADER;
	ptLeader[2].y	= rcWnd.Height() - CY_ROUNDED;

	// Create the caption region
	CaptionRegion.CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED);
	// Create the leader region
	LeaderRegion.CreatePolygonRgn(ptLeader, 3, ALTERNATE);
	// Create window region
	*hRegion =  ::CreateRectRgn(0, 0, rcWnd.Width(), rcWnd.Height() + CY_LEADER);
	// Combine the regions
	CombineRgn(*hRegion, CaptionRegion.operator HRGN(), LeaderRegion.operator HRGN(), RGN_OR);

	// Set the window size
	if (Size != NULL)
	{
		Size->cx	= rcWnd.Width();
		Size->cy	= rcWnd.Height() + CY_LEADER;
	}

	return TRUE;
}
Exemplo n.º 2
0
//////////////////
// Message handler handles caption-related messages
//
BOOL CCaptionPainter::RelayEvent(MSG* pMsg) 
{
	switch (pMsg->message)
	{
		case WM_MOUSEMOVE:
			return OnMouseMoveMsg(pMsg->pt);

		case WM_LBUTTONUP:
			return OnLButtonUp(pMsg->lParam, pMsg->pt);

		case WM_NCPAINT:
			return OnNcPaint(HRGN(pMsg->wParam));
		
		case WM_NCACTIVATE:
			return OnNcActivate(pMsg->wParam);
		
		case WM_SETTEXT:
			return OnSetText((LPCTSTR)pMsg->lParam);
		
		case WM_SYSCOLORCHANGE:
		case WM_SETTINGCHANGE:
			Invalidate();
			//m_pParentDlg->SendMessage(m_nPaintMsg, 0, 0L);
			return FALSE;
	}
	return FALSE;
}
Exemplo n.º 3
0
void CDrawHelper::ClipToRects( void )
{
	SelectClipRgn( m_dcMemory, NULL );
	if ( m_ClipRegion )
	{
		DeleteObject( m_ClipRegion );
		m_ClipRegion = HRGN( 0 );
	}

	if ( m_ClipRects.Size() > 0 )
	{
		RECT rc = m_ClipRects[ 0 ];
		m_ClipRegion = CreateRectRgn( rc.left, rc.top, rc.right, rc.bottom );
		for ( int i = 1; i < m_ClipRects.Size(); i++ )
		{
			RECT add = m_ClipRects[ i ];

			HRGN addIn = CreateRectRgn( add.left, add.top, add.right, add.bottom );
			HRGN result = CreateRectRgn( 0, 0, 100, 100 );

			int success = CombineRgn( result, m_ClipRegion, addIn, RGN_AND );
			
			DeleteObject( m_ClipRegion );
			DeleteObject( addIn );

			m_ClipRegion = result;
		}
	}

	SelectClipRgn( m_dcMemory, m_ClipRegion );
}
Exemplo n.º 4
0
void CAnimateButton::PrepareBitmap(HBITMAP hBitmap)
{
	int nStates = 4;

	//取得图像所处区域及计算各状态按钮窗口区域
	m_arBmpRgn.SetSize(nStates);
	m_arBmpRgn.SetSize(nStates);

	CRect rcTmp;
	for(int i = 0; i < nStates; i ++)
	{
		m_arBmpRgn[i] = BitmapToRegion(hBitmap, nStates, i);
	}

	CBitmap* pBmpWhole = CBitmap::FromHandle(hBitmap);
	BITMAP bmp;
	pBmpWhole->GetBitmap(&bmp);

	m_aniBtnWidth = bmp.bmWidth / nStates;
	m_aniBtnHeight = bmp.bmHeight;

	m_pMemDC = new CDC;
	CDC* pDC = GetDC();
	m_pMemDC->CreateCompatibleDC(pDC);
	m_pMemDC->SelectObject(pBmpWhole);
	ReleaseDC(pDC);

 	CRgn RgnWnd;
 	RgnWnd.CreateRectRgn(0, 0, m_aniBtnWidth, m_aniBtnHeight);
 	SetWindowRgn(HRGN(RgnWnd), FALSE);
	//调整大小(这样在DrawItem里面才可能限定画的范围)
	SetWindowPos(NULL, 0, 0, m_aniBtnWidth, m_aniBtnHeight, SWP_NOMOVE);
}
// --------------------------------------------------------------------------
int CToolTipWnd::OnCreate( LPCREATESTRUCT lpCreateStruct ) 
{
   if ( CWnd::OnCreate( lpCreateStruct ) == -1 )
      return -1;
   
   CRect rectCl;
   GetClientRect( &rectCl );
   
   int x=0, y=0;
   CRect rectTemp;
   
   rectTemp = rectCl;
   rectTemp.left = rectTemp.left + 10;
   
   x = (int)( (float)( (float)rectTemp.Width() / 2.0 ) / 1.41421 );
   y = (int)( (float)( (float)rectTemp.Height() / 2.0 ) / 1.41421 );
   
   m_rectText.top = ( ( rectTemp.Height() / 2 ) - y );
   m_rectText.left = ( ( rectTemp.Width() / 2 ) - x ) + 10;
   m_rectText.right = ( ( rectTemp.Width() / 2 ) + x ) + 10;
   m_rectText.bottom = ( ( rectTemp.Height() / 2 ) + y );
   
   m_rgn.m_hObject = NULL;
   m_rgnTri.m_hObject = NULL;
   m_rgnComb.m_hObject = NULL;
   
   BOOL bRegRet = m_rgn.CreateEllipticRgn( rectCl.left+10,rectCl.top,rectCl.right,rectCl.bottom );
   
   CPoint ptTri[4];
   ptTri[0].x = rectCl.left;
   ptTri[0].y = ( rectCl.bottom / 2 ) - 10;
   
   ptTri[1].x = rectCl.left + 15;
   ptTri[1].y = ( rectCl.bottom / 2 ) - 5;
   
   ptTri[2].x = rectCl.left + 15;
   ptTri[2].y = ( rectCl.bottom / 2 ) + 5;
   
   ptTri[3].x = rectCl.left;
   ptTri[3].y = ( rectCl.bottom / 2 ) - 10;
   
   BOOL bRegTriRet = m_rgnTri.CreatePolygonRgn( ptTri, 3, ALTERNATE );
   
   m_rgnComb.CreateRectRgn( rectCl.left+10,rectCl.top,rectCl.right,rectCl.bottom );
   int iRetComb = m_rgnComb.CombineRgn( &m_rgnTri, &m_rgn, RGN_OR );
   
   if ( iRetComb == ERROR )
   {
      AfxMessageBox((LPCTSTR) "ERROR in Combining Region" );
      return -1;
   }
   
   int bRgnWnd = SetWindowRgn( m_rgnComb.operator HRGN( ), TRUE );	
   
   m_strTextFont.CreateFont( m_iFontHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, m_strFontName );
   
   return 0;
}
Exemplo n.º 6
0
void CAnimateButton::SetBtnText(LPCTSTR lpszString, AnibtnTextOpinion ato)
{
	m_strBtnText = lpszString;
	m_ato = ato;

// 		if(m_pLogfont)
// 			delete m_pLogfont;
//
// 		m_pLogfont = new LOGFONT;
// 		m_ato.pFont->GetLogFont(m_pLogfont);
// 		TRACE("m_ato: font-size: %d\n", m_pLogfont->lfHeight);
// 		
// 		if(m_pFontTxt)
// 			delete m_pFontTxt;
// 		m_pFontTxt = new CFont;
// 		m_pFontTxt->CreatePointFontIndirect(m_pLogfont);	//用错函数了
// 		m_ato.pFont = m_pFontTxt;

//字体 - 写到前面便于后面计算下方、右方文字框大小
	if(m_fontTxt.GetSafeHandle())
		m_fontTxt.DeleteObject();

	if(ato.pLf)
		m_fontTxt.CreateFontIndirect(ato.pLf);	
	else
	{
		LOGFONT lf;
		m_pMemDC->GetCurrentFont()->GetLogFont(&lf); 
		lf.lfCharSet = DEFAULT_CHARSET; 
		lf.lfHeight = 0; 
		lf.lfWidth = 0; 
		strcpy(lf.lfFaceName,"微软雅黑"); 
		
		m_fontTxt.CreateFontIndirect(&lf);
	}// if ato.pFont
	


	if(m_ato.nPosition == TXTPOS_IN)
		DrawBtnText(m_pMemDC);
	else
	{
		m_pMemDC->SelectObject(m_fontTxt);

	//通过当前字体来计算字在按钮外面时,按钮区域(图像与文字)、按钮大小
		CRgn RgnWnd, RgnText;
		RgnWnd.CreateRectRgn(0, 0, m_aniBtnWidth, m_aniBtnHeight);

		TEXTMETRIC tm;
		m_pMemDC->GetTextMetrics(&tm);

		BOOL bIsUnderline = FALSE;
		if(ato.pLf)
			bIsUnderline = ato.pLf->lfUnderline;

		int nLength = m_strBtnText.GetLength();
		int nBoxWidth  = (int)tm.tmAveCharWidth * nLength + 2,
			nBoxHeight = (int)tm.tmHeight + (bIsUnderline ? 10 : 1);
		
		int nLeft, nTop;
		switch(ato.nPosition)
		{
		case TXTPOS_DOWN:
			nLeft = (m_aniBtnWidth - nBoxWidth) / 2;
			nTop = m_aniBtnHeight + ato.nDistance;
			//调整按钮大小
			SetWindowPos(NULL, 0, 0, m_aniBtnWidth, m_aniBtnHeight + m_ato.nDistance 
				+ nBoxHeight, SWP_NOMOVE);
			break;

		case TXTPOS_RIGHT:
			nLeft = m_aniBtnWidth + m_ato.nDistance;
			nTop = (m_aniBtnHeight - nBoxHeight) / 2; 
			//调整按钮大小
			SetWindowPos(NULL, 0, 0, m_aniBtnWidth + m_ato.nDistance + nBoxWidth,
				m_aniBtnHeight, SWP_NOMOVE);
			break;
		}// switch
		
		m_rcTextBox.SetRect(nLeft, nTop, nLeft + nBoxWidth, nTop + nBoxHeight);
		RgnText.CreateRectRgnIndirect(&m_rcTextBox);
		RgnWnd.CombineRgn(&RgnWnd, &RgnText, RGN_OR);
		SetWindowRgn(HRGN(RgnWnd), FALSE);
	}
}
Exemplo n.º 7
0
BOOL CXInfoTip::GetWindowRegion(CDC* pDC, HRGN* hRegion, CSize *Size )
{
	CRect	rcWnd (0,0,0,0);
	POINT	ptLeader[3];
	CRgn	LeaderRegion;
	CRgn	CaptionRegion;
	CFont	*pSysFont;
	
	ASSERT(pDC != NULL);
	ASSERT(hRegion != NULL);

	
	pSysFont = (CFont *)pDC->SelectObject(&m_fntBold);

	CRect rcWnd1, rcWnd2;

	pDC->DrawText(m_strCaption + "\n", &rcWnd1, DT_CALCRECT);

	pDC->SelectObject (m_pFont);

	pDC->DrawText(m_szText, &rcWnd2, DT_CALCRECT);

	m_nCaptionHeight = rcWnd1.Height ();
	rcWnd.right = max (rcWnd1.Width (), rcWnd2.Width ());
	rcWnd.bottom = m_nCaptionHeight + rcWnd2.Height ();

	if (m_bShowDSA)
	{
		
		CRect rcDSA;
		pDC->DrawText (LS (L_DONTSHOWTHISWINDOWAGAIN), &rcDSA, DT_CALCRECT);
		m_yDSA = rcWnd.bottom + rcDSA.Height ();
		rcWnd.bottom += 10 + rcDSA.Height ();
		m_cxDSA = rcDSA.Width ();
		rcWnd.right = max (rcWnd.right, m_cxDSA + 30);
	}

	pDC->SelectObject(pSysFont);

	
	rcWnd.InflateRect(CX_ROUNDED, CY_ROUNDED);

	
	if (m_hIcon != NULL)
		rcWnd.right = rcWnd.right + m_IconSize.cx + CX_ICON_MARGIN;
	if (rcWnd.Height() < m_IconSize.cy)
		rcWnd.bottom = rcWnd.top + m_IconSize.cy;

	

	ptLeader[0].x	= rcWnd.Width() - CX_ROUNDED;
	ptLeader[0].y	= rcWnd.Height() - CY_ROUNDED;

	ptLeader[1].x	= ptLeader[0].x;
	ptLeader[1].y	= ptLeader[0].y + CY_LEADER;

	ptLeader[2].x	= ptLeader[0].x - CX_LEADER;
	ptLeader[2].y	= rcWnd.Height() - CY_ROUNDED;

	
	CaptionRegion.CreateRoundRectRgn(0, 0, rcWnd.Width(), rcWnd.Height(), CX_ROUNDED, CY_ROUNDED);
	
	LeaderRegion.CreatePolygonRgn(ptLeader, 3, ALTERNATE);
	
	*hRegion =  ::CreateRectRgn(0, 0, rcWnd.Width(), rcWnd.Height() + CY_LEADER);
	
	CombineRgn(*hRegion, CaptionRegion.operator HRGN(), LeaderRegion.operator HRGN(), RGN_OR);

	
	if (Size != NULL)
	{
		Size->cx	= rcWnd.Width();
		Size->cy	= rcWnd.Height() + CY_LEADER;
	}

	return TRUE;
}