当前位置: 首页>>代码示例>>C++>>正文


C++ CDC::CreateCompatibleDC方法代码示例

本文整理汇总了C++中CDC::CreateCompatibleDC方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::CreateCompatibleDC方法的具体用法?C++ CDC::CreateCompatibleDC怎么用?C++ CDC::CreateCompatibleDC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDC的用法示例。


在下文中一共展示了CDC::CreateCompatibleDC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnPaint

void CSmallPolygonsVisDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CPaintDC dc(this);

		CDC mem;
		mem.CreateCompatibleDC(&dc);
		CBitmap bmp;
		bmp.CreateCompatibleBitmap(&dc, DRAW_WIDTH, DRAW_HEIGHT);
		mem.SelectObject(&bmp);
		mem.SetBkMode(TRANSPARENT);
		mem.FillSolidRect(0, 0, DRAW_WIDTH, DRAW_HEIGHT, RGB(128, 128, 128));

		LOGFONT font = {};
		font.lfHeight = 12;
		font.lfCharSet = ANSI_CHARSET;
		_tcscpy(font.lfFaceName, _T("Terminal"));
		CFont Font;
		Font.CreateFontIndirect(&font);
		mem.SelectObject(Font);

		for (int i = 0; i < m_sp.Np; ++i) {
			int x = m_sp.x[i], y = m_sp.y[i];
			x = (x * DRAW_WIDTH) / MAX_COORDINATE;
			y = (y * DRAW_HEIGHT) / MAX_COORDINATE;
			TCHAR w[64];
			_stprintf(w, _T("%d"), i);
			mem.SetTextColor(RGB(255, 255, 255));
			mem.TextOut(x + 4, y, w);
		}

		CPen line;
		line.CreatePen(PS_SOLID, 0, RGB(0, 255, 0));
		mem.SelectObject(line);
		for (int start_node : m_sp.polygons) {
			int x = m_sp.x[start_node], y = m_sp.y[start_node];
			x = (x * DRAW_WIDTH) / MAX_COORDINATE;
			y = (y * DRAW_HEIGHT) / MAX_COORDINATE;
			mem.MoveTo(x, y);
			int node = start_node;
			do {
				int next_node = m_sp.connection[node].next;
				int x = m_sp.x[next_node], y = m_sp.y[next_node];
				x = (x * DRAW_WIDTH) / MAX_COORDINATE;
				y = (y * DRAW_HEIGHT) / MAX_COORDINATE;
				mem.LineTo(x, y);
				node = m_sp.connection[node].next;
			} while (node != start_node);
		}

		CBrush brush;
		brush.CreateSolidBrush(RGB(255, 0, 0));

		for (int start_node : m_sp.polygons) {
			int node = start_node;
			do {
				mem.SelectObject(brush);
				int x = m_sp.x[node], y = m_sp.y[node];
				x = (x * DRAW_WIDTH) / MAX_COORDINATE;
				y = (y * DRAW_HEIGHT) / MAX_COORDINATE;
				mem.Ellipse(x - 2, y - 2, x + 2, y + 2);

				node = m_sp.connection[node].next;
			} while (node != start_node);
		}

		BitBlt(dc.GetSafeHdc(), LEFT_OFFSET, TOP_OFFSET, DRAW_WIDTH, DRAW_HEIGHT, mem.GetSafeHdc(), 0, 0, SRCCOPY);

		CDialogEx::OnPaint();
	}
}
开发者ID:firewood,项目名称:topcoder,代码行数:89,代码来源:SmallPolygonsVisDlg.cpp

示例2: InitComplexSymbolLayerCtrl

void CComplexSymbolLayerCtrl::InitComplexSymbolLayerCtrl(RECT * rect, 
														 UINT nIDResource , 
														 unsigned int nWidth)
{
	if( !rect )
	{
		return;
	}
	m_rc.bottom = rect->bottom - 5;
	m_rc.right = rect->right+1;
	m_rc.left = rect->left;
	m_rc.top = rect->top;
	m_nX = m_rc.right-m_rc.left;
	m_nY = m_rc.bottom-m_rc.top;
	if( m_LargeImageList!= NULL )
	{
		int nCount = m_LargeImageList->GetImageCount();
		for ( int i=0 ; nCount<i ; i++ )
		m_LargeImageList->Remove( i );
		m_LargeImageList->DeleteImageList();
		delete m_LargeImageList;
		m_LargeImageList=NULL;
	}
	m_LargeImageList=new CImageList;
	m_LargeImageList->Create(m_nX,m_nY,ILC_COLOR24,0,1);

	if( nIDResource!=-1 )
	{
		m_nWidth=nWidth;
		m_StateImageList.Create( nIDResource , nWidth , 1 , RGB(255,0,0) );
	}
	CDC * dc = GetDC();
	CDC MemDC;//创建相容的bitmap和dc

	HBITMAP hbitmap1 = CreateCompatibleBitmap( dc->GetSafeHdc() , m_nX , m_nY );
	HBITMAP hBitmapTemp;

	MemDC.CreateCompatibleDC(dc);
	hBitmapTemp = ( HBITMAP )SelectObject( MemDC , hbitmap1 );

	RECT rectMask;
	rectMask.top=rectMask.left= 0;
	rectMask.right = m_rc.right;
	rectMask.bottom = m_rc.bottom;

	HBRUSH hSolidBrush = CreateSolidBrush( DEFAULTCOLOR );
	FillRect( MemDC.GetSafeHdc() , &rectMask,hSolidBrush );
	hbitmap1=( HBITMAP )SelectObject( MemDC.m_hDC , hBitmapTemp );
	if(m_MaskBitmap!= NULL)
	{
		m_MaskBitmap->DeleteObject();
		m_MaskBitmap = NULL;
	}

	m_MaskBitmap=CBitmap::FromHandle( hbitmap1 );

	DeleteObject( hSolidBrush );
	ReleaseDC( dc );
	MemDC.DeleteDC();
	this->SetImageList( m_LargeImageList , LVSIL_NORMAL );
	this->SetImageList( &m_StateImageList , LVSIL_STATE );

	AddCOL();
}
开发者ID:lozpeng,项目名称:applesales,代码行数:64,代码来源:ComplexSymbolLayerCtrl.cpp

示例3: GetFontExtractWidth

void CNewYC::GetFontExtractWidth(CDC *pDC,CElecMapView *pView)
{
	CDC memdc;
	memdc.CreateCompatibleDC(pDC);
	float minx,miny,maxx,maxy;
	pView->GetFloatRect(&minx,&miny,&maxx,&maxy);
	if (!IntersectRect(minx,miny,maxx,maxy)) 
	{
		return;
	}
	GetRect(&minx,&miny,&maxx,&maxy);
	CPoint pt1,pt2,pt3,pt4;
	pt1=pView->UPtoLP(m_yc.rect.x0,m_yc.rect.y0);
	pt2=pView->UPtoLP(m_yc.rect.x0,m_yc.rect.y1);
	pt3=pView->UPtoLP(m_yc.rect.x1,m_yc.rect.y1);
	pt4=pView->UPtoLP(m_yc.rect.x1,m_yc.rect.y0);
	int hintcount,unitcount,hinthz,unithz;int hintdis,unitdis;
	hintcount=GetCharLen(m_yc.hint,33,&hinthz);
	unitcount=GetCharLen(m_yc.unit,17,&unithz);
	hintdis=0;unitdis=0;
	if (hintcount>0) hintdis=pView->ULtoLL(m_yc.hintdis);
	if (unitcount>0) unitdis=pView->ULtoLL(m_yc.unitdis);
	char s[256];
	memcpy(s,YC_STRING,sizeof(char)*m_yc.digitlength);
	s[m_yc.digitlength]='\0';
	CString tmpstr;
	tmpstr="";
	tmpstr=tmpstr+m_yc.hint;
	tmpstr=tmpstr+s;
	tmpstr=tmpstr+m_yc.unit;
	if ((pt3.x-pt1.x-hintdis-unitdis>(YC_MINDISWIDTH*(m_yc.digitlength+hintcount+unitcount+1)
		+pView->ULtoLL(m_yc.fontjj)*(m_yc.digitlength+hintcount+unitcount-hinthz-unithz)))&&
		(pt3.y-pt1.y>YC_MINDISHEIGHT))
	{
		m_yc.lgfont.lfHeight=pt3.y-pt1.y;
		m_yc.lgfont.lfWidth=(LONG)(pt3.x-pt1.x-hintdis-unitdis
			-pView->ULtoLL(m_yc.fontjj)*(m_yc.digitlength+hintcount+unitcount-hinthz-unithz))/
			(m_yc.digitlength+hintcount+unitcount);
		while (true) 
		{
			CFont m_font;
			LOGFONT tempfont;
			tempfont=m_yc.lgfont;
			m_font.CreateFontIndirect(&tempfont);
			CFont * m_oldfont=memdc.SelectObject(&m_font);
			CSize size;
			size=memdc.GetOutputTextExtent(tmpstr,m_yc.digitlength+hintcount+unitcount);//+2);
			size.cx=size.cx;//-m_yc.lgfont.lfWidth*1;//+qq;
			memdc.SelectObject(m_oldfont);
			//if ((minlen<=(pt3.x-pt1.x)*FontSizePercent)||(m_yc.lgfont.lfWidth<=0))
			if (((size.cx*(m_yc.digitlength+hintcount+unitcount+1)/(m_yc.digitlength+hintcount+unitcount))<=
				(pt3.x-pt1.x-hintdis-unitdis
				-pView->ULtoLL(m_yc.fontjj)*(m_yc.digitlength+hintcount+unitcount-hinthz-unithz)))||(m_yc.lgfont.lfWidth<=0))
			{
				m_yc.fontheight=pView->LLtoUL(m_yc.lgfont.lfHeight);
				m_yc.fontwidth=pView->LLtoUL(m_yc.lgfont.lfWidth);
				break;
			}else{
				m_yc.lgfont.lfWidth--;
			}
		}
	}

	CNewYCTool::canuse=true;
	CNewYCTool::m_yc=this->m_yc;
	sprintf(CNewYCTool::m_yc.ename,"");
	CNewYCTool::m_yc.fontwidth=(float)(pView->ULtoLL(m_yc.fontwidth));
	CNewYCTool::m_yc.fontheight=(float)(pView->ULtoLL(m_yc.fontheight));
	CNewYCTool::m_yc.fontjj=(float)(pView->ULtoLL(m_yc.fontjj));
	CNewYCTool::m_yc.hintdis=(float)(pView->ULtoLL(m_yc.hintdis));
}
开发者ID:github188,项目名称:MonitorSystem,代码行数:71,代码来源:NewYC.cpp

示例4: OnDraw

void CTinyCadView::OnDraw(CDC* pDC)
{
	//CTinyCadDoc* pDoc = GetCurrentDocument();
	CDC BitmapDC;
	CBitmap *old_bitmap = NULL;

	int selected;

	CRect client;
	if (pDC->IsKindOf(RUNTIME_CLASS(CPaintDC)))
	{
		client = static_cast<CPaintDC*> (pDC)->m_ps.rcPaint;
	}
	else
	{
		GetClientRect(&client);
	}

	// Are we going to use off-screen drawing?
	BOOL osb = !pDC->IsPrinting() && m_use_offscreen_drawing && CreateBitmap(*pDC, client.Width(), client.Height());

	if (osb)
	{
		BitmapDC.CreateCompatibleDC(pDC);
		old_bitmap = BitmapDC.SelectObject(&m_bitmap);
	}

	{
		CContext dc(osb ? &BitmapDC : pDC, GetTransform(), this);

		CDPoint origin = GetTransform().GetOrigin();

		if (osb)
		{
			CPoint point = CPoint(-client.left, -client.top);
			dc.SetPixelOffset(point);
		}

		if (pDC->IsPrinting())
		{
			dc.SetBlack(CTinyCadRegistry::GetPrintBandW());
		}

		CDPoint Start, End;
		CRect rect;
		GetClientRect(&rect);
		TransformSnap snap;
		snap.SetGridSnap(FALSE);
		Start = GetTransform().DeScale(snap, CPoint(rect.left, rect.top));
		End = GetTransform().DeScale(snap, CPoint(rect.right, rect.bottom));

		// Is any of this region in the off-page area?
		if (!pDC->IsPrinting())
		{

			// Paint the region white
			if (pDC->IsPrinting())
			{
				dc.SelectBrush(cWHITE);
				dc.SelectPen(PS_SOLID, 1, cWHITE);
			}
			else
			{
				COLORREF col = GetCurrentDocument()->GetOptions()->GetUserColor().Get(CUserColor::BACKGROUND);
				dc.SelectBrush(col, 0);
				dc.SelectPen(PS_SOLID, 1, col);
			}
			dc.Rectangle(CDRect(Start.x - 2, Start.y - 2, End.x + 2, End.y + 2));

			dc.SelectBrush(cOFFPAGE);
			dc.SelectPen(PS_SOLID, 1, cOFFPAGE);

			if (End.x > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x)
			{
				CDPoint a = CDPoint(GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x, 0);
				dc.Rectangle(CDRect(a.x, a.y, End.x, End.y));
			}
			if (End.y > GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y)
			{
				CDPoint a = CDPoint(Start.x, GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y);
				dc.Rectangle(CDRect(a.x, a.y, End.x, End.y));
			}
			if (Start.x < 0) dc.Rectangle(CDRect(0, Start.y, Start.x, End.y));
			if (Start.y < 0) dc.Rectangle(CDRect(Start.x, 0, End.x, Start.y));

			// Fill this region with a grid
			double grid = GetCurrentDocument()->m_snap.GetGrid();
			double SGrid = dc.GetTransform().doubleScale(grid);
			if (GetCurrentDocument()->GetOptions()->ShowGrid() && SGrid > 10)
			{
				double x = dc.GetTransform().GetOrigin().x;
				double y = dc.GetTransform().GetOrigin().y;

				TransformSnap s = GetCurrentDocument()->m_snap;
				s.SetGridSnap(TRUE);

				x = s.Snap(x);
				y = s.Snap(y);

				for (double xp = x >= 0 ? x : 0; xp < End.x && xp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().x; xp += grid)
//.........这里部分代码省略.........
开发者ID:soloveyhappy,项目名称:tiny,代码行数:101,代码来源:Paint.cpp

示例5: OnFileSaveImage

//-------------------------------------------------------------------------
// 그림파일로 저장
//-------------------------------------------------------------------------
void CMainFrame::OnFileSaveImage()
{
	//파일 다이얼로그 생성
	CFileDialog dlg(FALSE, L"bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
					L"Bitmap File(*.bmp) | *.bmp |JPG File(*.jpg) | *.jpg |PNG File(*.png) | *.png ||", this);

	if(dlg.DoModal() == IDOK)
	{
		//////////////////////////////////////////////////////////////////////////
		// View 내용을 비트맵으로 만듬
		CRect clientRect;
		CGraphicEditorView* psView = (CGraphicEditorView*)GetActiveView();
		psView->GetClientRect(clientRect);
		//선택 라인을 그리지 않도록 선택 모드 해제
		BOOL bsSingleSelect = FALSE, bsMultiSelect = FALSE;
		if (psView->m_bsSelectMode) 
		{
			bsSingleSelect = TRUE;
			psView->m_bsSelectMode = FALSE;

		}
		if(psView->m_bsMultiSelectMode)
		{
			bsMultiSelect = TRUE;
			psView->m_bsMultiSelectMode = FALSE;
		}
		psView->RedrawWindow();
		CDC dcMem;
		dcMem.CreateCompatibleDC(psView->GetDC());
		CBitmap cBitmap, *pOldBitmap;
		cBitmap.CreateCompatibleBitmap(psView->GetDC(), clientRect.Width(), clientRect.Height());
		pOldBitmap = (CBitmap*)dcMem.SelectObject(cBitmap);
		dcMem.BitBlt(0, 0, clientRect.Width(), clientRect.Height(), psView->GetDC(), 0, 0, SRCCOPY);

		//////////////////////////////////////////////////////////////////////////
		// 파일 저장
		Bitmap loadBitmap(cBitmap, NULL); //위에서 생성한 CBitmap을 GDI+에서 사용하는 Bitmap 객체로 바꿈
		CLSID imgClsid; //이미지 코덱 정보
		switch(dlg.m_ofn.nFilterIndex)
		{
		case 1:	//BMP에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/bmp", &imgClsid);
			break;
		case 2: //JPG에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/jpeg", &imgClsid);
			break;
		case 3: //PNG에 대한 이미지 코덱의 CLSID를 받아옴
			GetEncoderClsid(L"image/png", &imgClsid);
			break;
		}
		//그림파일 저장 시 파라미터
		int nQuality = 100;
		EncoderParameters param;
		param.Count                       = 1; 
		param.Parameter[0].Guid           = EncoderQuality;
		param.Parameter[0].Type           = EncoderParameterValueTypeLong;
		param.Parameter[0].NumberOfValues = 1;
		param.Parameter[0].Value          = &nQuality;

		//그림 파일 저장
		CString fileName = dlg.GetPathName();
		loadBitmap.Save(fileName,&imgClsid, &param);

		//////////////////////////////////////////////////////////////////////////
		//선택 라인이 해제되었다면 다시 활성화
		if (bsSingleSelect) 
		{
			bsSingleSelect = FALSE;
			psView->m_bsSelectMode = TRUE;

		}
		if(bsMultiSelect)
		{
			bsMultiSelect = FALSE;
			psView->m_bsMultiSelectMode = TRUE;
		}
	}
}
开发者ID:SeoGB,项目名称:exam,代码行数:81,代码来源:MainFrm.cpp

示例6: drawPictCtrl

void CSimpleDcmViewerDlg::drawPictCtrl()
{
	if (TFileManager::getInst()->m_D == 0) return;

	static bool first = true;

	if (first)
	{
		CWnd *cwndPC = GetDlgItem(IDC_PC);
		first = false;
		CRect r;
		WINDOWPLACEMENT winplace;
		cwndPC->GetClientRect(&r);
		cwndPC->GetWindowPlacement(&winplace);

		m_pcW = m_pcH = PC_SIZE;//-2
		m_pcX = winplace.rcNormalPosition.left;
		m_pcY = winplace.rcNormalPosition.top;
	}


	// picture ControlのCWndを取得
	CWnd *pcWnd = GetDlgItem(IDC_PC);
	CDC  *pcDC = pcWnd->GetDC(); 


	BITMAPINFO binfo;
	ZeroMemory(&binfo, sizeof(binfo));
	binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	binfo.bmiHeader.biBitCount = 32;//1pixel 32-bit (4-byte)
	binfo.bmiHeader.biPlanes   = 1;
	binfo.bmiHeader.biWidth    =  PC_SIZE;
	binfo.bmiHeader.biHeight   = -PC_SIZE; //if negative : origin --> left top 

	byte    *bmpbits; 
	HBITMAP  hbmp = CreateDIBSection(NULL, &binfo, DIB_RGB_COLORS, (void **)(&bmpbits), NULL, 0);

	CBitmap *cbmp = CBitmap::FromHandle(hbmp);
	CDC cbmpDC;
	cbmpDC.CreateCompatibleDC(pcDC);          
	CBitmap *oldBmp = cbmpDC.SelectObject(cbmp);

	const int    imgW = TFileManager::getInst()->m_W;
	const int    imgH = TFileManager::getInst()->m_H;
	const int    imgD = TFileManager::getInst()->m_D;
	const int    imgZ = m_slider_z       .GetPos();
	const float  vMax = (float)m_slider_winLvMax.GetPos();
	const float  vMin = (float)m_slider_winLvMin.GetPos();
	int x0 = m_spin_clipXmin.GetPos32(), x1 = m_spin_clipXmax.GetPos32();  t_cropI(x0, 0, imgW - 1);  t_cropI(x0, 0, imgW - 1);
	int y0 = m_spin_clipYmin.GetPos32(), y1 = m_spin_clipYmax.GetPos32();  t_cropI(y0, 0, imgH - 1);  t_cropI(y0, 0, imgH - 1);
	int z0 = m_spin_clipZmin.GetPos32(), z1 = m_spin_clipZmax.GetPos32();  t_cropI(z0, 0, imgD - 1);  t_cropI(z0, 0, imgD - 1);

	if (imgZ < 0 || imgZ > imgD - 1) return;


	const int WH = imgW * imgH;
	float *sliceImg = TFileManager::getInst()->m_volume[imgZ];

	double xCoef = imgW / (double)PC_SIZE;
	double yCoef = imgH / (double)PC_SIZE;

	for (int y = 0; y < PC_SIZE; ++y)
	{
		for (int x = 0; x < PC_SIZE; ++x)
		{
			int imgX = (int)((x + 0.5) * xCoef);
			int imgY = (int)((y + 0.5) * yCoef);
			int imgI = imgX + imgY * imgW;
			const float imgV = sliceImg[imgI];

			int bmpI = (x + y * PC_SIZE) * 4;
			if (x0 <= imgX && imgX <= x1 && y0 <= imgY && imgY <= y1 && z0 <= imgZ && imgZ <= z1)
			{
				byte c = (byte)(255.0 * min(1, max(0, (imgV - vMin) / (vMax - vMin))));
				bmpbits[bmpI + 0] = bmpbits[bmpI + 1] = bmpbits[bmpI + 2] = c;
			}
			else {
				bmpbits[bmpI + 0] = 192; bmpbits[bmpI + 1] = bmpbits[bmpI + 2] = 0;
			}
		}
	}

	pcDC->BitBlt(1, 1, PC_SIZE - 2, PC_SIZE - 2, &cbmpDC, 0, 0, SRCCOPY);


	//解放
	cbmpDC.SelectObject(oldBmp);
	DeleteDC(cbmpDC);
	DeleteObject(hbmp);
	pcWnd->ReleaseDC(pcDC);
}
开发者ID:HidetomoKataoka,项目名称:SimpleDcmViewer,代码行数:91,代码来源:SimpleDcmViewerDlg.cpp

示例7: CreateDragImage

HBITMAP CLibraryAlbumView::CreateDragImage(const CPoint& ptMouse, CPoint& ptMiddle)
{
	CRect rcClient, rcOne, rcAll( 32000, 32000, -32000, -32000 );

	GetClientRect( &rcClient );

	for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
	{
		CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
		GetItemRect( pTrack, &rcOne );

		if ( rcOne.IntersectRect( &rcClient, &rcOne ) )
		{
			rcAll.left		= min( rcAll.left, rcOne.left );
			rcAll.top		= min( rcAll.top, rcOne.top );
			rcAll.right		= max( rcAll.right, rcOne.right );
			rcAll.bottom	= max( rcAll.bottom, rcOne.bottom );
		}
	}

	BOOL bClipped = rcAll.Height() > MAX_DRAG_SIZE;

	if ( bClipped )
	{
		rcAll.left		= max( rcAll.left, ptMouse.x - MAX_DRAG_SIZE_2 );
		rcAll.right		= max( rcAll.right, ptMouse.x + MAX_DRAG_SIZE_2 );
		rcAll.top		= max( rcAll.top, ptMouse.y - MAX_DRAG_SIZE_2 );
		rcAll.bottom	= max( rcAll.bottom, ptMouse.y + MAX_DRAG_SIZE_2 );
	}

	CClientDC dcClient( this );
	CBitmap bmDrag;
	CDC dcDrag;

	if ( ! dcDrag.CreateCompatibleDC( &dcClient ) )
		return NULL;
	if ( ! bmDrag.CreateCompatibleBitmap( &dcClient, rcAll.Width(), rcAll.Height() ) )
		return NULL;

	CBitmap *pOldDrag = dcDrag.SelectObject( &bmDrag );

	dcDrag.FillSolidRect( 0, 0, rcAll.Width(), rcAll.Height(), DRAG_COLOR_KEY );

	CRgn pRgn;

	ptMiddle.SetPoint( ptMouse.x - rcAll.left, ptMouse.y - rcAll.top );
	if ( bClipped )
	{
		pRgn.CreateEllipticRgn(	ptMiddle.x - MAX_DRAG_SIZE_2, ptMiddle.y - MAX_DRAG_SIZE_2,
								ptMiddle.x + MAX_DRAG_SIZE_2, ptMiddle.y + MAX_DRAG_SIZE_2 );
		dcDrag.SelectClipRgn( &pRgn );
	}

	CDC* pBuffer = CoolInterface.GetBuffer( dcClient, m_szTrack );
	CRect rcBuffer( 0, 0, m_szTrack.cx, m_szTrack.cy );

	CFont* pOldFont = (CFont*)pBuffer->SelectObject( &CoolInterface.m_fntNormal );

	for ( POSITION pos = m_pSelTrack.GetHeadPosition() ; pos ; )
	{
		CLibraryAlbumTrack* pTrack = m_pSelTrack.GetNext( pos );
		GetItemRect( pTrack, &rcOne );
		CRect rcDummy;

		if ( rcDummy.IntersectRect( &rcAll, &rcOne ) )
		{
			pBuffer->FillSolidRect( &rcBuffer, DRAG_COLOR_KEY );
			pTrack->Paint( this, pBuffer, rcBuffer, -1 );
			dcDrag.BitBlt( rcOne.left - rcAll.left, rcOne.top - rcAll.top,
				m_szTrack.cx, m_szTrack.cy, pBuffer, 0, 0, SRCCOPY );
		}
	}

	pBuffer->SelectObject( pOldFont );
	dcDrag.SelectObject( pOldDrag );
	dcDrag.DeleteDC();

	return (HBITMAP) bmDrag.Detach();
}
开发者ID:lemonxiao0,项目名称:peerproject,代码行数:79,代码来源:CtrlLibraryAlbumView.cpp

示例8: DrawBackground

void CCustomToolBar::DrawBackground(CDC& dc, const CRect& crBackground, const CSize& czOffset)
{
	// Override this function to draw a custom background.

	// This function assumes that the caller has done all necessary
	// palette selection into the specified DC.

	// Check if we have a solid color background. If so, then just fill
	// the rectangle with the color.

	// IDEA: It would be more flexible to replace the "solid color" background
	// with a brush background. The brush would be owned by the toolbar.

	if (m_pBackground == NULL)
	{
		// Solid color. Fill the background rectangle.
		dc.FillSolidRect(crBackground, PaletteColor(m_clBackground));
	}
	else
	{
		// Bitmap background. We need to tile the bitmap onto the rectangle.
		// The offset parameter, czOffset, gives the offset from the origin
		// of the tiled background pattern to the origin of the specified DC.

		// Get the dimensions of the background bitmap.
		BITMAP Bitmap;
		if (m_pBackground->GetBitmap(&Bitmap))
		{
			// Create a memory DC to hold the background bitmap.
			CDC dcBitmap;
			if (dcBitmap.CreateCompatibleDC(&dc))
			{
				// Select the background bitmap into the DC.
				CBitmap* pOldBitmap = dcBitmap.SelectObject(m_pBackground);
				if (pOldBitmap != NULL)
				{
					// Compute the origin of the first background tile to
					// use for the fill.
					int nX0 = crBackground.left-((crBackground.left+czOffset.cx) % Bitmap.bmWidth);
					if (nX0 > crBackground.left)
					{
						nX0 -= Bitmap.bmWidth;
					}
					ASSERT(nX0 <= crBackground.left);

					int nY0 = crBackground.top-((crBackground.top+czOffset.cy) % Bitmap.bmHeight);
					if (nY0 > crBackground.top)
					{
						nY0 -= Bitmap.bmHeight;
					}
					ASSERT(nY0 <= crBackground.top);

					// Draw all the tiles required to cover the background. This could
					// be changed to draw to an offscreen bitmap, but I don't see any
					// advantage to this.
					for (int nY = nY0; nY < crBackground.bottom; nY += Bitmap.bmHeight)
					{
						for (int nX = nX0; nX < crBackground.right; nX += Bitmap.bmWidth)
						{
							// Figure out the BitBlt parameters for this tile.
							// This function does not assume that the DC has
							// a clipping region set up for the background
							// rectangle. The following code makes sure that
							// no drawing occurs outside of crBackground.

							int nDestinationX = nX;
							int nDestinationY = nY;
							int nXSize = Bitmap.bmWidth;
							int nYSize = Bitmap.bmHeight;
							int nSourceX = 0;
							int nSourceY = 0;

							// Clip left.
							if (nDestinationX < crBackground.left)
							{
								int nDelta = crBackground.left-nDestinationX;
								nXSize -= nDelta;
								nDestinationX += nDelta;
								nSourceX += nDelta;
							}

							// Clip top.
							if (nDestinationY < crBackground.top)
							{
								int nDelta = crBackground.top-nDestinationY;
								nYSize -= nDelta;
								nDestinationY += nDelta;
								nSourceY += nDelta;
							}

							// Clip right.
							if (nDestinationX+nXSize > crBackground.right)
							{
								nXSize -= nDestinationX+nXSize-crBackground.right;
							}

							// Clip bottom.
							if (nDestinationY+nYSize > crBackground.bottom)
							{
								nYSize -= nDestinationY+nYSize-crBackground.bottom;
//.........这里部分代码省略.........
开发者ID:jimmccurdy,项目名称:ArchiveGit,代码行数:101,代码来源:CustBar.cpp

示例9: DrawButton

void CCustomToolBar::DrawButton(CDC& dc, const CRect& crButton, int nButtonIndex, UINT uButtonID, WORD wButtonStyle, WORD wButtonState)
{
	// Override this function to draw custom buttons.

	// This function assumes that the caller has done all necessary
	// palette selection into the specified DC.

	// Make sure we have a bitmap to draw from.
	if (BitmapInitialized())
	{
		// Figure out which bitmap to use. In general, the button
		// index is not the same as the bitmap index.
		int nBitmapIndex = -1;
		for (int nIndex = 0; nIndex < m_nBitmapIDCount; nIndex++)
		{
			if (m_pBitmapIDArray[nIndex] == uButtonID)
			{
				nBitmapIndex = nIndex;
				break;
			}
		}

		// Draw the bitmap that corresponds to the button ID.
		if (nBitmapIndex != -1)
		{
			// Create a memory DC to hold the bitmap.
			CDC dcBitmap;
			if (dcBitmap.CreateCompatibleDC(&dc))
			{
				// Select the bitmap into the memory DC.
				CBitmap* pOldBitmap = dcBitmap.SelectObject(m_pBitmap);
				if (pOldBitmap != NULL)
				{
					// Figure out which state bitmap to use:
					//
					//		0:		Up			/ Cursor not over button
					//		1:		Up			/ Cursor over button
					//		2:		Down
					//		3:		Checked	/ Cursor not over button
					//		4:		Checked	/ Cursor over button
					//		5:		Disabled	/ Cursor not over button
					//		6:		Disabled	/ Cursor over button

					// Set some state variables.
					BOOL fButtonPressed ((wButtonState & TBSTATE_PRESSED) != 0);
					BOOL fButtonChecked ((wButtonState & TBSTATE_CHECKED) != 0);
					BOOL fButtonEnabled = GetToolBarCtrl().IsButtonEnabled((int)uButtonID);
					BOOL fButtonUnderCursor = IsActive() && (nButtonIndex == m_nLastButtonUnderCursor);

					int nX = nBitmapIndex;
					int nY = 0;
					if (!fButtonEnabled)
					{
						// Button is disabled.
						nY = fButtonUnderCursor ? 6 : 5;
					}
					else if (fButtonChecked)
					{
						// Button is checked.
						nY = fButtonUnderCursor ? 4 : 3;
					}
					else if (fButtonPressed)
					{
						// Button is pressed.
						nY = 2;
					}
					else
					{
						nY = fButtonUnderCursor ? 1 : 0;
					}

					// Draw the bitmap.
					if (m_pBitmapMask == NULL)
					{
						// There are no transparent areas, just copy the button bitmap.
						dc.BitBlt(
							crButton.left,
							crButton.top,
							crButton.Width(),
							crButton.Height(),
							&dcBitmap,
							nX*m_sizeButton.cx,
							nY*m_sizeButton.cy,
							SRCCOPY);
					}
					else
					{
						// There are transparent areas. We need to use the mask to
						// draw transparently.

						// Create a memory DC to hold the monochrome mask bitmap.
						CDC dcBitmapMask;
						if (dcBitmapMask.CreateCompatibleDC(&dcBitmap))
						{
							// Select the monochrom mask bitmap into the DC.
							CBitmap* pOldBitmapMask = dcBitmapMask.SelectObject(m_pBitmapMask);
							if (pOldBitmapMask != NULL)
							{
								// Erase to 0's (black) the areas of the desintation
								// where the opaque portions of the bitmap will be drawn.
//.........这里部分代码省略.........
开发者ID:jimmccurdy,项目名称:ArchiveGit,代码行数:101,代码来源:CustBar.cpp

示例10: OnPaint

void CTreeCtrlX::OnPaint() 
{
	CPaintDC dc(this);

	// Create a memory DC compatible with the paint DC
	CDC memDC;

	memDC.CreateCompatibleDC( &dc );

	CRect rcClip, rcClient;
	dc.GetClipBox( &rcClip );
	GetClientRect(&rcClient);

	// Select a compatible bitmap into the memory DC
	CBitmap bitmap;
	bitmap.CreateCompatibleBitmap( &dc, rcClient.Width(), rcClient.Height() );
	memDC.SelectObject( &bitmap );
	
	// Set clip region to be same as that in paint DC
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcClip );
	memDC.SelectClipRgn(&rgn);
	rgn.DeleteObject();


	// First let the control do its default drawing.
	CWnd::DefWindowProc( WM_PAINT, (WPARAM)memDC.m_hDC, 0 );


	HTREEITEM hItem = GetFirstVisibleItem();

	int n = GetVisibleCount()+1;
	while( hItem && n--)
	{
		CRect rect;

		// Do not meddle with selected items or drop highlighted items
		UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
		Color_Font cf;
	
		if ( !(GetItemState( hItem, selflag ) & selflag ) 
			&& m_mapColorFont.Lookup( hItem, cf ))
		{
			CFont *pFontDC;
			CFont fontDC;
			LOGFONT logfont;

			if( cf.logfont.lfFaceName[0] != '\0' ) 
			{
				logfont = cf.logfont;
			}
			else
			{
				// No font specified, so use window font
				CFont *pFont = GetFont();
				pFont->GetLogFont( &logfont );
			}

			fontDC.CreateFontIndirect( &logfont );
			pFontDC = memDC.SelectObject( &fontDC );

			if( cf.color != (COLORREF)-1 )
				memDC.SetTextColor( cf.color );

			CString sItem = GetItemText( hItem );

			GetItemRect( hItem, &rect, TRUE );
			memDC.SetBkColor( GetSysColor( COLOR_WINDOW ) );
			memDC.TextOut( rect.left+2, rect.top+1, sItem );
			
			memDC.SelectObject( pFontDC );
		}
		hItem = GetNextVisibleItem( hItem );
	}


	dc.BitBlt( rcClip.left, rcClip.top, rcClip.Width(), rcClip.Height(), &memDC, 
				rcClip.left, rcClip.top, SRCCOPY );
}
开发者ID:dougkelly88,项目名称:3rdparty,代码行数:79,代码来源:TreeCtrlX.cpp

示例11: SetButtonBitmaps

BOOL CCustomToolBar::SetButtonBitmaps(LPCTSTR pszResourceName, COLORREF clTransparent, SIZE sizeButton, const UINT* lpIDArray, int nIDCount, HINSTANCE hInstance)
{
	BOOL fResult = FALSE;

	// Free any existing bitmaps.
	FreeBitmaps();

	// Sanity Check.
	ASSERT(lpIDArray != NULL);
	ASSERT(nIDCount > 0);

	TRY
	{
		if ((lpIDArray != NULL)
		 && (nIDCount > 0))
		{
			// Set the button and image sizes for the toolbar.
			// We fake the image size at the minimum value (1,1).
			// For CCustomToolBar, the button and image sizes
			// are always the same.
			ASSERT(sizeButton.cx > 7);
			ASSERT(sizeButton.cy > 6);
			CToolBar::SetSizes(sizeButton, CSize(1, 1));

			// Attempt to load the button bitmaps.
			m_pBitmap = new CBitmap;
         if (Util::LoadResourceBitmap(*m_pBitmap, pszResourceName, m_pPalette, hInstance))
			{
				// Make a copy of the button bitmap ID array.
				m_nBitmapIDCount = nIDCount;
				m_pBitmapIDArray = new UINT[m_nBitmapIDCount];
				memcpy(m_pBitmapIDArray, lpIDArray, m_nBitmapIDCount*sizeof(*lpIDArray));

				// If there's a transparent color, then we need to create a mask bitmap.
				if (clTransparent == (COLORREF)-1)
				{
					// No transparency, so no mask needed.
					m_pBitmapMask = NULL;
					fResult = TRUE;
				}
				else
				{
					// Create a monochrome mask for the button bitmap.

					// Get the bitmap dimensions.
					BITMAP Bitmap;
					if (m_pBitmap->GetBitmap(&Bitmap))
					{
						// Create a DC to hold the bitmap.
						CDC dcBitmap;
						if (dcBitmap.CreateCompatibleDC(NULL))
						{
							// Select our palette into the DC.
							CPalette* pOldPalette;
							SelectPalette(dcBitmap, pOldPalette, TRUE);

							// Select the bitmap into the DC. This will be
							// the "source" DC (color).
							CBitmap* pOldBitmap = dcBitmap.SelectObject(m_pBitmap);
							if (pOldBitmap != NULL)
							{
								// Create the monochrome bitmap for the mask.
								m_pBitmapMask = new CBitmap;
								m_pBitmapMask->CreateBitmap(Bitmap.bmWidth, Bitmap.bmHeight, 1, 1, NULL);

								// Create a DC to hold the mask bitmap.
								CDC dcBitmapMask;
								if (dcBitmapMask.CreateCompatibleDC(&dcBitmap))
								{
									// Select the mask bitmap into the DC. This will be
									// the "destination" DC (monochrome).
									CBitmap* pOldBitmapMask = dcBitmapMask.SelectObject(m_pBitmapMask);
									if (pOldBitmapMask != NULL)
									{
										// Remember the text and background colors set
										// in the source DC. We will be changing them
										// and we'll want to restore them later.
										COLORREF clOldTextColor = dcBitmap.GetTextColor();
										COLORREF clOldBkColor = dcBitmap.GetBkColor();

										// Set the background color of the source DC
										// to the color we want to used for the masked
										// areas. When the color bitmap is copied to
										// the monochrome bitmap, the pixels that match
										// the specified color will be set to 1 in the
										// mask and the other pixels will be set to 0.
										dcBitmap.SetBkColor(PaletteColor(clTransparent));

										// Copy the data. The monochrome mask will be created.
										dcBitmapMask.BitBlt(
											0,
											0,
											Bitmap.bmWidth,
											Bitmap.bmHeight,
											&dcBitmap,
											0,
											0,
											SRCCOPY);

										// Now use the monochrome mask to set all the
//.........这里部分代码省略.........
开发者ID:jimmccurdy,项目名称:ArchiveGit,代码行数:101,代码来源:CustBar.cpp

示例12: OnEditImage

//********************************************************************************
void CButtonAppearanceDlg::OnEditImage() 
{
	ASSERT (m_pImages != NULL);
	ASSERT (m_iSelImage >= 0);

	CSize sizeImage = m_pImages->GetImageSize ();
	const BOOL bIsAlphaImage = m_pImages->GetBitsPerPixel() == 32;

	try
	{
		CClientDC	dc (&m_wndButtonList);
		CBitmap 	bitmap;
		CDC 		memDC;
		memDC.CreateCompatibleDC(&dc);

		if (bIsAlphaImage)
		{
			HBITMAP hbmp = CBCGPDrawManager::CreateBitmap_32(sizeImage, NULL);
			if (hbmp == NULL)
			{
				return;
			}

			bitmap.Attach(hbmp);
		}
		else if (!bitmap.CreateCompatibleBitmap (&dc, sizeImage.cx, sizeImage.cy))
		{
			return;
		}

		const COLORREF clrGrayStd = RGB (192, 192, 192);

		CBitmap* pOldBitmap = memDC.SelectObject (&bitmap);
		COLORREF clrTransparent = m_pImages->SetTransparentColor (clrGrayStd);

		memDC.FillSolidRect (CRect (0, 0, sizeImage.cx, sizeImage.cy), clrGrayStd);

		if (bIsAlphaImage)
		{
			CBCGPDrawManager dm(memDC);
			dm.FillAlpha(CRect (0, 0, sizeImage.cx, sizeImage.cy), 255);
		}

		CBCGPDrawState ds;
		if (!m_pImages->PrepareDrawImage (ds))
		{
			return;
		}

		m_pImages->Draw (&memDC, 0, 0, m_iSelImage);
		m_pImages->EndDrawImage (ds);

		m_pImages->SetTransparentColor (clrTransparent);

		memDC.SelectObject (pOldBitmap);

		BITMAP bmp;
		::GetObject (m_pImages->GetImageWell (), sizeof (BITMAP), (LPVOID)&bmp);

		if (g_pWndCustomize != NULL)
		{
			ASSERT_VALID (g_pWndCustomize);

			if (!g_pWndCustomize->OnEditToolbarMenuImage (this, bitmap, bmp.bmBitsPixel))
			{
				return;
			}
		}
		else
		{
			CBCGPImageEditDlg dlg (&bitmap, this, bmp.bmBitsPixel);
			if (dlg.DoModal () != IDOK)
			{
				return;
			}
		}

		if (bIsAlphaImage)
		{
			CRect rectImage(0, 0, sizeImage.cx, sizeImage.cy);

			CBCGPDrawManager::FillAlpha(rectImage, (HBITMAP)bitmap, 255);
			CBCGPDrawManager::FillTransparentAlpha(rectImage, (HBITMAP)bitmap, clrGrayStd);
		}

		m_pImages->UpdateImage (m_iSelImage, (HBITMAP) bitmap);

		m_wndButtonList.Invalidate ();
	}
	catch (...)
	{
		CBCGPLocalResource locaRes;
		AfxMessageBox (IDP_BCGBARRES_INTERLAL_ERROR);
	}
}
开发者ID:iclosure,项目名称:jframework,代码行数:96,代码来源:ButtonAppearanceDlg.cpp

示例13: OnAddImage

void CButtonAppearanceDlg::OnAddImage() 
{
	CBCGPLocalResource locaRes;

	ASSERT (m_pImages != NULL);

	CSize sizeImage = m_pImages->GetImageSize ();
	const BOOL bIsAlphaImage = m_pImages->GetBitsPerPixel() == 32;

	try
	{
		CClientDC	dc (&m_wndButtonList);
		CBitmap 	bitmap;
		CDC 		memDC;	

		memDC.CreateCompatibleDC(&dc);
		
		if (bIsAlphaImage)
		{
			HBITMAP hbmp = CBCGPDrawManager::CreateBitmap_32(sizeImage, NULL);
			if (hbmp == NULL)
			{
				return;
			}

			bitmap.Attach(hbmp);
		}
		else if (!bitmap.CreateCompatibleBitmap (&dc, sizeImage.cx, sizeImage.cy))
		{
			AfxMessageBox (IDP_BCGBARRES_CANNT_CREATE_IMAGE);
			return;
		}

		CBitmap* pOldBitmap = memDC.SelectObject (&bitmap);

		CRect rect (0, 0, sizeImage.cx, sizeImage.cy);
		memDC.FillRect (CRect (0, 0, sizeImage.cx, sizeImage.cy),
						&globalData.brBtnFace);

		if (bIsAlphaImage)
		{
			CBCGPDrawManager dm(memDC);
			dm.FillAlpha(CRect (0, 0, sizeImage.cx, sizeImage.cy), 255);
		}

		memDC.SelectObject (pOldBitmap);

		BITMAP bmp;
		::GetObject (m_pImages->GetImageWell (), sizeof (BITMAP), (LPVOID)&bmp);

		if (g_pWndCustomize != NULL)
		{
			ASSERT_VALID (g_pWndCustomize);

			if (!g_pWndCustomize->OnEditToolbarMenuImage (this, bitmap, bmp.bmBitsPixel))
			{
				return;
			}
		}
		else
		{
			CBCGPImageEditDlg dlg (&bitmap, this, bmp.bmBitsPixel);
			if (dlg.DoModal () != IDOK)
			{
				return;
			}
		}

		if (bIsAlphaImage)
		{
			CRect rectImage(0, 0, sizeImage.cx, sizeImage.cy);

			CBCGPDrawManager::FillAlpha(rectImage, (HBITMAP)bitmap, 255);
			CBCGPDrawManager::FillTransparentAlpha(rectImage, (HBITMAP)bitmap, globalData.clrBtnFace);
		}

		int iImageIndex = m_pImages->AddImage ((HBITMAP) bitmap);
		if (iImageIndex < 0)
		{
			AfxMessageBox (IDP_BCGBARRES_CANNT_CREATE_IMAGE);
			return;
		}

		RebuildImageList ();
		m_wndButtonList.SelectButton (iImageIndex);
	}
	catch (...)
	{
		AfxMessageBox (IDP_BCGBARRES_INTERLAL_ERROR);
	}
}
开发者ID:iclosure,项目名称:jframework,代码行数:91,代码来源:ButtonAppearanceDlg.cpp

示例14: onCustomDraw

LRESULT UploadQueueFrame::onCustomDraw(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled) {
	if(!BOOLSETTING(SHOW_PROGRESS_BARS)) {
		bHandled = FALSE;
		return 0;
	}

	CRect rc;
	LPNMLVCUSTOMDRAW cd = (LPNMLVCUSTOMDRAW)pnmh;

	switch(cd->nmcd.dwDrawStage) {
	case CDDS_PREPAINT:
		return CDRF_NOTIFYITEMDRAW;
	case CDDS_ITEMPREPAINT:
		return CDRF_NOTIFYSUBITEMDRAW;

	case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
		// Let's draw a box if needed...
		if(ctrlList.findColumn(cd->iSubItem) == UploadQueueItem::COLUMN_TRANSFERRED) {
			// draw something nice...
				TCHAR buf[256];
				UploadQueueItem *ii = (UploadQueueItem*)cd->nmcd.lItemlParam;

				ctrlList.GetItemText((int)cd->nmcd.dwItemSpec, cd->iSubItem, buf, 255);
				buf[255] = 0;

				ctrlList.GetSubItemRect((int)cd->nmcd.dwItemSpec, cd->iSubItem, LVIR_BOUNDS, rc);

				// Text rect
				CRect rc2 = rc;
				rc2.MoveToXY(0, 0);
                rc2.left = 6; // indented with 6 pixels
				rc2.right -= 2; // and without messing with the border of the cell

				// Set references
				CDC cdc;
				cdc.CreateCompatibleDC(cd->nmcd.hdc);
				HBITMAP pOldBmp = cdc.SelectBitmap(CreateCompatibleBitmap(cd->nmcd.hdc,  rc.Width(),  rc.Height()));
				HDC& dc = cdc.m_hDC;

				HFONT oldFont = (HFONT)SelectObject(dc, WinUtil::font);
				SetBkMode(dc, TRANSPARENT);

				CBarShader statusBar(rc.Height(), rc.Width(), SETTING(UPLOAD_BAR_COLOR), ii->getSize());
				statusBar.FillRange(0, ii->getPos(), SETTING(COLOR_DONE));
				statusBar.Draw(cdc, 0, 0, SETTING(PROGRESS_3DDEPTH));

				SetTextColor(dc, SETTING(PROGRESS_TEXT_COLOR_UP));
                ::ExtTextOut(dc, rc2.left, rc2.top + (rc2.Height() - WinUtil::getTextHeight(dc) - 1)/2, ETO_CLIPPED, rc2, buf, _tcslen(buf), NULL);

				SelectObject(dc, oldFont);
				
				BitBlt(cd->nmcd.hdc,rc.left, rc.top, rc.Width(), rc.Height(), dc, 0, 0, SRCCOPY);

				DeleteObject(cdc.SelectBitmap(pOldBmp));
				return CDRF_SKIPDEFAULT;	
		}
		// Fall through
	default:
		return CDRF_DODEFAULT;
	}
}
开发者ID:Dimetro83,项目名称:DC_DDD,代码行数:61,代码来源:UploadQueueFrame.cpp

示例15: TTFAddString

BOOL StringToBitmap::TTFAddString(String_256 *text, UINT32 Xsize, UINT32 Ysize, UINT32 DPI, PLOGFONT pLogFont,
                                  INT32 IntLeading, KernelBitmap **BM, UINT32 ForeColour)
{
    KernelBitmap *Bitmap = *BM;

    /*	HDC ScreenDC = CreateCompatibleDC(NULL);
    	if (ScreenDC == NULL)
    	{
    		ERROR3("StringToBitmap::AddString: Unable to create screen DC");
    		return FALSE;
    	}*/

    CDC SysDisplay;
    BOOL ok=SysDisplay.CreateCompatibleDC(NULL);
    if(!ok)
    {
        //DeleteDC(ScreenDC);
        ERROR3("StringToBitmap::TTF AddString: Unable to create CDC");
        return FALSE;
    }

    HDC ScreenDC = SysDisplay.m_hDC;

    // bodge to get things working with GetBezierFromChar
    INT32 OldlfHeight = pLogFont->lfHeight;
    pLogFont->lfHeight = -(pLogFont->lfHeight - IntLeading);

    UINT32 CurrentPathSizeAlloc = 0;
    Trans2DMatrix *pTransform = NULL;
    DocCoord *pPathCoords = NULL;

    Path *pPath = NULL;
    //pPath = new Path();

    DocCoord *pPolyCordBuffer = NULL;
    PathVerb *pPolyVerbBuffer = NULL;
    UINT32 TextLength = (UINT32)text->Length();
    SIZE StringSize= {0,0};

    // Get handle of font

//	HFONT hNewFont = CreateFontIndirect(pLogFont);
//	HGDIOBJ hOldFont = SelectObject(ScreenDC, hNewFont);

    CFont UnHintedCFont;
    if(!UnHintedCFont.CreateFontIndirect(pLogFont))
    {
        SysDisplay.DeleteDC();
        pLogFont->lfHeight = OldlfHeight;
        return FALSE;
    }

    CFont* pOldCFont=SysDisplay.SelectObject(&UnHintedCFont);

    // Get the default character to use if a charater is not present in the font.
    WCHAR FontDefaultCharacter = (unsigned char)'?';
    TEXTMETRIC FontTextData;
#ifdef _UNCCODE
    if (SysDisplay.GetTextMetrics(&FontTextData))
        FontDefaultCharacter = FontTextData.tmDefaultChar;
#else
    if (SysDisplay.GetTextMetrics(&FontTextData))
        FontDefaultCharacter = (unsigned char)FontTextData.tmDefaultChar;
#endif

    // Work out a nice scaling factor so the font fits in the bitmap ok...

    // Not 32 ?
    GetTextExtentPoint(ScreenDC, *text, TextLength, &StringSize);

    if(StringSize.cy == 0)
    {
        SysDisplay.SelectObject(pOldCFont);
        SysDisplay.DeleteDC();
        pLogFont->lfHeight = OldlfHeight;
        return FALSE;
    }

    //ERROR3IF(!ok, "Initial GetTextExtentPoint32() failed");
    double YScale = ((double)Ysize / (double)StringSize.cy) / (double)2;
    double XScale = YScale;

    // Shift thumbnail upwards, and scale down a bit - to get the g's looking right
    // One or two fonts require this reducing (their tops are clipped), 72000/100 is
    // about right for most of them though...
    // Note the external previews were done with 72000/220 for Matrix and 72000/140 for
    // the capital only fonts.
    double YShift = 72000/100;//72000/80;

    YScale = (YScale * 78) / 100;
    XScale = (XScale * 78) / 100;

    if(!text->IsEmpty())
    {
        const TCHAR* pCurrentChar = (const TCHAR*)(*text);

        while (ok && *pCurrentChar!=0)
        {
            // Get the current character as Unicode.
#ifdef _UNICODE
//.........这里部分代码省略.........
开发者ID:eradman,项目名称:xara-cairo,代码行数:101,代码来源:fontpgen.cpp


注:本文中的CDC::CreateCompatibleDC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。