void CBCGPPlannerViewMulti::OnPaint (CDC* pDC, const CRect& rectClient)
{
	ASSERT_VALID (pDC);

	OnDrawClient (pDC, m_rectApps);

	OnDrawAppointmentsDuration (pDC);

	if (m_nHeaderAllDayHeight != 0)
	{
		CRect rtHeader (m_rectApps);
		rtHeader.top    -= m_nHeaderAllDayHeight;
		rtHeader.bottom  = rtHeader.top + m_nHeaderAllDayHeight;

		OnDrawHeaderAllDay (pDC, rtHeader);

		CRgn rgn;
		rgn.CreateRectRgn (rtHeader.left, rtHeader.top, rtHeader.right, rtHeader.bottom);

		pDC->SelectClipRgn (&rgn);

		OnDrawAppointments (pDC, rtHeader);

		pDC->SelectClipRgn (NULL);
	}

	{
		CRgn rgn;
		rgn.CreateRectRgn (m_rectApps.left, m_rectApps.top, m_rectApps.right, m_rectApps.bottom);

		pDC->SelectClipRgn (&rgn);
		
		OnDrawAppointments (pDC, m_rectApps);

		pDC->SelectClipRgn (NULL);
	}

	if (!m_rectTimeBar.IsRectEmpty ())
	{
		OnDrawTimeBar (pDC, m_rectTimeBar, IsCurrentTimeVisible ());
	}

	OnDrawUpDownIcons (pDC);

	if (m_nHeaderHeight != 0)
	{
		CRect rtHeader (rectClient);
		rtHeader.left   = m_rectApps.left;
		rtHeader.bottom = rtHeader.top + m_nHeaderHeight / 2;

		OnDrawHeader (pDC, rtHeader);

		rtHeader.top = rtHeader.bottom;
		rtHeader.bottom = rtHeader.top + m_nHeaderHeight / 2;

		OnDrawHeaderResource (pDC, rtHeader);
	}

	InitToolTipInfo ();
}
Exemple #2
0
void CScoreView::SetupRgn(CDC *pDC,				//窗体的DC指针
						  CBitmap &cBitmap,		//含有窗体形状的位图对象
						  // CSkinImage skinImage,
						  COLORREF TransColor)	//透明色
{

	CDC memDC;
	//创建与传入DC兼容的临时DC
	memDC.CreateCompatibleDC(pDC);

	CBitmap *pOldMemBmp=NULL;
	//将位图选入临时DC
	pOldMemBmp=memDC.SelectObject(&cBitmap);

	CRgn wndRgn;
	//创建总的窗体区域,初始region为0
	wndRgn.CreateRectRgn(0,0,0,0);


	BITMAP bit;   
	cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽     

	int y;
	for(y=0;y<=bit.bmHeight  ;y++)
	{
		CRgn rgnTemp; //保存临时region

		int iX = 0;
		do
		{
			//跳过透明色找到下一个非透明色的点.
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) == TransColor)
				iX++;

			//记住这个起始点
			int iLeftX = iX;

			//寻找下个透明色的点
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) != TransColor)
				++iX;

			//创建一个包含起点与重点间高为1像素的临时“region”
			rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);

			//合并到主"region".
			wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);

			//删除临时"region",否则下次创建时和出错
			rgnTemp.DeleteObject();
		}while(iX <bit.bmWidth );
		iX = 0;
	}
	if(pOldMemBmp)
		memDC.SelectObject(pOldMemBmp);
	//HRGN wndRgn=skinImage.CreateImageRegion(RGB(255,0,255));
	CWnd * pWnd = pDC->GetWindow();
	pWnd->SetWindowRgn(wndRgn,TRUE);    
	pWnd->SetForegroundWindow();    
}
Exemple #3
0
void CScoreView::SetupRgn(CDC *pDC,CSkinImage bImage,COLORREF TransColor)
{
	//bImage.GetWidth()/5;
	tagImageLoadInfo ImageIDB;
	bImage.GetLoadInfo(ImageIDB);
	CBitmap cBitmap;
	cBitmap.LoadBitmap(ImageIDB.uResourceID);//这个BITMAP是5倍长的,所以会有问题死机。
	CDC memDC;
	//创建与传入DC兼容的临时DC
	memDC.CreateCompatibleDC(pDC);

	CBitmap *pOldMemBmp=NULL;
	//将位图选入临时DC
	pOldMemBmp=memDC.SelectObject(&cBitmap);

	CRgn wndRgn;
	//创建总的窗体区域,初始region为0
	wndRgn.CreateRectRgn(0,0,0,0);


	BITMAP bit;   
	cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽     

	int y;
	for(y=0;y<=bit.bmHeight  ;y++)
	{
		CRgn rgnTemp; //保存临时region

		int iX = 0;
		do
		{
			//跳过透明色找到下一个非透明色的点.
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) == TransColor)
				iX++;

			//记住这个起始点
			int iLeftX = iX;

			//寻找下个透明色的点
			while (iX <= bit.bmWidth  && memDC.GetPixel(iX, y) != TransColor)
				++iX;

			//创建一个包含起点与重点间高为1像素的临时“region”
			rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);

			//合并到主"region".
			wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);

			//删除临时"region",否则下次创建时和出错
			rgnTemp.DeleteObject();
		}while(iX <bit.bmWidth );
		iX = 0;
	}
	if(pOldMemBmp)
		memDC.SelectObject(pOldMemBmp);
	CWnd * pWnd = pDC->GetWindow();
	pWnd->SetWindowRgn(wndRgn,TRUE);
	pWnd->SetForegroundWindow();   
} 
Exemple #4
0
void CFlashingWnd::SetUpRegion(const CRect& cRect, int type)
{
	///////////////////////////////////////////////////
	//
	// Under construction ...!
	// (Just to get an idea how it works now and what previously developers had in mind)
	//
	// There is currently a pixel fault in defined region and recorded region
	// Right pixel column and Top pixel row are not recorded.  E.g. Area 200x200 becone 199x199
	// Don't know if this is only with manual setup region the case or with other screen copies as well
	// 
	//
	//    +--- wndRgn --------------------+
	//    |  +--- rgnTemp--------------+  |
    //
	// wndRgn defines a new rect with the size of the requested area but something bigger because the border lines are included either.
	// rgnTemp relative points to the area with the size of the area off interrest but inside wndRgn
	// rgnTemp2 ??
	// rgnTemp3 ??
	//
	///////////////////////////////////////////////////
	CRgn wndRgn;	
	CRgn rgnTemp;

	m_cRect = cRect;
	// TRACE( _T("## CFlashingWnd::SetUpRegion / m_cRect before / L=%d R=%d T=%d B=%d / W=%d H=%d\n"), m_cRect.left , m_cRect.right , m_cRect.top , m_cRect.bottom, m_cRect.Width(), m_cRect.Height() );

	// Type=0 stands for ... cProgramOpts.m_bAutoPan == false
	if (type == 0) {

		CRgn rgnTemp2;
		CRgn rgnTemp3;
		// ToDo: Check if all +1 are applied correctly. Parameters in function below are not checked.
        // Check if we have forgotten to apply a few or don't we need them (the +1's) at all.?
		wndRgn.CreateRectRgn(   0         , 0         , m_cRect.Width() + DOUBLETHICKNESS , m_cRect.Height() + DOUBLETHICKNESS  );
		rgnTemp.CreateRectRgn(  THICKNESS , THICKNESS , m_cRect.Width() + THICKNESS + 1   , m_cRect.Height() + THICKNESS + 1    );
		rgnTemp2.CreateRectRgn( 0         , SIDELEN2  , m_cRect.Width() + DOUBLETHICKNESS , m_cRect.Height() - SIDELEN + 1      );
		rgnTemp3.CreateRectRgn( SIDELEN2  , 0         , m_cRect.Width() - SIDELEN + 1     , m_cRect.Height() + DOUBLETHICKNESS  );

		wndRgn.CombineRgn(&wndRgn,&rgnTemp,RGN_DIFF);
		wndRgn.CombineRgn(&wndRgn,&rgnTemp2,RGN_DIFF);
		wndRgn.CombineRgn(&wndRgn,&rgnTemp3,RGN_DIFF);

		wndRgn.OffsetRgn( m_cRect.left - THICKNESS   , m_cRect.top - THICKNESS );
	} else {
		
		wndRgn.CreateRectRgn(  0             , 0             , m_cRect.Width() + DOUBLESMALLTHICKNESS , m_cRect.Height() + DOUBLESMALLTHICKNESS);
		rgnTemp.CreateRectRgn( SMALLTHICKNESS, SMALLTHICKNESS, m_cRect.Width() + SMALLTHICKNESS + 1   , m_cRect.Height() + SMALLTHICKNESS + 1);

		wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_DIFF);

		wndRgn.OffsetRgn(m_cRect.left - SMALLTHICKNESS, m_cRect.top - SMALLTHICKNESS);
	}

	SetWindowRgn(wndRgn, TRUE);
}
HRGN CSkinWin::GetRegion(int w, int h)
{
    CWnd *pWnd = CWnd::FromHandle(m_hWnd);
    CRect wr;
    pWnd->GetWindowRect(wr);
	//SKIN_SHANG 右边框
	//wr.left+=m_BorderRightWidth;
    
    CRgn rgn;
    if ( m_bTrans )
    {
        CDC *pDC = pWnd->GetDC();
        CDC memDC;
        CMyBitmap bmp;
        CBitmap *obmp;
        memDC.CreateCompatibleDC(pDC);
        bmp.CreateCompatibleBitmap( pDC, w, m_TitleHeight );
        obmp = memDC.SelectObject(&bmp);
        /*
        memDC.FillSolidRect( 0, 0, w, h, 0 );
        DrawFrame( &memDC, 0, 0, w, h, 0 );
        */
        DrawTitle( &memDC, m_BorderLeftWidth , 0, 
                   wr.Width() - m_BorderRightWidth - m_BorderLeftWidth + 1, 0 );
        DrawLeft( &memDC, 0, 0, m_bmpLeft.Height(), 0 );
		//SKIN_SHANG 右边框
        DrawRight( &memDC, wr.Width() - m_BorderRightWidth , 0, m_bmpRight.Height(), 0 );
        
        memDC.SelectObject(obmp);

		//wyw
		memDC.DeleteDC();

        pWnd->ReleaseDC( pDC );

        rgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
        HRGN hrgn = bmp.CreateRgnFromFile( m_colTrans );
        CRgn newrgn;
        newrgn.CreateRectRgn( 0, m_TitleHeight, wr.Width(), wr.Height() );
        newrgn.CombineRgn( &rgn, CRgn::FromHandle(hrgn), RGN_XOR  );

		//wyw
		bmp.DeleteObject();
		DeleteObject(hrgn);
		rgn.DeleteObject();
        
        return (HRGN)newrgn.Detach();
    }
    else
        rgn.CreateRectRgn( 0, 0, wr.Width(), wr.Height() );
        
    
    return (HRGN)rgn.Detach();
}
Exemple #6
0
void CBmpButton::SetWndRng()
{
	if (NULL == m_pBmpUncheckedNormal) return;

	CRect rcDlgRect;
	GetWindowRect(rcDlgRect);

	BITMAP BmpInfo;
	m_pBmpUncheckedNormal->GetBitmap(&BmpInfo);

	MoveWindow(rcDlgRect.left, rcDlgRect.top, BmpInfo.bmWidth, BmpInfo.bmHeight);

	const int iBitWidth = BmpInfo.bmBitsPixel / 8;
	
	if(iBitWidth == 4)
	{
		//有alpha通道,则裁窗口形状

		CRgn rgn;
		rgn.CreateRectRgn(0, 0, BmpInfo.bmWidth, BmpInfo.bmHeight);

		int iBitSize = BmpInfo.bmWidth * BmpInfo.bmHeight * iBitWidth;
		BYTE *pBits = new BYTE[iBitSize];

		m_pBmpUncheckedNormal->GetBitmapBits(iBitSize, pBits);

		for (int y = 0; y < BmpInfo.bmHeight; y++)
		{
			int iRow = y * BmpInfo.bmWidth;

			for (int x = 0; x < BmpInfo.bmWidth; x++)
			{
				int iPos = (iRow + x) * iBitWidth;

				if (pBits[iPos + 3] == 0)//检测alpha是否为透明
				{
					CRgn rgnCut;
					rgnCut.CreateRectRgn(x, y, x+1, y+1);

					rgn.CombineRgn(&rgn, &rgnCut, RGN_XOR);
				}
			}
		}
		
		SetWindowRgn(rgn, FALSE);

		delete []pBits;
	}
}
Exemple #7
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);
}
Exemple #8
0
void CSmcView::OnDraw(CDC* pDC)
{
    CSmcDoc* pDoc = GetDocument();
    CRect rect;
    GetClientRect(&rect);

    CRgn rgn;
    rgn.CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
    pDC->SelectClipRgn(&rgn);

    int ScrollIndex = GetScrollPos(SB_VERT);

    POSITION pos = m_strList.FindIndex(ScrollIndex+m_nPageSize);
    ASSERT(pos);
    rect.top = rect.bottom-pDoc->m_nYsize;
    int i = 0;

    pDC->SetBkMode(OPAQUE);
    CFont* pOldFont = pDC->SelectObject(&pDoc->m_fntText);

    while ( pos && i++ <= m_nPageSize) {
        CString str = m_strList.GetPrev(pos);

        if ( pDC->RectVisible(&rect) )
            DrawWithANSI(pDC, rect, &str, m_nPageSize - i);

        rect.top -= pDoc->m_nYsize;
        rect.bottom -= pDoc->m_nYsize;
    }
    pDC->SelectObject(pOldFont);
}
Exemple #9
0
void GPDraw3DFrame( CDC* pDC, CRect& rcDayFrame, LPCRECT pRcClip)
{
	CBrush brush1, brush2;
	brush1.CreateSolidBrush( RGB(149,149,149));
	brush2.CreateSolidBrush( RGB(255,255,255));
	
	if (pRcClip)
	{
		pDC->ExcludeClipRect(pRcClip);
	}
	

	pDC->FrameRect(rcDayFrame, &brush1);
	pDC->SelectObject(&brush2);
	rcDayFrame.InflateRect(1,1,1,1);
	pDC->FrameRect(rcDayFrame, &brush2);
	rcDayFrame.DeflateRect(2,2,2,2);
	pDC->FrameRect(rcDayFrame, &brush2);


	if (pRcClip)
	{
		CRgn rgn;	
		rgn.CreateRectRgn(pRcClip->left, pRcClip->top, pRcClip->right, pRcClip->bottom);
		pDC->SelectClipRgn(&rgn, RGN_OR);
	}
}
void CResizableLayout::EnumAndClipChildWindow(HWND hWnd, CDC* pDC)
{
	// obtain window position
	CRect rect;
	::GetWindowRect(hWnd, &rect);
	GetResizableWnd()->ScreenToClient(&rect);
	pDC->DPtoLP(&rect);

	// use window region if any
	CRgn rgn;
	rgn.CreateRectRgn(0,0,0,0);
	if (COMPLEXREGION == ::GetWindowRgn(hWnd, rgn))
	{
		rgn.OffsetRgn(rect.TopLeft());
	}
	else
	{
		rgn.SetRectRgn(&rect);
	}

	// go clipping?
	if (LikesClipping(hWnd))
		pDC->SelectClipRgn(&rgn, RGN_DIFF);
	else
		pDC->SelectClipRgn(&rgn, RGN_OR);
}
Exemple #11
0
BOOL CSkinBtn::OnEraseBkgnd(CDC* pDC)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if(m_bRePain == FALSE)
	{
		if(!m_bDCStored)
		{
    		CRect  rect;
			GetClientRect(&rect);

			m_memDC.CreateCompatibleDC (pDC);
			CBitmap	btScreen;
			btScreen.CreateCompatibleBitmap (pDC,rect.Width(),rect.Height());
			m_memDC.SelectObject (&btScreen);

			m_memDC.BitBlt (0,0,rect.Width(),rect.Height(),pDC,0,0,SRCCOPY);

			m_bDCStored=true;

			CRgn rgn;
			rgn.CreateRectRgn (0, 0, rect.Width(), rect.Height());
			SetWindowRgn (rgn, TRUE);

			btScreen.DeleteObject();
		}
	}
	return TRUE;// CButton::OnEraseBkgnd(pDC);//
}
void CResizableLayout::ClipChildWindow(const CResizableLayout::LayoutInfo& layout,
									   CRgn* pRegion)
{
	// obtain window position
	CRect rect;
	::GetWindowRect(layout.hWnd, &rect);
	::MapWindowPoints(NULL, GetResizableWnd()->m_hWnd, (LPPOINT)&rect, 2);

	// use window region if any
	CRgn rgn;
	rgn.CreateRectRgn(0,0,0,0);
	switch (::GetWindowRgn(layout.hWnd, rgn))
	{
	case COMPLEXREGION:
	case SIMPLEREGION:
		rgn.OffsetRgn(rect.TopLeft());
		break;

	default:
		rgn.SetRectRgn(&rect);
	}

	// get the clipping property
	BOOL bClipping = layout.properties.bAskClipping ?
		LikesClipping(layout) : layout.properties.bCachedLikesClipping;

	// modify region accordingly
	if (bClipping)
		pRegion->CombineRgn(pRegion, &rgn, RGN_DIFF);
	else
		pRegion->CombineRgn(pRegion, &rgn, RGN_OR);
}
void CWndMapPartsAnimeList::OnPaint()
{
	int x, cx, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgParts->Lock ();
	DCTmp.Attach (hDC);

	GetClientRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	x = GetScrollPos (SB_HORZ);

	cx = min (rc.Width (), m_pImgParts->Width ());
	cy = min (rc.Height (), m_pImgParts->Height ());
	dc.FillSolidRect (rc, RGB (128, 128, 128));
	dc.BitBlt (0, 0, cx, cy, &DCTmp, x * 16, 0, SRCCOPY);

	m_pImgParts->Unlock ();
	DCTmp.Detach ();
}
Exemple #14
0
//枚举函数
BOOL CALLBACK CLayeredWindow::EnumChildProc(HWND hWndChild, LPARAM lParam)
{
	//获取位置
	CRect rcWindow;
	::GetWindowRect(hWndChild,&rcWindow);

	//创建区域
	if ((rcWindow.Width()>0)&&(rcWindow.Height()>0))
	{
		//变量定义
		ASSERT(lParam!=0L);
		tagEnumChildInfo * pEnumChildInfo=(tagEnumChildInfo *)lParam;

		//窗口判断
		HWND hWndParent=::GetParent(hWndChild);
		if (hWndParent!=pEnumChildInfo->pWndControl->GetSafeHwnd())
		{
			return TRUE;
		}

		//转换位置
		ASSERT(pEnumChildInfo->pWndControl!=NULL);
		pEnumChildInfo->pWndControl->ScreenToClient(&rcWindow);

		//创建区域
		CRgn RgnChild;
		RgnChild.CreateRectRgn(rcWindow.left,rcWindow.top,rcWindow.right,rcWindow.bottom);

		//合并区域
		ASSERT(pEnumChildInfo->pRegionResult!=NULL);
		pEnumChildInfo->pRegionResult->CombineRgn(pEnumChildInfo->pRegionResult,&RgnChild,RGN_DIFF);
	}

	return TRUE;
}
Exemple #15
0
//////////////////////////////////////////////////////////////////////////
// 画透明异形图的函数
// 注:在这里特别感谢CSDN网友: 黄凯飞, ID: hkf314
void CAnimateButton::AlphaBitmap(int nItem)
{
	CDC* pDC = GetDC();
	CDC TmpDC;
	TmpDC.CreateCompatibleDC(pDC);
	//当然,TmpBmp用来记录画的内容
	CBitmap TmpBmp;
	TmpBmp.CreateCompatibleBitmap(pDC, m_aniBtnWidth, m_aniBtnHeight);
	TmpDC.SelectObject(&TmpBmp);
	
	//把按钮下的背景拷贝过来
	TmpDC.BitBlt(0, 0, m_aniBtnWidth, m_aniBtnHeight, pDC, 0, 0, SRCCOPY);
	//把内存DC中的图像透明地画出来

	AlphaBlend(TmpDC.m_hDC, 0, 0, m_aniBtnWidth, m_aniBtnHeight, m_pMemDC->m_hDC,
		 nItem * m_aniBtnWidth, 0, m_aniBtnWidth, m_aniBtnHeight, m_bf);

	//填充异形图像以外的区域为mask色
	CRgn rgn;
	rgn.CreateRectRgn(0, 0, m_aniBtnWidth, m_aniBtnHeight);
	rgn.CombineRgn(&rgn, CRgn::FromHandle(m_arBmpRgn[nItem]), RGN_DIFF);
//	TRACE("CRgn::FromHandle(m_arBmpRgn[nItem]): %d\n", nItem);
	CBrush maskBrh;
	maskBrh.CreateSolidBrush(m_clrTrans);
	TmpDC.FillRgn(&rgn, &maskBrh);
//	TmpDC.FillRgn(CRgn::FromHandle(m_arBmpRgn[nItem]), &maskBrh);

	//抠除mask色,直接画出来
 	::TransparentBlt(pDC->m_hDC, 0, 0, m_aniBtnWidth, m_aniBtnHeight, TmpDC.m_hDC,
 		 0, 0, m_aniBtnWidth, m_aniBtnHeight, m_clrTrans);
// 	pDC->BitBlt(0, 0, m_aniBtnWidth, m_aniBtnHeight, &TmpDC, 0, 0, SRCCOPY);
// 	pDC->FillRgn(CRgn::FromHandle(m_arBmpRgn[nItem]), &maskBrh);

	ReleaseDC(pDC);
}
void CWndMapPartsGrp::OnPaint()
{
	int x, y, cx, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgParts->Lock ();
	DCTmp.Attach (hDC);

	GetClientRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	x = GetScrollPos (SB_HORZ);
	y = GetScrollPos (SB_VERT);

	cx = min (rc.Width (), m_pImgParts->Width ());
	cy = min (rc.Height (), m_pImgParts->Height ());
	dc.FillSolidRect (rc, RGB (128, 128, 128));
	dc.BitBlt (0, 0, cx, cy, &DCTmp, x * 16, y * 16, SRCCOPY);

	x = m_ptCursor.x * 16;
	y = (m_ptCursor.y - m_nPos) * 16;
	rcTmp.SetRect (x, y, x + 15, y + 15);

	dc.DrawEdge (rcTmp, EDGE_BUMP, BF_FLAT | BF_RECT);

	m_pImgParts->Unlock ();
	DCTmp.Detach ();
}
Exemple #17
0
void CLabHorizScale::drawScale(CDC *pDC)
{
   int tickLength;
   
   CRgn rgn;
   CRect rect = bounds();
   rgn.CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
   pDC->SelectClipRgn(&rgn);
      
   for(double x=getTickMin(); x<=maximum(); x=x+tickIncrement())
   {
      double temp = x/(majorTickFrequency()*tickIncrement());
      if(temp == ceil(temp))
         tickLength = 7;
      else
         tickLength = 3;


      pDC->MoveTo(translateCoordinate(x), rect.top);
      pDC->LineTo(translateCoordinate(x), rect.top + tickLength);

      temp = x/(tickMarkFrequency() * tickIncrement());
      if(temp == ceil(temp))
      {
         CString tickMarkStr;
         tickMarkStr.Format("%.*f", precision(), x);
         
         pDC->TextOut(translateCoordinate(x) - _parent->getCharWidth() * tickMarkStr.GetLength()/2, 
                      rect.top + 7 /* _parent->getCharHeight()*/, 
                      tickMarkStr);

      }
   }
}
Exemple #18
0
BOOL CResizableLayout::EnumAndClipChildWindow(HWND hWnd, LPARAM lParam)
{
	CResizableLayout* pThis = (CResizableLayout*)lParam;

	// only direct children
	if (::GetParent(hWnd) != pThis->GetResizableWnd()->GetSafeHwnd())
		return TRUE;

	if (!::IsWindowVisible(hWnd))
		return TRUE;	// skip invisible windows

	// go clipping?
	if (!pThis->LikesClipping(hWnd))
		return TRUE;

	// obtain window position
	CRect rect;
	::GetWindowRect(hWnd, &rect);
	pThis->GetResizableWnd()->ScreenToClient(&rect);

	// use window region if any
	CRgn rgn;
	rgn.CreateRectRgn(0,0,0,0);
	if (COMPLEXREGION == ::GetWindowRgn(hWnd, rgn))
	{
		rgn.OffsetRgn(rect.TopLeft());
		pThis->m_pClipDC->SelectClipRgn(&rgn, RGN_DIFF);
	}
	else
	{
		pThis->m_pClipDC->ExcludeClipRect(&rect);
	}

	return TRUE;
}
Exemple #19
0
/// <param name="list">list of points</param>
/// <param name="count">number of points</param>
/// <param name="width">pen width for drawing line</param>
/// <param name="color">pen color</param>
/// <param name="fill">polygon fill color</param>
void Canvas::DrawPolygon(const rect_t &rect, const rect_t &box, point_t list[], size_t count, meter_t width, color_t color, color_t fill)
{
	CPen pen;
	CBrush brush;
	std::vector<POINT> pts;
	POINT pt = {0};

	for (size_t i = 0; i < count; i++)
	{
		pt.x = list[i].x - box.x + rect.x;
		pt.y = list[i].y - box.y + rect.y;
		pts.push_back(pt);
	}
	CRgn region;
	region.CreateRectRgn(rect.x, rect.y, rect.x + rect.wide, rect.y + rect.high);
	SelectClipRgn(region);

	brush.CreateSolidBrush(fill);
	pen.CreatePen(PS_SOLID, width, color);
	HPEN hSavePen = SelectPen(pen);
	HBRUSH hSaveBrush = SelectBrush(brush);
	Polygon(&pts[0], pts.size());

	SelectPen(hSavePen);
	SelectBrush(hSaveBrush);
	SelectClipRgn(NULL);
}
void CStaticMapShadow::OnPaint()
{
	int x, y, cy;
	HDC hDC;
	CDC DCTmp;
	CRect rc, rcTmp;
	CRgn rgn;
	CPaintDC dc(this);

	hDC = m_pImgShadow->Lock ();
	DCTmp.Attach (hDC);

	GetWindowRect (rc);
	rgn.CreateRectRgn (0, 0, rc.Width (), rc.Height ());
	dc.SelectClipRgn (&rgn, RGN_COPY);

	ScreenToClient (rc);
	cy = min (rc.Height (), m_pImgShadow->Height ());
	dc.BitBlt (0, 0, m_pImgShadow->Width (), cy, &DCTmp, 0, 0, SRCCOPY);

	x = m_ptCursor.x * 16;
	y = (m_ptCursor.y - m_nPos) * 16;
	cy = y + 15;
	cy = min (cy, rc.Height ());
	rcTmp.SetRect (x, y, x + 15, cy);

	dc.DrawEdge (rcTmp, EDGE_BUMP, BF_FLAT | BF_RECT);

	m_pImgShadow->Unlock ();
	DCTmp.Detach ();
}
Exemple #21
0
void CAnsiWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

    CRect rect;
    GetClientRect(&rect);

    CRgn rgn;
    rgn.CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
    dc.SelectClipRgn(&rgn);

    int ScrollIndex = GetScrollPos(SB_VERT);

    POSITION pos = m_strList.FindIndex(ScrollIndex+m_nPageSize);
    ASSERT(pos);
    rect.top = rect.bottom-pDoc->m_nYsize;
    int i = 0;

    dc.SetBkMode(OPAQUE);
    CFont* pOldFont = dc.SelectObject(&pDoc->m_fntText);

    while ( pos && i++ <= m_nPageSize) {
        CString str = m_strList.GetPrev(pos);

        if ( dc.RectVisible(&rect) )
            DrawWithANSI(&dc, rect, &str, m_nPageSize - i);

        rect.top -= pDoc->m_nYsize;
        rect.bottom -= pDoc->m_nYsize;
    }
    dc.SelectObject(pOldFont);
}
Exemple #22
0
int COXSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
	{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	if ((HRGN)m_rgn != NULL)
		{
		CRgn rgn;
		rgn.CreateRectRgn(0,0,1,1);
		switch(rgn.CopyRgn(&m_rgn))
			{
			case ERROR:
				TRACE0("COXSplashWnd::OnCreate(): fail to load the calculated region.\r\n");
				rgn.DeleteObject();
				break;
			case NULLREGION:
				TRACE0("COXSplashWnd::OnCreate(): empty region was encountered.\r\n");
				rgn.DeleteObject();
				break;
			default:
				::SetWindowRgn(m_hWnd, (HRGN)rgn.Detach(), TRUE);
			}
		}
	
	CenterWindow();
	if (m_nTimeout != SPLASH_NOTIMER)
		SetTimer(OXSPLASHWND_TIMERID_HIDE, m_nTimeout, NULL);

	SetCapture();
	::SetCursor(::LoadCursor(NULL, IDC_ARROW));
	
	return 0;
	}
Exemple #23
0
HBRUSH CIconEditEx::CtlColor(CDC* pDC, UINT nCtlColor)
{
	HBRUSH hbr;
	hbr = (HBRUSH)m_brBkgnd; // Passing a Handle to the Brush
	CRect rcClient;
	GetClientRect(&rcClient);
	if (m_progressValue > 0.0)
	{
		CRect rc;
		GetRect(&rc);
		pDC->FillSolidRect(&rc, m_colors[COL_Bk]);
		GetClientRect(&rc);
		CRgn rgn;
		rgn.CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
		pDC->SelectClipRgn(&rgn, RGN_COPY);
		pDC->FillSolidRect(0, 0, INT(rc.Width() * m_progressValue), rc.Height(), m_colors[COL_Progress]);
		pDC->SetBkMode(TRANSPARENT);
	}
	//if (m_hIcon != NULL)
	//{
	//	CRgn rgn;
	//	rgn.CreateRectRgn(cMargin, cMargin, cMargin + m_cx, cMargin + m_cy);
	//	pDC->SelectClipRgn(&rgn, RGN_OR);
	//	INT top = (rcClient.Height() - m_cy) / 2;
	//	::DrawIconEx(pDC->m_hDC, cMargin, top, m_hIcon, m_cx, m_cy, 0, NULL, DI_NORMAL );
	//}
	//if (m_hClearIcon != NULL)
	//{
	//	INT top = (rcClient.Height() - m_cy) / 2;
	//	::DrawIconEx(pDC->m_hDC, cMargin, top, m_hIcon, m_cx, m_cy, 0, NULL, DI_NORMAL );
	//}
	pDC->SetBkColor(m_colors[COL_Bk]); // Setting the Color of the Text Background to the one passed by the Dialog
	pDC->SetTextColor(m_colors[COL_Text]); // Setting the Text Color to the one Passed by the Dialog
	return hbr;
}
Exemple #24
0
void TextProgressCtrl::OnPaint(void)
{
    CPaintDC sPaintDC(this);

    MemDC sMemDC(&sPaintDC);

    CRect sClientRect;
    GetClientRect(sClientRect);

    xpr_double_t sFraction = 0.0;
    if ((mMax - mMin) > 0)
        sFraction = (xpr_double_t)(mPos - mMin) / ((xpr_double_t)(mMax - mMin));

    CRect sProgressRect(sClientRect);
    sProgressRect.right = sProgressRect.left + (xpr_sint_t)(sProgressRect.Width() * sFraction);

    CRect sBackRect(sClientRect);
    sBackRect.left = sProgressRect.right;

    sMemDC.FillSolidRect(sProgressRect, mProgressColor);
    sMemDC.FillSolidRect(sBackRect, mBackColor);

    if (XPR_IS_TRUE(mShowText))
    {
        xpr_tchar_t sText[0xff] = {0};
        _stprintf(sText, XPR_STRING_LITERAL("%d%%"), (xpr_sint_t)(sFraction * 100.0));

        CFont *sOldFont = sMemDC.SelectObject(&mTextFont);
        sMemDC.SetBkMode(TRANSPARENT);

        CRgn sRgn;
        sRgn.CreateRectRgn(sProgressRect.left, sProgressRect.top, sProgressRect.right, sProgressRect.bottom);
        sMemDC.SelectClipRgn(&sRgn);
        sMemDC.SetTextColor(mTextBackColor);

        sMemDC.DrawText(sText, sClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

        sRgn.DeleteObject();
        sRgn.CreateRectRgn(sBackRect.left, sBackRect.top, sBackRect.right, sBackRect.bottom);
        sMemDC.SelectClipRgn(&sRgn);
        sMemDC.SetTextColor(mTextProgressColor);

        sMemDC.DrawText(sText, sClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

        sMemDC.SelectObject(sOldFont);
    }
}
void CTextProgressCtrl::OnPaint() 
{
    if (m_nMin >= m_nMax) 
        return;

    CRect LeftRect, RightRect, ClientRect;
    GetClientRect(ClientRect);

    double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin));

    CPaintDC PaintDC(this); // device context for painting
    CMyMemDC dc(&PaintDC);
    //CPaintDC dc(this);    // device context for painting (if not double buffering)

    LeftRect = RightRect = ClientRect;

    LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction);
    dc.FillSolidRect(LeftRect, m_colFore);

    RightRect.left = LeftRect.right;
    dc.FillSolidRect(RightRect, m_colBk);

    if (m_bShowText)
    {
        CString str;
        if (m_strText.GetLength())
            str = m_strText;
        else
            str.Format(_T("%d%%"), (int)(Fraction*100.0));

        dc.SetBkMode(TRANSPARENT);

        CRgn rgn;
        rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom);
        dc.SelectClipRgn(&rgn);
        dc.SetTextColor(m_colTextBk);

        dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

        rgn.DeleteObject();
        rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom);
        dc.SelectClipRgn(&rgn);
        dc.SetTextColor(m_colTextFore);

        dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
    }
}
void CBCGPSDPlaceMarkerWnd::ShowTabbedAt (CRect rect, CRect rectTab)
{
    if (!m_bTabbed || m_rectLast != rect || m_rectTab != rectTab)
    {
        Hide ();

        CRgn rgnMain;
        CBCGPTabbedControlBar::m_bTabsAlwaysTop ? 
			rgnMain.CreateRectRgn (0, rectTab.Height (), rect.Width(), rect.Height() + rectTab.Height ()) :
			rgnMain.CreateRectRgn (0, 0, rect.Width(), rect.Height());

        CRgn rgnTab;
        if (CBCGPTabbedControlBar::m_bTabsAlwaysTop)
		{
			rgnTab.CreateRectRgn (rectTab.left, 0, rectTab.Width (), rectTab.Height ());
		}
		else
		{
			rgnTab.CreateRectRgnIndirect (rectTab);
		}

        rgnMain.CombineRgn (&rgnMain, &rgnTab, RGN_OR);
        SetWindowRgn (rgnMain, FALSE);

        m_bTabbed = TRUE;

        m_rectLast = rect;
		m_rectTab = rectTab;

		if (CBCGPTabbedControlBar::m_bTabsAlwaysTop)
		{
			SetWindowPos (&CWnd::wndTop, rect.left, rectTab.top, 
				rect.Width(), rect.Height() + m_rectTab.Height (),
				SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOREDRAW);
		}
		else
		{
			SetWindowPos (&CWnd::wndTop, rect.left, rect.top, 
				rect.Width(), rect.Height() + m_rectTab.Height (),
				SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOREDRAW);
		}
		m_bShown = TRUE;
        RedrawWindow ();
    }
}
BOOL GetRegionfromBitmap(RECT r, CRgn *pRgn, CBitmap *pBitmap, COLORREF keyColor, COLORREF cTolerance)
{
	if (!pBitmap) 
		return FALSE;

	if (!pRgn) 
		return FALSE;

	BYTE lr = (BYTE)max(0, (int)GetRValue(keyColor) - (int)GetRValue(cTolerance));
	BYTE lg = (BYTE)max(0, (int)GetGValue(keyColor) - (int)GetGValue(cTolerance));
	BYTE lb = (BYTE)max(0, (int)GetBValue(keyColor) - (int)GetBValue(cTolerance));
	BYTE hr = (BYTE)min((int)0xff, (int)GetRValue(keyColor) + (int)GetRValue(cTolerance));
	BYTE hg = (BYTE)min((int)0xff, (int)GetGValue(keyColor) + (int)GetGValue(cTolerance));
	BYTE hb = (BYTE)min((int)0xff, (int)GetBValue(keyColor) + (int)GetBValue(cTolerance));

	CDC					memDC;
	CBitmap				*pOldMemBmp = NULL;
	CRect				cRect(r);
	int					x, y;
	int					n=0;		//number of transparent pixels
	CRgn				rgnTemp;

	memDC.CreateCompatibleDC(NULL);
	pOldMemBmp = memDC.SelectObject(pBitmap);
	pRgn->CreateRectRgn(0, 0, cRect.Width(), cRect.Height());

	//COLORREF m_Color = memDC.GetPixel(0, 0);
	for (x = 0; x <= r.right - r.left; x++)
	{
		for (y = 0; y <= r.bottom - r.top; y++)
		{
			COLORREF cr = memDC.GetPixel(x,y);
			BYTE b = GetRValue(cr);
			if (lr <= b && b <= hr) 
			{
				b = GetGValue(cr);
				if (lg <= b && b <= hg) 
				{
					b = GetBValue(cr);
					if (lb <= b && b <= hb) 
					{
						rgnTemp.CreateRectRgn(x, y, x + 1, y + 1);
						pRgn->CombineRgn(pRgn, &rgnTemp, RGN_XOR);
						rgnTemp.DeleteObject();	
						++n;
					}
				}
			}
		}
	}

	if (pOldMemBmp) 
		memDC.SelectObject(pOldMemBmp);
	memDC.DeleteDC();

	return n > 0;
}
void CMyBalloon::SetupWindowRgn()
{
	CRect rcWnd (0,0,0,0);
	
	CSize sizeReq = m_pContent->getRequiredSize ();
	
	rcWnd.right = sizeReq.cx;
	rcWnd.bottom = sizeReq.cy;

	rcWnd.InflateRect (3, 3);

	rcWnd.left += 3; rcWnd.right += 3;
	rcWnd.top  += 3; rcWnd.bottom += 3;

	int cxScreen = GetSystemMetrics (SM_CXSCREEN);
	int cyScreen = GetSystemMetrics (SM_CYSCREEN);
	
	m_bLeaderAtRight = false; m_bLeaderAtTop = false;
	if (m_ptAnchor.x + rcWnd.Width () > cxScreen)
		m_bLeaderAtRight = true;
	if (m_ptAnchor.y - rcWnd.Height () - CY_LEADER < 0)
		m_bLeaderAtTop = true;

	if (m_bLeaderAtTop)
	{
		rcWnd.top += CY_LEADER;
		rcWnd.bottom += CY_LEADER;
	}

	CPoint ptLeader [3];

	ptLeader[0].x = m_bLeaderAtRight ? rcWnd.Width () - CX_ROUNDED - CX_LEADER_MARGIN : 
	CX_ROUNDED + CX_LEADER_MARGIN;
	ptLeader[0].y = m_bLeaderAtTop ? rcWnd.top + CY_ROUNDED : rcWnd.Height() - CY_ROUNDED;
	
	ptLeader[1].x = ptLeader[0].x;
	ptLeader[1].y = m_bLeaderAtTop ? ptLeader[0].y - CY_ROUNDED - CY_LEADER : ptLeader[0].y + CY_ROUNDED + CY_LEADER;
	
	ptLeader[2].x = m_bLeaderAtRight ? ptLeader[0].x - CX_ROUNDED - CX_LEADER - CX_LEADER_MARGIN - 10 : 
		ptLeader[0].x + CX_ROUNDED + CX_LEADER + CX_LEADER_MARGIN + 10;
	ptLeader[2].y = m_bLeaderAtTop ? rcWnd.top + CY_ROUNDED + CY_LEADER : rcWnd.Height() - CY_ROUNDED - CY_LEADER;

	CRgn rgnLeader, rgnContent;

	rgnContent.CreateRoundRectRgn (rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, CX_ROUNDED, CY_ROUNDED);
	rgnLeader.CreatePolygonRgn (ptLeader, 3, ALTERNATE);
	CRgn rgn; rgn.CreateRectRgn (0, 0, rcWnd.Width (), rcWnd.Height () + CY_LEADER);
	rgn.CombineRgn (&rgnContent, &rgnLeader, RGN_OR);

	SetWindowPos (CWnd::FromHandle (HWND_TOPMOST), 
		(m_bLeaderAtRight ? m_ptAnchor.x - rcWnd.Width () + CX_ROUNDED + CX_LEADER_MARGIN : m_ptAnchor.x - CX_ROUNDED - CX_LEADER_MARGIN),
		(m_bLeaderAtTop ? m_ptAnchor.y : m_ptAnchor.y - rcWnd.Height () - CY_LEADER), 
		rcWnd.Width (), rcWnd.Height () + CY_LEADER, 0);

	SetWindowRgn (rgn, FALSE);
}
Exemple #29
0
BOOL CVisualManager::OnSetWindowRegion (CWnd* pWnd, CSize sizeWindow)
{
	ASSERT_VALID (pWnd);

	if (pWnd->GetSafeHwnd () == NULL)
	{
		return FALSE;
	}

	if (!CanDrawImage ())
	{
		return FALSE;
	}

	if (globalData.DwmIsCompositionEnabled ())
	{
		return FALSE;
	}

    CSize sz (0, 0);

	if (DYNAMIC_DOWNCAST (CBCGPFrameWnd, pWnd) != NULL)
	{
		if (pWnd->IsZoomed ())
		{
			pWnd->SetWindowRgn (NULL, TRUE);
			return TRUE;
		}

		sz  = CSize (9, 9);
	}

	if (sz != CSize (0, 0))
	{
        CRgn rgn;
		BOOL bCreated = FALSE;

		bCreated = rgn.CreateRoundRectRgn (0, 0, sizeWindow.cx + 1, sizeWindow.cy + 1, sz.cx, sz.cy);

		if (bCreated)
		{
			if (pWnd->IsKindOf (RUNTIME_CLASS (CMDIChildWnd)))
			{
				CRgn rgnWinodw;
				rgnWinodw.CreateRectRgn (0, sz.cy, sizeWindow.cx, sizeWindow.cy);

				rgn.CombineRgn (&rgn, &rgnWinodw, RGN_OR);
			}

			pWnd->SetWindowRgn ((HRGN)rgn.Detach (), TRUE);
			return TRUE;
		}
	}

	return FALSE;
}
Exemple #30
0
void CProgressCtrlX::DrawClippedText(const CDrawInfo& info, const CRect& rcClip, CString& sText, const CPoint& ptWndOrg)
{
	CDC *pDC = info.pDC;
	CRgn rgn;
	CRect rc = ConvertToReal(info, rcClip);
	rc.OffsetRect(-ptWndOrg);
	rgn.CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
	pDC->SelectClipRgn(&rgn);
	pDC->TextOut (0, 0, sText);
	rgn.DeleteObject();
}