void CinvadersView::OnDraw(CDC* pDC)
{
	CinvadersDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	//drawbackground
	CBitmap bitmap;
	CDC dcMemory;
	if(pDoc->sp.level==1){
		bitmap.LoadBitmapW(IDB_BITMAP1);}
	if(pDoc->sp.level==2){
		bitmap.LoadBitmapW(IDB_BITMAP2);}
	if(pDoc->sp.level==3){
		bitmap.LoadBitmapW(IDB_BITMAP3);}
	if(pDoc->sp.level==4){
		bitmap.LoadBitmapW(IDB_BITMAP4);}
	if(pDoc->sp.level==5){
		bitmap.LoadBitmapW(IDB_BITMAP5);}
	dcMemory.CreateCompatibleDC(pDC);
	dcMemory.SelectObject(bitmap);



	HICON player;
	HICON alien1;
	HICON alien2;
	HICON alien3;
	HICON alien4;
	HICON pRocket;
	HICON aRocket;
	HICON explo;
	player=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1));
	alien1=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2));
	alien2=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3));
	alien3=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4));
	alien4=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5));
	pRocket=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON6));
	aRocket=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON6));
	explo=LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON7));
	//draw player
	dcMemory.DrawIcon(pDoc->sp.player.left,pDoc->sp.player.top,player);

	//draw rocket
	if(pDoc->sp.pRock==true)dcMemory.DrawIcon(pDoc->sp.pRocket.left,pDoc->sp.pRocket.top,pRocket);
	if(pDoc->sp.aRock==true)dcMemory.DrawIcon(pDoc->sp.aRocket.left,pDoc->sp.aRocket.top,aRocket);

	if(pDoc->sp.exploa==true)dcMemory.DrawIcon(pDoc->sp.pRocket.left,pDoc->sp.pRocket.top,explo);pDoc->sp.exploa=false;
	if(pDoc->sp.explop==true)dcMemory.DrawIcon(pDoc->sp.player.left,pDoc->sp.player.top,explo);pDoc->sp.explop=false;
	//draw invaders
	for(int i=0;i<pDoc->sp.aliens.size();i++){
		if(pDoc->sp.aliens.at(i).i==0){
			dcMemory.DrawIcon(pDoc->sp.aliens.at(i).r.left,pDoc->sp.aliens.at(i).r.top,alien4);}
		if(pDoc->sp.aliens.at(i).i==1){
			dcMemory.DrawIcon(pDoc->sp.aliens.at(i).r.left,pDoc->sp.aliens.at(i).r.top,alien3);}
		if(pDoc->sp.aliens.at(i).i==2){
			dcMemory.DrawIcon(pDoc->sp.aliens.at(i).r.left,pDoc->sp.aliens.at(i).r.top,alien2);}
		if(pDoc->sp.aliens.at(i).i==3){
			dcMemory.DrawIcon(pDoc->sp.aliens.at(i).r.left,pDoc->sp.aliens.at(i).r.top,alien1);}
	}
	//drawscore&level
	dcMemory.TextOutW(200,pDoc->sp.border.bottom-20,pDoc->sp.llvl);
	dcMemory.TextOutW(250,pDoc->sp.border.bottom-20,pDoc->sp.lvl);
	dcMemory.TextOutW(300,pDoc->sp.border.bottom-20,pDoc->sp.lliv);
	dcMemory.TextOutW(350,pDoc->sp.border.bottom-20,pDoc->sp.liv);
	dcMemory.TextOutW(400,pDoc->sp.border.bottom-20,pDoc->sp.str);
	dcMemory.TextOutW(450,pDoc->sp.border.bottom-20,pDoc->sp.scr);
	//drawend
 

	if(pDoc->sp.gameOver==true){
		dcMemory.TextOutW(320,240,pDoc->sp.scr);
	}
	
	pDC->BitBlt(pDoc->sp.border.left,pDoc->sp.border.top,640,480,&dcMemory,0,0,SRCCOPY);	
}
Exemplo n.º 2
0
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();
	}
}
Exemplo n.º 3
0
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));
}
Exemplo n.º 4
0
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();
}
Exemplo n.º 5
0
//-------------------------------------------------------------------------
// 그림파일로 저장
//-------------------------------------------------------------------------
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;
		}
	}
}
Exemplo n.º 6
0
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)
				{
					for (double yp = y >= 0 ? y : 0; yp < End.y && yp < GetCurrentDocument()->GetDetails().GetPageBoundsAsPoint().y; yp += grid)
					{
						dc.SetPixel(CDPoint(xp, yp), 0);
					}
				}
			}
		}

		Start -= CDPoint(10, 10);
		End += CDPoint(10, 10);

		GetCurrentDocument()->GetSelectBegin();

		drawingIterator it = GetCurrentDocument()->GetDrawingBegin();
		while (it != GetCurrentDocument()->GetDrawingEnd())
		{
			CDrawingObject *obj = *it;

			selected = !pDC->IsPrinting() && GetCurrentDocument()->IsSelected(obj);
			paint_options options = selected ? draw_selected : draw_normal;

			if (!pDC->IsPrinting() || !obj->IsConstruction())
			{
				if (pDC->IsPrinting() || obj->IsInside(Start.x, End.x, Start.y, End.y))
				{
					obj->Paint(dc, options);
				}
			}

			++it;
		}

		// Now draw the selectable object, so it stands out...
		CDrawingObject *obj = GetCurrentDocument()->GetSelectable();
		if (obj != NULL && !GetCurrentDocument()->IsSelected(obj))
		{
			paint_options options = draw_selectable;
			GetCurrentDocument()->GetSelectable()->Paint(dc, options);
		}

		// If only one item is selected then just draw its handles now
		if (GetCurrentDocument()->IsSingleItemSelected())
		{
			GetCurrentDocument()->GetSingleSelectedItem()->PaintHandles(dc);
		}

		// if necessary turn back on the current object to be edited
		if (GetCurrentDocument()->GetEdit() != NULL) {
			//ATLTRACE2("TinyCadView::GetCurrentDocument->GetEdit->Paint(dc, draw_selected=%d)\n",draw_selected);
			GetCurrentDocument()->GetEdit()->Paint(dc, draw_selected);
		}

		// Draw the design details
		GetCurrentDocument()->Display(dc);
	}

	if (osb)
	{
		pDC->BitBlt(client.left, client.top, client.Width(), client.Height(), &BitmapDC, 0, 0, SRCCOPY);
		BitmapDC.SelectObject(old_bitmap);
	}
}
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();
}
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);
}
Exemplo n.º 9
0
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.
								// This allows us to OR the button bitmap into the
								// destination.
								COLORREF clOldTextColor = dc.SetTextColor(RGB(0,0,0));    // 0's in mask (opaque) go to 0's
								COLORREF clOldBkColor = dc.SetBkColor(RGB(255,255,255));  // 1's in mask (transparent) go to 1's

								dc.BitBlt(
									crButton.left,
									crButton.top,
									crButton.Width(),
									crButton.Height(),
									&dcBitmapMask,
									nX*m_sizeButton.cx,
									nY*m_sizeButton.cy,
									SRCAND);

								// Restore old colors.
								dc.SetTextColor(clOldTextColor);
								dc.SetBkColor(clOldBkColor);

								// Restore the previously selected bitmap.
								dcBitmapMask.SelectObject(pOldBitmapMask);
								pOldBitmapMask = NULL;

								// OR the button bitmap into the destination.
								// The button bitmap has been preprocessed
								// in SetButtonBitmaps so that the transparent
								// areas are set to 0's. The destination bitmap
								// has already been cleared to 0's for the
								// opaque portions of the bitmap. Thus we can
								// OR the button bitmap data into the destination
								// bitmap data for a transparent effect.

								dc.BitBlt(
									crButton.left,
									crButton.top,
									crButton.Width(),
									crButton.Height(),
									&dcBitmap,
									nX*m_sizeButton.cx,
									nY*m_sizeButton.cy,
									SRCPAINT);
							}

							dcBitmapMask.DeleteDC();
						}
					}
						
					dcBitmap.SelectObject(pOldBitmap);
					pOldBitmap = NULL;
				}

				dcBitmap.DeleteDC();
			}
		}
	}
}
Exemplo n.º 10
0
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;
							}

							if ((nXSize > 0) && (nYSize > 0))
							{
								// Draw the tile (or whatever's left of it after clipping.)
								dc.BitBlt(
									nDestinationX,
									nDestinationY,
									nXSize,
									nYSize,
									&dcBitmap,
									nSourceX,
									nSourceY,
									SRCCOPY);
							}
						}
					}

					dcBitmap.SelectObject(pOldBitmap);
					pOldBitmap = NULL;
				}
			}
		}
	}
}
Exemplo n.º 11
0
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
										// transparent pixels in the original bitmap
										// to 0's (black). The makes easy to OR the
										// color bitmap onto the destination and
										// achieve a transparent effect.
										dcBitmap.SetTextColor(RGB(255,255,255)); // 0's in mask (opaque) go to 1's
										dcBitmap.SetBkColor(RGB(0,0,0));         // 1's in mask (transparent) go to 0's

										dcBitmap.BitBlt(
											0,
											0,
											Bitmap.bmWidth,
											Bitmap.bmHeight,
											&dcBitmapMask,
											0,
											0,
											SRCAND);

										// Restore the colors we changed.
										dcBitmap.SetBkColor(clOldBkColor);
										dcBitmap.SetTextColor(clOldTextColor);

										// Select the old bitmap back in.
										dcBitmapMask.SelectObject(pOldBitmapMask);
										pOldBitmapMask = NULL;

										// Everything worked!
										fResult = TRUE;
									}

									dcBitmapMask.DeleteDC();
								}

								dcBitmap.SelectObject(pOldBitmap);
								pOldBitmap = NULL;

								// Restore the previous palette.
								DeselectPalette(dcBitmap, pOldPalette, TRUE);
							}

							dcBitmap.DeleteDC();
						}
					}
				}
			}
		}
	}
	END_TRY

	if (!fResult)
	{
		// Something did not work. Make sure any allocated memory is freed.
		FreeBitmaps();
	}

	// Redraw ourselves.
	Invalidate();

	return fResult;
}
Exemplo n.º 12
0
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 );
}
Exemplo n.º 13
0
//********************************************************************************
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);
	}
}
Exemplo n.º 14
0
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);
	}
}
Exemplo n.º 15
0
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;
	}
}
Exemplo n.º 16
0
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
            WCHAR wchr = *pCurrentChar;		// pCurrentChar is a pointer to WCHAR in _UNICODE builds
#else
            UINT32 CharToConvert = 0;
            if (UnicodeManager::IsDBCSLeadByte(*pCurrentChar))
                CharToConvert = UnicodeManager::ComposeMultiBytes(*pCurrentChar, *(pCurrentChar+1));
            else
                CharToConvert = (unsigned char)(*pCurrentChar);
            WCHAR wchr = UnicodeManager::MultiByteToUnicode(CharToConvert);
#endif

            // Get positioning information for this character
            ok = GetTextExtentPoint(ScreenDC, *text, (pCurrentChar-(TCHAR*)(*text)), &StringSize);
            ERROR3IF(!ok, "GetTextExtentPoint32() failed");
            if (!ok) break;

            // Get the characters path
            DWORD PathSize = 0;
            ok = TextManager::GetBezierFromChar(&SysDisplay, wchr, pLogFont, &PathSize, (POINT *)NULL, (BYTE *)NULL);
            if (!ok)
            {
                wchr = FontDefaultCharacter;
                ok = TextManager::GetBezierFromChar(&SysDisplay, wchr, pLogFont, &PathSize, (POINT *)NULL, (BYTE *)NULL);
            }
            ERROR3IF(!ok, "GetBezierFromChar returned false");
            if (!ok) break;

            // Pointer to an array of path coordinates
            if(pPolyCordBuffer == NULL)
            {
                TRY
                {
                    pPolyCordBuffer = new DocCoord[PathSize];
                }
                CATCH (CMemoryException, e)
                {
                    pPolyCordBuffer = NULL;
                    /*ERROR(_R(IDS_OUT_OF_MEMORY), FALSE);*/
                }
                END_CATCH
            }

            // Pointer to an array of path verbs
            if(pPolyVerbBuffer == NULL)
            {
                TRY
                {
                    pPolyVerbBuffer = new PathVerb[PathSize];
                }
                CATCH (CMemoryException, e)
                {
                    pPolyVerbBuffer = NULL;
                    /*ERROR(_R(IDS_OUT_OF_MEMORY), FALSE);*/
                }
                END_CATCH
            }

            if (pPolyCordBuffer == NULL || pPolyVerbBuffer == NULL)
            {
                ok = FALSE;
                break;
            }

            CurrentPathSizeAlloc = PathSize;

            // Fill up the buffers until they're bursting with fontyness
            ok = TextManager::GetBezierFromChar(&SysDisplay, wchr, pLogFont, &PathSize, (POINT *)pPolyCordBuffer,
                                                (BYTE *)pPolyVerbBuffer);
            if(!ok) TRACEUSER( "Richard", _T("GetBezierFromChar returned false in second phase...\n"));
            if(!ok)	break;

            // Spaces set PathSize to zero
            if((PathSize > 0)/* && (pPath != NULL)*/)
            {
                pPath = new Path();
                pPath->Initialise(PathSize, 12);
                pPath->CopyPathDataFrom(pPolyCordBuffer, pPolyVerbBuffer, PathSize, TRUE);

                // Major bodge at present with the x spacing...
                Matrix scale(XScale, 0, 0, YScale, (INT32)((XScale*StringSize.cx*72000)/(double)DPI), (INT32)YShift);

                pTransform = new Trans2DMatrix(scale);
                pPathCoords = pPath->GetCoordArray();
                pTransform->Transform( pPathCoords, pPath->GetNumCoords() );
                delete pTransform;

                pPath->InitialiseFlags();

                ok = ALU->GradFillPath(pPath, ForeColour, ForeColour, 0, 0, 0,/*Xsize/2,*/ Ysize, S2BMP_ANTIALIAS);
                ERROR3IF(!ok, "Gradfillpath returned false");
                if(!ok)	break;

                delete pPath;
            }

            // S2BMP_MAGIC is the worderfully fabby constant that mark's getbezierfromchar returns
            // Theory goes that he's going to sort this out sometime...
            if(CurrentPathSizeAlloc != S2BMP_MAGIC)
            {
                delete []pPolyCordBuffer;
                delete []pPolyVerbBuffer;

                pPolyCordBuffer = NULL;
                pPolyVerbBuffer = NULL;
                CurrentPathSizeAlloc = 0;
            }

            pPath = NULL;
            pTransform = NULL;

            pCurrentChar = camStrinc(pCurrentChar);
        }
Exemplo n.º 17
0
void CHexEdit::OnPaint() 
{
	CPaintDC pdc(this); // device context for painting

	CRect rc;
	GetClientRect(rc);
	
	CDC	dc;
	dc.CreateCompatibleDC(CDC::FromHandle(pdc.m_ps.hdc));
	CBitmap bm;

	bm.CreateCompatibleBitmap(CDC::FromHandle(pdc.m_ps.hdc), rc.Width(), rc.Height());
	dc.SelectObject(bm);

	CBrush b;
	b.CreateSolidBrush(RGB(0xff,0xff,0xff));
	dc.FillRect(rc, &b);

	ASSERT(m_currentAddress >= 0);
	ASSERT(m_topindex >= 0);

	dc.SelectObject(m_Font);
	int		height		= 0;
	int		x,y;
	char	buf[256];
    WCHAR   wbuf[256];
	int	 n=0;
	x = rc.TopLeft().x;
	y = rc.TopLeft().y;

	dc.SetBoundsRect(&rc, DCB_DISABLE);

	if(m_pData)
	{
		//
		// get char dimensions
		//
		if(m_bUpdate)
		{
			dc.GetCharWidth('0', '0', &m_nullWidth);
			CSize sz = dc.GetTextExtent(L"0", 1);
			m_lineHeight = sz.cy;
			
			m_offHex	= m_bShowAddress ? (m_bAddressIsWide ? m_nullWidth * 9 : m_nullWidth * 5) : 0;
			m_offAscii	= m_bShowAddress ? (m_bAddressIsWide ? m_nullWidth * 9 : m_nullWidth * 5) : 0;
			m_offAscii += m_bShowHex	 ? (m_bpr * 3 * m_nullWidth) : 0;

			m_lpp = rc.Height() / m_lineHeight;
			m_bHalfPage = FALSE;
			if(m_lpp * m_bpr > m_length)
			{
				m_lpp = (m_length + (m_bpr/2)) / m_bpr ;
				if(m_length % m_bpr != 0)
				{
					m_bHalfPage = TRUE;
					m_lpp++;
				}
			}
			m_bUpdate = FALSE;
			UpdateScrollbars();
		}

		//TRACE("%i %i\n", m_topindex, m_selStart);
		
		height = rc.Height() / m_lineHeight;
		height *= m_lineHeight;

		if(m_bShowAddress)
		{
			char fmt[8] = {'%','0','8','l','X'};
			fmt[2] = m_bAddressIsWide ? '8' : '4';
			int w = m_bAddressIsWide ? 8 : 4;
			y = 0;
			CRect rcd = rc;
			rcd.TopLeft().x = m_offAddress;
			for(int	 i = m_topindex + m_AddOff; (i < m_length+ m_AddOff) && (rcd.TopLeft().y < height); i+= m_bpr)
			{
				sprintf(buf, fmt, i);
				CMySystem::CharToWCHAR(wbuf,buf);
				dc.DrawText(wbuf, w, rcd, DT_LEFT|DT_TOP|DT_SINGLELINE|DT_NOPREFIX);
				rcd.TopLeft().y += m_lineHeight;
			}
		}
		if(m_bShowHex)
		{
			y = 0;
			CRect rcd = rc;
			rcd.TopLeft().x = x = m_offHex;

			if(m_selStart != 0xffffffff && (m_currentMode == EDIT_HIGH || m_currentMode == EDIT_LOW))
			{
				int	 i;
				int	 n = 0;
				int	 selStart = m_selStart, selEnd = m_selEnd;
				if(selStart > selEnd)
					selStart ^= selEnd ^= selStart ^= selEnd;

				for(i = m_topindex ; (i < selStart) && (y < height); i++)
				{
					char* p = &buf[0];
					TOHEX(m_pData[i], p);
					*p++ = ' ';
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 3);
					x += m_nullWidth * 3;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offHex;
						y += m_lineHeight;
					}
				}
				dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
				dc.SetBkColor(GetSysColor(COLOR_HIGHLIGHT));
				for(; (i < selEnd) && (i < m_length) && (y < height); i++)
				{
					char* p = &buf[0];
					TOHEX(m_pData[i], p);
					*p++ = ' ';
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 3);
					x += m_nullWidth * 3;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offHex;
						y += m_lineHeight;
					}
				}
				dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
				dc.SetBkColor(GetSysColor(COLOR_WINDOW));
				for(; (i < m_length) && (y < height); i++)
				{
					char* p = &buf[0];
					TOHEX(m_pData[i], p);
					*p++ = ' ';
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 3);
					x += m_nullWidth * 3;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offHex;
						y += m_lineHeight;
					}
				}
			}
			else
			{
				for(int	 i = m_topindex ; (i < m_length) && (rcd.TopLeft().y < height);)
				{
					char* p = &buf[0];
					for(	 n = 0; (n < m_bpr) && (i < m_length); n++)
					{
						TOHEX(m_pData[i ], p);
						*p++ = ' ';
						i++;
					}
					while(n < m_bpr)
					{
						*p++ = ' ';	*p++ = ' ';	*p++ = ' ';
						n++;
					}
			        CMySystem::CharToWCHAR(wbuf,buf);
					dc.DrawText(wbuf, m_bpr*3, rcd, DT_LEFT|DT_TOP|DT_SINGLELINE|DT_NOPREFIX);
					rcd.TopLeft().y += m_lineHeight;
				}
			}
		}
		if(m_bShowAscii)
		{
			y = 0;
			CRect rcd = rc;
			rcd.TopLeft().x = x = m_offAscii;
			if(m_selStart != 0xffffffff && m_currentMode == EDIT_ASCII)
			{
				int	 i;
				int	 n = 0;
				int	 selStart = m_selStart, selEnd = m_selEnd;
				if(selStart > selEnd)
					selStart ^= selEnd ^= selStart ^= selEnd;

				for(i = m_topindex ; (i < selStart) && (y < height); i++)
				{
					buf[0] = isprint(m_pData[i]) ? m_pData[i] : '.';
				    CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 1);
					x += m_nullWidth;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offAscii;
						y += m_lineHeight;
					}
				}
				dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
				dc.SetBkColor(GetSysColor(COLOR_HIGHLIGHT));
				for(; (i < selEnd) && (y < height); i++)
				{
					buf[0] = isprint(m_pData[i]) ? m_pData[i] : '.';
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 1);
					x += m_nullWidth;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offAscii;
						y += m_lineHeight;
					}
				}
				dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
				dc.SetBkColor(GetSysColor(COLOR_WINDOW));
				for(; (i < m_length) && y < height; i++)
				{
					buf[0] = isprint(m_pData[i]) ? m_pData[i] : '.';
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.TextOut(x, y, wbuf, 1);
					x += m_nullWidth;
					n++;
					if(n == m_bpr)
					{
						n = 0;
						x = m_offAscii;
						y += m_lineHeight;
					}
				}
			}
			else
			{
				for(int	 i = m_topindex ; (i < m_length) && (rcd.TopLeft().y < height);)
				{
					char* p = &buf[0];
					for(	 n = 0; (n < m_bpr) && (i < m_length); n++)
					{
						*p++ = isprint(m_pData[i]) ? m_pData[i] : '.';
						i++;
					}
					CMySystem::CharToWCHAR(wbuf,buf);
					dc.DrawText(wbuf, n, rcd, DT_LEFT|DT_TOP|DT_SINGLELINE|DT_NOPREFIX);
					rcd.TopLeft().y += m_lineHeight;
				}
			}
		}
	}
	pdc.BitBlt(0, 0, rc.Width(), rc.Height(), &dc, 0, 0, SRCCOPY);
}
Exemplo n.º 18
0
void CCustomToolBar::OnNcPaint() 
{
	// Get window DC that we will be drawing into.
	CWindowDC dc(this);

	// Create a DC for the offscreen bitmap. By using an offscreen bitmap
	// we can ensure that there will be no flickering.
	CDC dcOffScreen;
	if (dcOffScreen.CreateCompatibleDC(&dc))
	{
		// Compute the rectangle we will be updating.
		CRect crUpdate;
		GetWindowRect(crUpdate);
		ScreenToClient(crUpdate);

		// The DC we have is for the entire window including the non-client
		// area, so we have to make it zero-based for that area.
		crUpdate.OffsetRect(-crUpdate.left, -crUpdate.top);

		// Create the offscreen bitmap in a format compatible
		// with the destination DC.
		CBitmap OffScreenBitmap;
		if (OffScreenBitmap.CreateCompatibleBitmap(&dc, crUpdate.Width(), crUpdate.Height()))
		{
			// Select our palette into the offscreen DC.
			CPalette* pOldOffScreenPalette;
			SelectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);

			// Select the bitmap into the DC.
			CBitmap* pOldBitmap = dcOffScreen.SelectObject(&OffScreenBitmap);
			if (pOldBitmap != NULL)
			{
				// Draw borders in non-client area.
				CRect crBorder(crUpdate);
				DrawBorder(dcOffScreen, crBorder);

				// Don't allow background to draw over borders.
				dcOffScreen.IntersectClipRect(crBorder);

				// Draw the background.
				CRect crOffset;
				GetWindowRect(crOffset);
				ScreenToClient(crOffset);
				DrawBackground(dcOffScreen, crBorder, CSize(crOffset.left, crOffset.top));

				// We now have the bitmap for the non-client area. We want to
				// copy this onto the window DC without overwriting the client
				// area. To do this we compute the client area and exclude it
				// from the clipping rectangle.
				CRect crClient;
				GetClientRect(crClient);
				crClient.OffsetRect(-crOffset.left, -crOffset.top);
				dc.ExcludeClipRect(crClient);

				// Select our palette into the DC.
				CPalette* pOldPalette;
				SelectPalette(dc, pOldPalette, FALSE);

				// Copy the offscreen bitmap to the destination DC.
				dc.BitBlt(
					crUpdate.left,
					crUpdate.top,
					crUpdate.Width(),
					crUpdate.Height(),
					&dcOffScreen,
					crUpdate.left,
					crUpdate.top,
					SRCCOPY);

				// Restore the previous palette.
				DeselectPalette(dc, pOldPalette, FALSE);

				dcOffScreen.SelectObject(pOldBitmap);
				pOldBitmap = NULL;
			}

			// Cleanup the offscreen bitmap.
			OffScreenBitmap.DeleteObject();
			DeselectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);
		}

		dcOffScreen.DeleteDC();
	}
}
Exemplo n.º 19
0
//绘画界面
void CSkinWndObject::DrawSkinView(CDC * pDC)
{
	//获取参数
	CRect ClientRect;
	m_pWndHook->GetClientRect(&ClientRect);

	//建立缓冲图
	CSkinImage CaptionImage;
	CaptionImage.Create(ClientRect.Width()-2*m_nXExcursionPos,m_SkinAttribute.m_nCaptionHeigth,16);
	if (CaptionImage.IsNull()) return;

	//绘画背景
	CDC BufferDC;
	BufferDC.CreateCompatibleDC(NULL);
	BufferDC.SelectObject(CaptionImage);
	DrawCaption(&BufferDC,CaptionImage.GetWidth(),CaptionImage.GetHeight());

	//建立 DC
	if (pDC==NULL)
	{
		CClientDC ClientDC(m_pWndHook);
		ClientDC.BitBlt(m_nXExcursionPos,1,CaptionImage.GetWidth(),CaptionImage.GetHeight(),&BufferDC,0,0,SRCCOPY);
		ClientDC.Draw3dRect(&ClientRect,RGB(0,0,0),RGB(0,0,0));
		BufferDC.DeleteDC();
	}
	else
	{
		pDC->BitBlt(m_nXExcursionPos,1,CaptionImage.GetWidth(),CaptionImage.GetHeight(),&BufferDC,0,0,SRCCOPY);
		pDC->Draw3dRect(&ClientRect,RGB(0,0,0),RGB(0,0,0));
	}

	//获取标题
	TCHAR strTitle[128];
	GetWindowText(*m_pWndHook,strTitle,CountArray(strTitle));

	//计算位置
	INT nYPos=(m_SkinAttribute.m_nCaptionHeigth-12)/2+2;
	INT nXPos=46;

	//建立缓冲图
	CClientDC ClientDC(m_pWndHook);
	ClientDC.SetBkMode(TRANSPARENT);
	ClientDC.SelectObject(m_SkinAttribute.m_DefaultFont);
	ClientDC.SetTextAlign(TA_LEFT);

	//变量定义
	int nStringLength=lstrlen(strTitle);
	int nXExcursion[8]={1,1,1,0,-1,-1,-1,0};
	int nYExcursion[8]={-1,0,1,1,1,0,-1,-1};

	//绘画边框
	ClientDC.SetTextColor(RGB(0,112,192));
	for (int i=0;i<CountArray(nXExcursion);i++)
	{
		ClientDC.TextOut(nXPos+nXExcursion[i],nYPos+nYExcursion[i],strTitle,nStringLength);
	}

	//绘画标题m_SkinAttribute.m_crCaptionTXColor
	ClientDC.SetTextColor(RGB(255,255,255));
	ClientDC.TextOut(nXPos,nYPos,strTitle);

	BufferDC.DeleteDC();

	return;
}
Exemplo n.º 20
0
void CCustomToolBar::OnPaint() 
{
	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////
	// Copied from CToolBar::OnPaint()

	if (m_bDelayedButtonLayout)
	{
		m_bDelayedButtonLayout = FALSE;
		BOOL bHorz = (m_dwStyle & CBRS_ORIENT_HORZ) != 0;
		if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
			CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT);
		else if (bHorz)
 			CalcDynamicLayout(0, LM_HORZ | LM_HORZDOCK | LM_COMMIT);
		else
			CalcDynamicLayout(0, LM_VERTDOCK | LM_COMMIT);
	}

	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	// Get the rectangle we're going to be drawing.
	CRect crUpdate;
	if (GetUpdateRect(crUpdate))
	{
		// Get the actual device context we will be painting onto.
		CPaintDC dc(this);

		// Select out palette into the DC.
		CPalette* pOldPalette;
		SelectPalette(dc, pOldPalette, FALSE);

		// We construct an offscreen bitmap with the contents
		// to copy onto the final DC. This should avoid all flicker.

		// Create a DC for the offscreen bitmap.
		CDC dcOffScreen;
		if (dcOffScreen.CreateCompatibleDC(&dc))
		{
			// Create the offscreen bitmap in a format compatible
			// with the destination DC.
			CBitmap OffScreenBitmap;
			if (OffScreenBitmap.CreateCompatibleBitmap(&dc, crUpdate.Width(), crUpdate.Height()))
			{
				// Select our palette into the offscreen DC.
				CPalette* pOldOffScreenPalette;
				SelectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);

				// Select the bitmap into the DC.
				CBitmap* pOldBitmap = dcOffScreen.SelectObject(&OffScreenBitmap);
				if (pOldBitmap != NULL)
				{
					// Offset the origin of the offscreen DC to match
					// the coordinate system of the final destination DC.
					dcOffScreen.OffsetWindowOrg(crUpdate.left, crUpdate.top);

					// Draw the background (DrawBackground() is virtual.)
					DrawBackground(dcOffScreen, crUpdate, CSize(0,0));

					int nButtons = GetToolBarCtrl().GetButtonCount();

					for (int nButton = 0; nButton < nButtons; nButton++)
					{
						// Get the bounding rectangle of the button.
						CRect crButton;
						GetItemRect(nButton, crButton);

						// Check if the button is in the update region. If not, then
						// there's nothing to draw.
						CRect crIntersect;
						if (crIntersect.IntersectRect(crButton, crUpdate))
						{
							// Get the button information.
							UINT uButtonID;
							UINT uButtonStyleState;
							int nButtonBitmap;
							GetButtonInfo(nButton, uButtonID, uButtonStyleState, nButtonBitmap);
							WORD wButtonStyle = LOWORD(uButtonStyleState);
							WORD wButtonState = HIWORD(uButtonStyleState);

							// If the button is hidden, then there's nothing to draw.
							if ((wButtonState & TBSTATE_HIDDEN) == 0)
							{
								if (wButtonStyle == TBSTYLE_SEP)
								{
									// Draw the separator (DrawSeparator() is virtual.)
									DrawSeparator(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState);
								}
								else
								{
									// Draw the button (DrawButton() is virtual.)
									DrawButton(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState);
								}
							}
						}
					}

					// Copy the offscreen bitmap to the destination DC.
					dc.BitBlt(
						crUpdate.left,
						crUpdate.top,
						crUpdate.Width(),
						crUpdate.Height(),
						&dcOffScreen,
						crUpdate.left,
						crUpdate.top,
						SRCCOPY);

					dcOffScreen.SelectObject(pOldBitmap);
					pOldBitmap = NULL;
				}

				// Clean up the offscreen bitmap and DC.
				OffScreenBitmap.DeleteObject();
				DeselectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);
			}

			dcOffScreen.DeleteDC();
		}

		DeselectPalette(dc, pOldPalette, FALSE);
	}
}
Exemplo n.º 21
0
void CMaskedBitmap::DrawTransparent(CDC *pDC, int x, int y,
	COLORREF clrTransparency)
{
    BITMAP bm;
    GetBitmap (&bm);
    CPoint size (bm.bmWidth, bm.bmHeight);
    pDC->DPtoLP (&size);

    CPoint org (0, 0);
    pDC->DPtoLP (&org);

	//
    // Create a memory DC (dcImage) and select the bitmap into it.
	//
    CDC dcImage;
    dcImage.CreateCompatibleDC (pDC);
    CBitmap* pOldBitmapImage = dcImage.SelectObject (this);
    dcImage.SetMapMode (pDC->GetMapMode ());

	//
    // Create a second memory DC (dcAnd) and in it create an AND mask.
	//
    CDC dcAnd;
    dcAnd.CreateCompatibleDC (pDC);
    dcAnd.SetMapMode (pDC->GetMapMode ());

    CBitmap bitmapAnd;
    bitmapAnd.CreateBitmap (bm.bmWidth, bm.bmHeight, 1, 1, NULL);
    CBitmap* pOldBitmapAnd = dcAnd.SelectObject (&bitmapAnd);

    dcImage.SetBkColor (clrTransparency);
    dcAnd.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y,
        SRCCOPY);

	//
    // Create a third memory DC (dcXor) and in it create an XOR mask.
	//
    CDC dcXor;
    dcXor.CreateCompatibleDC (pDC);
    dcXor.SetMapMode (pDC->GetMapMode ());

    CBitmap bitmapXor;
    bitmapXor.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight);
    CBitmap* pOldBitmapXor = dcXor.SelectObject (&bitmapXor);

    dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcImage, org.x, org.y,
        SRCCOPY);

    dcXor.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,
        0x220326);

	//
    // Copy the pixels in the destination rectangle to a temporary
    // memory DC (dcTemp).
	//
    CDC dcTemp;
    dcTemp.CreateCompatibleDC (pDC);
    dcTemp.SetMapMode (pDC->GetMapMode ());

    CBitmap bitmapTemp;
    bitmapTemp.CreateCompatibleBitmap (&dcImage, bm.bmWidth, bm.bmHeight);
    CBitmap* pOldBitmapTemp = dcTemp.SelectObject (&bitmapTemp);

    dcTemp.BitBlt (org.x, org.y, size.x, size.y, pDC, x, y, SRCCOPY);

	//
    // Generate the final image by applying the AND and XOR masks to
    // the image in the temporary memory DC.
	//
    dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcAnd, org.x, org.y,
        SRCAND);

    dcTemp.BitBlt (org.x, org.y, size.x, size.y, &dcXor, org.x, org.y,
        SRCINVERT);

	//
    // Blit the resulting image to the screen.
	//
    pDC->BitBlt (x, y, size.x, size.y, &dcTemp, org.x, org.y, SRCCOPY);

	//
    // Restore the default bitmaps.
	//
    dcTemp.SelectObject (pOldBitmapTemp);
    dcXor.SelectObject (pOldBitmapXor);
    dcAnd.SelectObject (pOldBitmapAnd);
    dcImage.SelectObject (pOldBitmapImage);
}
Exemplo n.º 22
0
BOOL CSkinProgress::SetBitmap(
    CBitmap *pTempBitmap,
    BOOL bDisplay)
{
    BITMAP sBmpSrc;
    HGDIOBJ hOldBitmap;
    HGDIOBJ hOldStretch;
    CRect WndRect;
    CDC BmpDC;
    CDC StretchDC;

    mPaintRect.SetRect(0, 0, 0, 0);

    GetClientRect(&WndRect);

    CPaintDC PaintDC(CWnd::FromHandle(m_hWnd));

    if (mpBaseBmp != NULL)
        delete mpBaseBmp;

    mpBaseBmp = new CBitmap;

    if (mpCompatibleBmp != NULL)
        delete mpCompatibleBmp;

    mpCompatibleBmp = new CBitmap;

    if (pTempBitmap == NULL)
        return FALSE;

    CopyBitmap(mpBaseBmp, pTempBitmap);

    ConvertBitmap(mpCompatibleBmp, mpBaseBmp, &PaintDC);

    mpCompatibleBmp->GetBitmap(&sBmpSrc);
    mnBmpWidth  = sBmpSrc.bmWidth / SKIN_PROGRESS_BITMAP_COUNT;
    mnBmpHeight = sBmpSrc.bmHeight;

    if (mpStretchBmp != NULL)
        delete mpStretchBmp;

    mpStretchBmp = new CBitmap;

    mpStretchBmp->CreateCompatibleBitmap(&PaintDC, sBmpSrc.bmWidth, WndRect.Height() - 2);

    BmpDC.CreateCompatibleDC(&PaintDC);
    hOldBitmap = BmpDC.SelectObject(*mpCompatibleBmp);

    StretchDC.CreateCompatibleDC(&PaintDC);
    hOldStretch = StretchDC.SelectObject(*mpStretchBmp);

    StretchDC.SetStretchBltMode(HALFTONE);

    StretchDC.StretchBlt(0, 0, sBmpSrc.bmWidth, WndRect.Height() - 2,&BmpDC, 0, 0, sBmpSrc.bmWidth, sBmpSrc.bmHeight, SRCCOPY);

    StretchDC.SelectObject(hOldStretch);
    StretchDC.DeleteDC();

    BmpDC.SelectObject(hOldBitmap);
    BmpDC.DeleteDC();

    mpStretchBmp->GetBitmap(&sBmpSrc);

    mnBmpWidth  = sBmpSrc.bmWidth / SKIN_PROGRESS_BITMAP_COUNT;
    mnBmpHeight = sBmpSrc.bmHeight;

    mBarImageList.Detach();

    if(!mBarImageList.Create(mnBmpWidth, mnBmpHeight, ILC_COLOR32, 0, 0))
    {
        return false;
    } else
    {
        mBarImageList.Add(mpStretchBmp, RGB(0, 255, 255));

        if (bDisplay != false)
        {
            OnCalcPos();
        }

        return true;
    }
}
Exemplo n.º 23
0
void cMarketImage::LoadRemoteImages( int iGroup, bool bShowPurchased, LPCSTR szOrderBy, int page, int itemsperpage, bool bThumbnailsUpdate )
{
	if ( m_pParent ) 
	{ 
		//m_pParent->m_textNoItems.ShowWindow( SW_HIDE );
		m_pParent->CancelRefresh();
	}

	for ( int i = 0; i <= MAX_ITEMS_PER_PAGE; i++ ) m_dwObjID [ i ] = 0;

	m_iItemClicked = -1;

	m_Images.DeleteImageList ( );
	m_Images.Create     ( 64, 64, ILC_COLOR32 | ILC_MASK, 1, 16 );
	//m_Images.SetBkColor ( RGB ( 255, 255, 255 ) );
	
	DeleteAllItems ( );
	SetImageList ( &m_Images, LVSIL_NORMAL );
	SetIconSpacing( 0, 130 );

	SetRedraw( FALSE );

	int iGroupID = 0;
	MarketGroup *pGroup = NULL;
	MarketObject *pObject = NULL;

	bool bIsSearch = false;
	bool bIsCart = false;
	bool bIsRoot = false;
	bool bIsItems = false;

	bool bNeedThumbnailUpdate = false;
	CString sThumbnailsNeeded = "";
	
	if ( iGroup == 0 ) bIsRoot = true;
	else if ( iGroup == -1 ) bIsSearch = true;
	else if ( iGroup == -2 ) bIsCart = true;
	else if ( iGroup == -3 ) bIsItems = true;
	else if ( iGroup == -4 ) iGroupID = -4;
	else
	{
		pGroup = MarketObject::GetGroup( iGroup );
		if ( pGroup ) iGroupID = pGroup->dwGroupID;
	}

	int imageCount = 0;
	int count = 0;

	if ( bIsRoot || bIsItems || (pGroup && pGroup->pChildGroup) )
	{
		bool bIsArtistList = false;

		MarketGroup *pChild;
		if ( pGroup ) pChild = pGroup->pChildGroup;
		else if ( bIsItems ) { pChild = MarketObject::GetGroupList(); bIsArtistList = true; }
		else if ( bIsRoot )
		{
			//main menu
			CBitmap bmpFolder;
			bmpFolder.LoadBitmap( IDB_FOLDER_ICON );

			m_Images.Add( &bmpFolder, (CBitmap*)NULL );
			imageCount++;

			CString sSearchResults = GetLanguageData( "TGC Store", "SearchResults" );
			CString sShoppingCart = GetLanguageData( "TGC Store", "ShoppingCart" );
			CString sFreeItems = GetLanguageData( "TGC Store", "FreeItems" );
			CString sOnlineItems = GetLanguageData( "TGC Store", "OnlineItems" );

			sSearchResults += "\\";
			sShoppingCart += "\\";
			sFreeItems += "\\";
			sOnlineItems += "\\";

			InsertItem ( 0, sSearchResults, 0 );
			InsertItem ( 1, sShoppingCart, 0 );
			InsertItem ( 2, sOnlineItems, 0 );
			
			SetRedraw( TRUE );
			Invalidate( );
			return;
		}

		int iGroupCount = 0;

		while ( pChild )
		{
			iGroupCount++;
			pChild = pChild->pNextGroup;
		}

		MarketGroup** pSortedGroupList = new MarketGroup* [ iGroupCount ];

		if ( pGroup ) pChild = pGroup->pChildGroup;
		else pChild = MarketObject::GetGroupList();
		iGroupCount = 0;

		while ( pChild )
		{
			pSortedGroupList [ iGroupCount ] = pChild;
			iGroupCount++;
			pChild = pChild->pNextGroup;
		}

		::sort( pSortedGroupList, pSortedGroupList + iGroupCount, cmpG );

		CBitmap bmpFolder;
		bmpFolder.LoadBitmap( IDB_FOLDER_ICON );

		m_Images.Add( &bmpFolder, (CBitmap*)NULL );
		imageCount++;

		if ( bIsArtistList )
		{
			bool bNeedImages = false;

			for( int i=0; i < iGroupCount; i++ )
			{
				CString sName = pSortedGroupList [ i ]->szName;

				EnterCriticalSection( &theApp.m_csDirectoryChanges );
				SetCurrentDirectory( theApp.m_szDirectory );
				CString path = "Files\\TGCStore\\TEMP\\Artists\\";
				path += sName;
				path += ".bmp";
				CImage image;
				HRESULT hr = image.Load( path );
				LeaveCriticalSection( &theApp.m_csDirectoryChanges );

				sName += "\\";

				if ( FAILED(hr) )
				{
					InsertItem ( count++, sName, 0 );
					bNeedImages = true;
				}
				else
				{
					CWindowDC wndDC( this );
					CDC dc;
					dc.CreateCompatibleDC( &wndDC );

					CBitmap	bitmap; bitmap.CreateBitmap( 64,64, 1, 32, NULL );
					CBitmap *oldBmp = dc.SelectObject( &bitmap );

					image.StretchBlt( dc.GetSafeHdc( ), 0,0, 64,64 );
					dc.SelectObject( oldBmp );

					m_Images.Add( &bitmap, (CBitmap*)NULL );
					InsertItem ( count++, sName, imageCount++ );
				}
			}

			if ( bNeedImages && m_pParent && !m_pParent->AreArtistIconsLoaded() ) m_pParent->SetTimer( 5, 1000, NULL );
		}
		else
		{
			for( int i=0; i < iGroupCount; i++ )
			{
				CString sName = pSortedGroupList [ i ]->szName;
				sName += "\\";
				InsertItem ( count++, sName, 0 );
			}
		}

		delete [] pSortedGroupList;
	}

	CBitmap bmpNoThumbnail;
	bmpNoThumbnail.LoadBitmap( IDB_NO_THUMBNAIL );
	m_Images.Add( &bmpNoThumbnail, (CBitmap*)NULL );
	int iNoThumbnailIcon = imageCount;
	imageCount++;

	if ( bIsSearch ) pObject = MarketObject::GetSearchList( );
	else if ( bIsCart ) pObject = MarketObject::GetCartList( );
	else pObject = MarketObject::GetObjectList( );

	int iObjCount = 0;

	while ( pObject )
	{
		if ( ( bShowPurchased || !pObject->IsPurchased() ) && ( bIsSearch || bIsCart || iGroupID == -4 || pObject->GetGroupID( ) == iGroupID ) )
		{
			iObjCount++;
		}

		pObject = pObject->pNextObject;
	}

	if ( iObjCount == 0 && count == 0 )
	{
		//InsertItem ( 0, "<No Items>", -1 );
		if ( m_pParent ) m_pParent->ShowNoItemsMsg();
		if ( m_pParent ) m_pParent->SetPageNumbers( 1,1 );

		SetRedraw( TRUE );
		Invalidate();
		m_pParent->m_textNoItems.Invalidate();
		return;
	}

	if ( iObjCount == 0 )
	{
		if ( m_pParent ) m_pParent->SetPageNumbers( 1,1 );
	}
	else
	{
		if ( bIsSearch ) pObject = MarketObject::GetSearchList( );
		else if ( bIsCart ) pObject = MarketObject::GetCartList( );
		else pObject = MarketObject::GetObjectList( );

		MarketObject **pSortedList = new MarketObject* [ iObjCount ];
		iObjCount = 0;

		while ( pObject )
		{
			if ( ( bShowPurchased || !pObject->IsPurchased() ) && ( bIsSearch || bIsCart || iGroupID == -4 || pObject->GetGroupID( ) == iGroupID ) )
			{
				pSortedList [ iObjCount ] = pObject;
				iObjCount++;
			}

			pObject = pObject->pNextObject;
		}

		if ( szOrderBy && strlen( szOrderBy ) > 0 )
		{
			MarketObject::SetSortIndex( szOrderBy );

			::sort( pSortedList, pSortedList + iObjCount, cmpO );
		}

		//HZIP zpImages = OpenZip( "Files\\TGCStore\\TEMP\\Thumbnails.zip", NULL );
		//if ( !zpImages ) MessageBox( "Failed to open image zip" );
		//int count = 0;
		//int imageCount = 0;

		int start = 0;
		int end = iObjCount;
		if ( itemsperpage > 0 ) 
		{
			int iMaxPage = (iObjCount-1) / itemsperpage + 1;
			if ( page > iMaxPage ) page = iMaxPage;
			if ( page < 1 ) page = 1;

			if ( m_pParent ) m_pParent->SetPageNumbers( page, iMaxPage );

			if ( iObjCount > itemsperpage )
			{
				start = (page-1) * itemsperpage; 
				end = (page * itemsperpage);
				if ( end > iObjCount ) end = iObjCount;
			}
		}
		
		for ( int i = start; i < end; i++ )
		{
			pObject = pSortedList [ i ];

			try
			{
				if ( !pObject->GetThumbnail( ) ) throw 1;
			
				/*
				int iIndex = -1;
				ZRESULT result = FindZipItem( zpImages, pObject->GetThumbnail( ), true, &iIndex, NULL );
				if ( result != ZR_OK )
				{
					//char str [ 32 ];
					//sprintf_s( str, 32, "Error: %d", result );
					//MessageBox( str );
					//MessageBox( pObject->GetThumbnail( ) );
				}

				if ( iIndex < 0 ) throw 2;
				*/

				EnterCriticalSection( &theApp.m_csDirectoryChanges );

				SetCurrentDirectory( theApp.m_szDirectory );

				CString path = "Files\\TGCStore\\TEMP\\Thumbnails\\";
				path += pObject->GetThumbnail( );
				
				CImage image;
				HRESULT hr = image.Load( path );
				
				LeaveCriticalSection( &theApp.m_csDirectoryChanges );

				if ( FAILED(hr) )
				{
					if ( bNeedThumbnailUpdate ) sThumbnailsNeeded += ";";
					char szID [ 12 ];
					sprintf_s( szID, 12, "%d", pObject->GetID() );
					sThumbnailsNeeded += szID;
					bNeedThumbnailUpdate = true;
					throw 3;
				}

				CWindowDC wndDC( this );
				CDC dc;
				dc.CreateCompatibleDC( &wndDC );

				CBitmap	bitmap; bitmap.CreateBitmap( 64,64, 1, 32, NULL );
				CBitmap *oldBmp = dc.SelectObject( &bitmap );

				image.StretchBlt( dc.GetSafeHdc( ), 0,0, 64,64 );
				dc.SelectObject( oldBmp );

				m_Images.Add( &bitmap, (CBitmap*)NULL );
				//bitmap.DeleteObject( );

				InsertItem ( count, pObject->GetName( ), imageCount );
				if ( count <= MAX_ITEMS_PER_PAGE ) m_dwObjID [ count ] = pObject->GetID();
				count++;
				imageCount++;
			}
			catch ( int )
			{
				InsertItem ( count, pObject->GetName( ), iNoThumbnailIcon );
				if ( count <= MAX_ITEMS_PER_PAGE ) m_dwObjID [ count ] = pObject->GetID();
				count++;
			}
		}

		delete [] pSortedList;

//		CloseZip( zpImages );

		//SetCurrentDirectory( szOldDir );
	}

	if ( bNeedThumbnailUpdate && !bThumbnailsUpdate )
	{
		if ( m_pParent ) m_pParent->UpdateThumbnails( sThumbnailsNeeded );
	}

	SetRedraw( TRUE );
	Invalidate( );
	m_pParent->m_textNoItems.Invalidate();
}
HRGN CSplashScreenEx::CreateRgnFromBitmap(HBITMAP hBmp, COLORREF color)
{
	// this code is written by Davide Pizzolato

	if (!hBmp) return NULL;

	BITMAP bm;
	GetObject( hBmp, sizeof(BITMAP), &bm );	// get bitmap attributes

	CDC dcBmp;
	dcBmp.CreateCompatibleDC(GetDC());	//Creates a memory device context for the bitmap
	dcBmp.SelectObject(hBmp);			//selects the bitmap in the device context

	const DWORD RDHDR = sizeof(RGNDATAHEADER);
	const DWORD MAXBUF = 40;		// size of one block in RECTs
	// (i.e. MAXBUF*sizeof(RECT) in bytes)
	LPRECT	pRects;								
	DWORD	cBlocks = 0;			// number of allocated blocks

	INT		i, j;					// current position in mask image
	INT		first = 0;				// left position of current scan line
	// where mask was found
	bool	wasfirst = false;		// set when if mask was found in current scan line
	bool	ismask;					// set when current color is mask color

	// allocate memory for region data
	RGNDATAHEADER* pRgnData = (RGNDATAHEADER*)new BYTE[ RDHDR + ++cBlocks * MAXBUF * sizeof(RECT) ];
	memset( pRgnData, 0, RDHDR + cBlocks * MAXBUF * sizeof(RECT) );
	// fill it by default
	pRgnData->dwSize	= RDHDR;
	pRgnData->iType		= RDH_RECTANGLES;
	pRgnData->nCount	= 0;
	for ( i = 0; i < bm.bmHeight; i++ )
		for ( j = 0; j < bm.bmWidth; j++ ){
			// get color
			ismask=(dcBmp.GetPixel(j,bm.bmHeight-i-1)!=color);
			// place part of scan line as RECT region if transparent color found after mask color or
			// mask color found at the end of mask image
			if (wasfirst && ((ismask && (j==(bm.bmWidth-1)))||(ismask ^ (j<bm.bmWidth)))){
				// get offset to RECT array if RGNDATA buffer
				pRects = (LPRECT)((LPBYTE)pRgnData + RDHDR);
				// save current RECT
				pRects[ pRgnData->nCount++ ] = CRect( first, bm.bmHeight - i - 1, j+(j==(bm.bmWidth-1)), bm.bmHeight - i );
				// if buffer full reallocate it
				if ( pRgnData->nCount >= cBlocks * MAXBUF ){
					LPBYTE pRgnDataNew = new BYTE[ RDHDR + ++cBlocks * MAXBUF * sizeof(RECT) ];
					memcpy( pRgnDataNew, pRgnData, RDHDR + (cBlocks - 1) * MAXBUF * sizeof(RECT) );
					delete pRgnData;
					pRgnData = (RGNDATAHEADER*)pRgnDataNew;
				}
				wasfirst = false;
			} else if ( !wasfirst && ismask ){		// set wasfirst when mask is found
				first = j;
				wasfirst = true;
			}
		}
		dcBmp.DeleteDC();	//release the bitmap
		// create region
		/*  Under WinNT the ExtCreateRegion returns NULL (by [email protected]) */
		//	HRGN hRgn = ExtCreateRegion( NULL, RDHDR + pRgnData->nCount * sizeof(RECT), (LPRGNDATA)pRgnData );
		/* ExtCreateRegion replacement { */
		HRGN hRgn=CreateRectRgn(0, 0, 0, 0);
		ASSERT( hRgn!=NULL );
		pRects = (LPRECT)((LPBYTE)pRgnData + RDHDR);
		for(i=0;i<(int)pRgnData->nCount;i++)
		{
			HRGN hr=CreateRectRgn(pRects[i].left, pRects[i].top, pRects[i].right, pRects[i].bottom);
			VERIFY(CombineRgn(hRgn, hRgn, hr, RGN_OR)!=ERROR);
			if (hr) DeleteObject(hr);
		}
		ASSERT( hRgn!=NULL );
		/* } ExtCreateRegion replacement */

		delete pRgnData;
		return hRgn;
}
void CopyBmpToDC(CDC* pMemDC, CBitmap* pBmp, int nWidth, int nHeight, BOOL bStretch /*= FALSE*/,
                 int left/*=LEFT_WIDTH*/, int right /*= RIGHT_WIDTH*/, BOOL Transparent/*= TRUE*/,
                 BOOL Tile/*=FALSE*/) {
    CDC tDC;

    if (!tDC.CreateCompatibleDC(pMemDC)) {
        return;
    }

    BITMAP l_bmpObj = {0};
    pBmp->GetObject(sizeof(l_bmpObj), &l_bmpObj);
    CBitmap* pOldBmp = tDC.SelectObject(pBmp);
    pMemDC->SetStretchBltMode(COLORONCOLOR);

    if (nWidth < left + right || bStretch) {
        if (Transparent) {
            TransparentBlt(*pMemDC, 0, 0, nWidth, nHeight, tDC, 0, 0, l_bmpObj.bmWidth, l_bmpObj.bmHeight,
                           RGB(0xff, 0, 0xff));
        } else {
            StretchBlt(*pMemDC, 0, 0, nWidth, nHeight, tDC, 0, 0, l_bmpObj.bmWidth, l_bmpObj.bmHeight,
                       SRCCOPY);
        }
    } else {
        if (Transparent) {
            TransparentBlt(*pMemDC, 0, 0, left, nHeight, tDC, 0, 0, left, l_bmpObj.bmHeight, RGB(0xff, 0,
                           0xff));
            TransparentBlt(*pMemDC, nWidth - right, 0, right, nHeight, tDC, l_bmpObj.bmWidth - right, 0, right,
                           l_bmpObj.bmHeight, RGB(0xff, 0, 0xff));
        } else {
            StretchBlt(*pMemDC, 0, 0, left, nHeight, tDC, 0, 0, left, l_bmpObj.bmHeight, SRCCOPY);
            StretchBlt(*pMemDC, nWidth - right, 0, right, nHeight, tDC, l_bmpObj.bmWidth - right, 0, right,
                       l_bmpObj.bmHeight, SRCCOPY);
        }

        if (Tile) {
            CRect rcBmp(left, 0, l_bmpObj.bmWidth - right, l_bmpObj.bmHeight);

            int start = left;
            int len = nWidth - right;

            while (start < len) {
                if (Transparent) {
                    TransparentBlt(*pMemDC, start, 0, min(rcBmp.Width(), len - start), nHeight, tDC, rcBmp.left, 0,
                                   min(rcBmp.Width(), len - start), l_bmpObj.bmHeight, RGB(0xff, 0, 0xff));
                } else {
                    StretchBlt(*pMemDC, start, 0, min(rcBmp.Width(), len - start), nHeight, tDC, rcBmp.left, 0,
                               min(rcBmp.Width(), len - start), l_bmpObj.bmHeight , SRCCOPY);
                }

                start += rcBmp.Width();
            }
        } else {
            if (Transparent) {
                TransparentBlt(*pMemDC, left, 0, nWidth - left - right, nHeight, tDC, left, 0,
                               l_bmpObj.bmWidth - left - right, l_bmpObj.bmHeight, RGB(0xff, 0, 0xff));
            } else {
                StretchBlt(*pMemDC, left, 0, nWidth - left - right, nHeight, tDC, left, 0,
                           l_bmpObj.bmWidth - left - right, l_bmpObj.bmHeight, SRCCOPY);
            }
        }


    }

    tDC.SelectObject(pOldBmp);
    tDC.DeleteDC();
}
Exemplo n.º 26
0
BOOL CBackgroundUtil::TileBitmap(
	CDC* pDC, 
	CRect rc
) {
	CDC MemDC;

	// If there is a bitmap loaded
	if (m_BmpPattern.m_hObject != NULL)
	{
		MemDC.CreateCompatibleDC(pDC);
		CBitmap* pOldBitmap = MemDC.SelectObject(&m_BmpPattern);

		// Clip the tiling to the requested rect.
		// Convert from screen coords to logical coords...
		CRgn rgn;
		CRect rectRgn = rc;
		pDC->DPtoLP( &rectRgn );
		rgn.CreateRectRgn(
			rectRgn.TopLeft().x, 
			rectRgn.TopLeft().y, 
			rectRgn.BottomRight().x, 
			rectRgn.BottomRight().y
		); 
		pDC->SelectClipRgn( &rgn ); 

		if ( m_BkgndStyle == BDBS_TILE )
		{
			// Tile the bitmap.
			// Note that it has to be offset as needed, but
			// we want to make sure we still tile the whole client area.

			// actual xoffset = -xoff + (xoff/xbmp)*xbmp
			int x = - m_nXOffset + ( m_nXOffset / m_nBmpWidth  ) * m_nBmpWidth ;
			int y = - m_nYOffset + ( m_nYOffset / m_nBmpHeight ) * m_nBmpHeight;

			while ( y < rc.Height() ) 
			{
				while( x < rc.Width() ) 
				{
					pDC->BitBlt(x, y, m_nBmpWidth, m_nBmpHeight, &MemDC, 0, 0, SRCCOPY);
					x += m_nBmpWidth;
				}
				x = - m_nXOffset + ( m_nXOffset / m_nBmpWidth  ) * m_nBmpWidth ;
				y += m_nBmpHeight;
			}
		
		} else if ( m_BkgndStyle == BDBS_CENTER )
		{
			pDC->BitBlt(
				m_nXOffset + ( rc.Width()  - m_nBmpWidth  ) / 2, 
				m_nYOffset + ( rc.Height() - m_nBmpHeight ) / 2, 
				m_nBmpWidth, 
				m_nBmpHeight, 
				&MemDC, 
				0, 
				0, 
				SRCCOPY
			);		
		}

		MemDC.SelectObject(pOldBitmap);

		pDC->SelectClipRgn( NULL ); 

		return TRUE;
	}

	return FALSE; // Normal behaviour
} // End of TileBitmap
Exemplo n.º 27
0
void CNSChartCtrl::OnPaint() 
{
	CPaintDC dc(this); 

	int iValues	= m_ChartValues.GetSize();
	int iColors		= m_BrushArray.GetSize();

	CString str;
	CRect rect;
	GetClientRect(&rect);

	// Check values count
	if(iValues <= 0 )
	{
		CFont* oldFont = dc.SelectObject(&m_txtFont);

		str = "No data are available...";
		dc.FillSolidRect(rect,RGB(255,255,255));
		rect.top += 50;
		dc.DrawText(str,&rect,DT_CENTER|DT_VCENTER);
		dc.SelectObject(oldFont);
		return;
	}
	// Check color count
	if(iColors <= 1)
	{
		CFont* oldFont = dc.SelectObject(&m_txtFont);
		str = "Color count mus be > 1";
		dc.FillSolidRect(rect,RGB(255,255,255));
		rect.top += 50;
		dc.DrawText(str,&rect,DT_CENTER|DT_VCENTER);
		dc.SelectObject(oldFont);
		return;
	}

	//Creating double buffer painting

	CDC imageDC;
	imageDC.CreateCompatibleDC(&dc);

	CBitmap* pOldMemDCBitmap = NULL;

	if(m_bmpScreen.m_hObject == NULL) 
		m_bmpScreen.CreateCompatibleBitmap( &dc, rect.Width(), rect.Height() );
	pOldMemDCBitmap = (CBitmap*)imageDC.SelectObject(&m_bmpScreen);
	
	imageDC.FillSolidRect(rect,RGB(255,255,255));

//	rect.DeflateRect(0,5);

	// Drawing the chart
	if(m_dwStyle == NSCS_BAR ){
		DrawBarChart(&imageDC);
	}
	if(m_dwStyle == NSCS_PIE ){
		DrawPieChart(&imageDC);
	}
	if(m_dwStyle == NSCS_LINE ){
		DrawLineChart(&imageDC);
	}
	// Drawing the Title

	if(m_Caption.GetLength() == 0 )
		GetWindowText(str);
	else
	{
		str = m_Caption;
	}



	CFont* oldFont = imageDC.SelectObject(&m_titleFont);
	imageDC.DrawText(str,rect,DT_CENTER);
	imageDC.SelectObject(oldFont);

	// Drawing the new bitmap

	dc.BitBlt( rect.left , rect.top , rect.Width(), rect.Height(), 
					&imageDC, 0, 0, SRCCOPY );

	imageDC.SelectObject(pOldMemDCBitmap);

}
Exemplo n.º 28
0
void CEnBitmap::DrawStretched(CDC* dc, int x, int y, int w, int h, int sx, int sy, int sw, int sh){
	CDC mdc;
	//CDC* ddc=CWnd::GetDesktopWindow()->GetDC();
	mdc.CreateCompatibleDC(0);
	CBitmap* ob=mdc.SelectObject(this);
	BLENDFUNCTION func;
	func.BlendOp=AC_SRC_OVER;
	func.AlphaFormat=AC_SRC_ALPHA;
	func.SourceConstantAlpha=255;
	func.BlendFlags=0;
	if(scaleType==0){
		dc->AlphaBlend(x, y, w, h, &mdc, sx, sy, sw, sh, func);
	}else{
		int s9t=scale9.top;
		int s9b=scale9.bottom;
		int s9l=scale9.left;
		int s9r=scale9.right;

		int iw=rcImg.right;
		int ih=rcImg.bottom;

		if(useAlpha){
		// Углы
		dc->AlphaBlend(x, y, s9l, s9t, &mdc, 0, 0, s9l, s9t, func);
		dc->AlphaBlend(x+w-s9r, y, s9r, s9t, &mdc, iw-s9r, 0, s9r, s9t, func);
		dc->AlphaBlend(x, y+h-s9b, s9l, s9b, &mdc, 0, ih-s9b, s9l, s9b, func);
		dc->AlphaBlend(x+w-s9r, y+h-s9b, s9r, s9b, &mdc, iw-s9r, ih-s9b, s9r, s9b, func);
	
		//Вертикальные стороны
		dc->AlphaBlend(x, y+s9t, s9l, h-s9t-s9b, &mdc, 0, s9t, s9l, ih-s9t-s9b, func);
		dc->AlphaBlend(x+w-s9r, y+s9t, s9r, h-s9t-s9b, &mdc, iw-s9r, s9t, s9r, ih-s9t-s9b, func);
		
		//Горизонтальные стороны
		dc->AlphaBlend(x+s9l, y, w-s9l-s9r, s9t, &mdc, s9l, 0, iw-s9l-s9r, s9t, func);
		dc->AlphaBlend(x+s9l, y+h-s9b, w-s9l-s9r, s9b, &mdc, s9l, ih-s9b, iw-s9l-s9r, s9b, func);
	
		//И середина
		dc->AlphaBlend(x+s9l, y+s9t, w-s9l-s9r, h-s9t-s9b, &mdc, s9l, s9t, iw-s9l-s9r, ih-s9t-s9b, func);
		}
		else
		{
		// Углы
		dc->BitBlt(x, y, s9l, s9t, &mdc, 0, 0, SRCCOPY);
		dc->BitBlt(x+w-s9r, y, s9r, s9t, &mdc, iw-s9r, 0, SRCCOPY);
		dc->BitBlt(x, y+h-s9b, s9l, s9b, &mdc, 0, iw-s9b, SRCCOPY);
		dc->BitBlt(x+w-s9r, y+h-s9b, s9r, s9b, &mdc, iw-s9r, ih-s9b, SRCCOPY);
	
		//Вертикальные стороны
		dc->StretchBlt(x, y+s9t, s9l, h-s9t-s9b, &mdc, 0, s9t, s9l, ih-s9t-s9b, SRCCOPY);
		dc->StretchBlt(x+w-s9r, y+s9t, s9r, h-s9t-s9b, &mdc, iw-s9r, s9t, s9r, ih-s9t-s9b, SRCCOPY);
		
		//Горизонтальные стороны
		dc->StretchBlt(x+s9l, y, w-s9l-s9r, s9t, &mdc, s9l, 0, iw-s9l-s9r, s9t, SRCCOPY);
		dc->StretchBlt(x+s9l, y+h-s9b, w-s9l-s9r, s9b, &mdc, s9l, ih-s9b, iw-s9l-s9r, s9b, SRCCOPY);
	
		//И середина
		dc->StretchBlt(x+s9l, y+s9t, w-s9l-s9r, h-s9t-s9b, &mdc, s9l, s9t, iw-s9l-s9r, ih-s9t-s9b, SRCCOPY);
		}
	}
	mdc.SelectObject(ob);
	//ReleaseDC(NULL, mdc);
	mdc.DeleteDC();
	//CWnd::GetDesktopWindow()->ReleaseDC(ddc);
}
Exemplo n.º 29
0
void CMlsSimpleBitmapButton::DrawButton(CDC* pDC)
{
	// Upack the state of the button.
	BOOL fSelected = GetSelect();
	BOOL fFocused = FALSE;
	BOOL fDisabled = !IsWindowEnabled();
	BOOL fDefault = FALSE;

	// Create a bitmap which will be used to draw the button image.
	// When the bitmap is complete, it will be drawn onto the button.
	CRect crButton;
	GetClientRect(crButton);

	CBitmap bmButton;
	bmButton.CreateCompatibleBitmap(pDC, crButton.Width(), crButton.Height());

	CDC dcButton;
	dcButton.CreateCompatibleDC(pDC);

	dcButton.SelectObject(&bmButton);

	// Initialize the button bitmap to the button face color.
	Util::FillRectangleWithColor(dcButton, crButton, GetSysColor(COLOR_BTNFACE));

	// Compute the area available for content.
	CRect crContent(crButton);
	crContent.InflateRect(-MinimumMargin, -MinimumMargin);
	CRect crTextContent(crContent);

	// Compute the bitmap dimensions and its nominal position. Adjust crTextContent to the
	// area which is available next to the bitmap.
	CRect crBitmap;
	crBitmap.SetRectEmpty();

	if (!crContent.IsRectEmpty())
	{
		if (m_fHaveBitmap)
		{
			crBitmap.SetRect(0, 0, m_nBitmapWidth, m_nBitmapHeight);

			// Set first bitmap position base on major alignment type.
			switch (m_Alignment)
			{
				case Left:
				{
					crBitmap.OffsetRect(crContent.left, crContent.top+(crContent.Height()-crBitmap.Height())/2);
					crTextContent.left += crBitmap.Width()+Separator;
					break;
				}
				case Right:
				{
					crBitmap.OffsetRect(crContent.right-crBitmap.Width(), crContent.top+(crContent.Height()-crBitmap.Height())/2);
					crTextContent.right -= crBitmap.Width()+Separator;
					break;
				}
				case Top:
				{
					crBitmap.OffsetRect(crContent.left+(crContent.Width()-crBitmap.Width())/2, crContent.top);
					crTextContent.top += crBitmap.Height()+Separator;
					break;
				}
				case Bottom:
				{
					crBitmap.OffsetRect(crContent.left+(crContent.Width()-crBitmap.Width())/2, crContent.bottom-crBitmap.Height());
					crTextContent.bottom -= crBitmap.Height()+Separator;
					break;
				}
				default:
				{
					ASSERT(FALSE);
				}
			}
		}
		else
		{
			crBitmap.SetRectEmpty();
		}
	}

	// Compute the text dimensions and its nominal position.
	CRect crText;
	crText.SetRectEmpty();
	CString csText;

	if (!crTextContent.IsRectEmpty())
	{
		GetWindowText(csText);
		if (!csText.IsEmpty())
		{
			// Get the font which we are using for the text.
			CFont* pFont = GetFont();
			if (pFont != NULL)
			{
				// Select the font we are going to use for drawing the text.
				dcButton.SelectObject(pFont);

				// Compute the extent of the text. The text is formatted into the area next to
				// the button. If the text is multiple line, the full width is always used.
				crText.SetRect(0, 0, crTextContent.Width(), crTextContent.Height());
				int nTextHeight = Util::DrawText(&dcButton, csText, crText, DT_CALCRECT | (m_fMultipleLine ? (m_fWordWrap ? DT_WORDBREAK : 0) : DT_SINGLELINE));

				// Build the rectangle that has the dimensions of the text.
				crText.bottom = nTextHeight;

				// Clip to content dimensions.
				if (crText.Width() > crTextContent.Width())
				{
					crText.right = crTextContent.Width();
				}
				if (crText.Height() > crTextContent.Height())
				{
					crText.bottom = crTextContent.Height();
				}

				// Adjust text rectangle within content rectangle.
				int nXOffset = 0;
				int nYOffset = 0;

				switch (m_Alignment)
				{
					case Left:
					case Right:
					{
						switch (m_nVariation)
						{
							case 0: nXOffset = 0;                                        break;
							case 1: nXOffset = (crTextContent.Width()-crText.Width())/2; break;
							case 2: nXOffset = (crTextContent.Width()-crText.Width());   break;
							case 3: nXOffset = 0;                                        break;
						}
						if (m_Alignment == Right)
						{
							nXOffset = (crTextContent.Width()-crText.Width())-nXOffset;
						}
						nYOffset = (crTextContent.Height()-crText.Height())/2;
						break;
					}
					case Top:
					case Bottom:
					{
						switch (m_nVariation)
						{
							case 0: nYOffset = 0;                                          break;
							case 1: nYOffset = (crTextContent.Height()-crText.Height())/2; break;
							case 2: nYOffset = (crTextContent.Height()-crText.Height());   break;
							case 3: nYOffset = 0;                                          break;
						}
						if (m_Alignment == Bottom)
						{
							nYOffset = (crTextContent.Height()-crText.Height())-nYOffset;
						}
						nXOffset = (crTextContent.Width()-crText.Width())/2;
						break;
					}
					default:
					{
						ASSERT(FALSE);
					}
				}

				crText.OffsetRect(crTextContent.left+nXOffset, crTextContent.top+nYOffset);
			}
		}
	}

	// If the layout variation is 3, then center both the bitmap and text within the
	// content rectangle.
	if (!crContent.IsRectEmpty())
	{
		if (m_nVariation == 3)
		{
			// Compute the rectangle which encloses both the bitmap and text.
			CRect crBoth;
			crBoth.SetRectEmpty();
			if (!crBitmap.IsRectEmpty())
			{
				crBoth |= crBitmap;
			}
			if (!crText.IsRectEmpty())
			{
				crBoth |= crText;
			}

			// Move the bitmap and text back to the content rectangle.
			int nXOffset = 0;
			int nYOffset = 0;

			switch (m_Alignment)
			{
				case Left:
				case Right:
				{
					nXOffset = (crContent.Width()-crBoth.Width())/2;
					if (m_Alignment == Right)
					{
						nXOffset = -nXOffset;
					}
					break;
				}
				case Top:
				case Bottom:
				{
					nYOffset = (crContent.Height()-crBoth.Height())/2;
					if (m_Alignment == Bottom)
					{
						nYOffset = -nYOffset;
					}
					break;
				}
				default:
				{
					ASSERT(FALSE);
				}
			}

			// Adjust the bitmap and text rectangles.
			crBitmap.OffsetRect(nXOffset, nYOffset);
			crText.OffsetRect(nXOffset, nYOffset);
		}
	}

	// If the button is selected, offset the bitmap and text.
	if (fSelected)
	{
		crBitmap.OffsetRect(1, 1);
		crText.OffsetRect(1, 1);
	}

	// Draw the bitmap onto the button image at the computed position.
	if (!crBitmap.IsRectEmpty())
	{
		CDC dcBitmap;
		dcBitmap.CreateCompatibleDC(pDC);

		// Erase to 0's (black) the areas of the button where the opaque portions
		// of the bitmap will be drawn.
		dcButton.SetTextColor(RGB(0,0,0));
		dcButton.SetBkColor(RGB(255,255,255));
		dcBitmap.SelectObject(&m_bmMask);
		dcButton.BitBlt(crBitmap.left, crBitmap.top, crBitmap.Width(), crBitmap.Height(), &dcBitmap, 0, 0, SRCAND);

		// Draw the bitmap onto the button.
		dcBitmap.SelectObject(&m_bmBitmap);
		dcButton.BitBlt(crBitmap.left, crBitmap.top, crBitmap.Width(), crBitmap.Height(), &dcBitmap, 0, 0, SRCPAINT);
	}

	// Draw the text onto the button image at the computed position.
	if (!crText.IsRectEmpty())
	{
		// Draw the text.
		dcButton.SetTextColor(GetSysColor(COLOR_BTNTEXT));
		dcButton.SetBkMode(TRANSPARENT);
		Util::DrawText(&dcButton, csText, crText, (m_fMultipleLine ? (DT_CENTER | (m_fWordWrap ? DT_WORDBREAK : 0)) : DT_SINGLELINE));
	}

	// If the button is disabled, indicate this by embossing the bitmap.
	if (fDisabled)
	{
		Util::Emboss(dcButton, crButton, GetSysColor(COLOR_BTNFACE), GetSysColor(COLOR_BTNHILIGHT), GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_BTNHILIGHT));
	}

	// Draw the button in its current state.
	if (fSelected)
	{
		// Button is selected, draw a black border with a shadow border inside.
		CRect crDraw(crButton);
		Util::DrawBorderWithColor(dcButton, crDraw, GetSysColor(COLOR_BTNTEXT), 1);
		crDraw.InflateRect(-1, -1);
		Util::DrawBorderWithColor(dcButton, crDraw, GetSysColor(COLOR_BTNSHADOW), 1);
	}
	else
	{
		CRect crDraw(crButton);

		// If the button is focused or the default button, draw a
		// black border around it. The rest of the image moves in
		// to make room.
		if (fFocused | fDefault)
		{
			Util::DrawBorderWithColor(dcButton, crDraw, GetSysColor(COLOR_BTNTEXT), 1);
			crDraw.InflateRect(-1, -1);
		}

		// Draw the raised 3D border:
		//
		//    W-----------WB
		//    |           D|
		//    |           ||
		//    |           ||
		//    WD----------D|
		//    B------------B


		CRect crSide;

		// W horizontal
		crSide.SetRect(crDraw.left, crDraw.top, crDraw.right-1, crDraw.top+1);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNHILIGHT));

		// W vertical
		crSide.SetRect(crDraw.left, crDraw.top+1, crDraw.left+1, crDraw.bottom-1);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNHILIGHT));

		// B horizontal
		crSide.SetRect(crDraw.left, crDraw.bottom-1, crDraw.right, crDraw.bottom);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNTEXT));

		// B vertical
		crSide.SetRect(crDraw.right-1, crDraw.top, crDraw.right, crDraw.bottom-1);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNTEXT));

		// D horizontal
		crSide.SetRect(crDraw.left+1, crDraw.bottom-2, crDraw.right-1, crDraw.bottom-1);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNSHADOW));

		// D vertical
		crSide.SetRect(crDraw.right-2, crDraw.top+1, crDraw.right-1, crDraw.bottom-2);
		Util::FillRectangleWithColor(dcButton, crSide, GetSysColor(COLOR_BTNSHADOW));
	}

	// If the button is focused, draw the focus rectangle.
	if (fFocused)
	{
		CRect crDraw(crButton);
		crDraw.InflateRect(-4, -4);
		dcButton.DrawFocusRect(crDraw);
	}

	// Copy the bitmap onto the button.
	pDC->BitBlt(crButton.left, crButton.top, crButton.Width(), crButton.Height(), &dcButton, 0, 0, SRCCOPY);

	dcButton.DeleteDC();
	bmButton.DeleteObject();
}
Exemplo n.º 30
0
void ECommentPane::OnPaint()
{
	CRect   cr;
	GetClientRect(&cr);

	CPaintDC PaintDC(this);
	CDC* pDC = &PaintDC;

	//
	//
	//

//----------------
// flicker
//----------------
	CDC* pParsedDC = pDC;
	CDC     MemDC;
	CBitmap MemBM;
	MemBM.CreateCompatibleBitmap(pParsedDC,cr.Width(),cr.Height());
	MemDC.CreateCompatibleDC(pParsedDC);
	MemDC.SelectObject(&MemBM);
	pDC = &MemDC;
//----------------

	CRect r = cr;

	CFont f;

	pDC->SetBkColor(RGB(255,255,255));

	CRect rlef = r;
	CRect rrig = r;

	rlef.right = 17;
	rrig.left  = rlef.right;

	pDC->FillSolidRect( r , ::GetSysColor(COLOR_3DFACE  ));

	m_pPropWnd->DrawFrame( pDC , r , true , m_pPropWnd->GetColorPaneKey() );

	rrig.DeflateRect(2,2);
	r.DeflateRect(5,3);

	CRect TextAreaRect = r;

	//
	//
	//

	CString sTitle = "-";
	CString sNoComments = "-";

	//
	//
	//

	int nWeight = FW_MEDIUM;	//m_bMinimized ? FW_BOLD : FW_MEDIUM;

	f.CreateFont(13,0,0,0,nWeight,0,0,0,0,0,0,0,0, _T("tahoma") );
	pDC->SelectObject(&f);



	if( m_pCommentHost!=NULL )
	{
		CString sName;
		CString s = m_pCommentHost->GetCurrentComment( sName );

		UINT nFlags = DT_LEFT | DT_WORDBREAK;

		if( s.GetLength()==0 )
		{
			s = sNoComments;
			nFlags = DT_SINGLELINE | DT_CENTER | DT_VCENTER;
		}
		else
		{
			while( true )
			{
				CRect TrimmedTextRect = TextAreaRect;

				pDC->DrawText( s , TrimmedTextRect , DT_WORDBREAK | DT_CALCRECT );

				if( TrimmedTextRect.Height() <= TextAreaRect.Height() )
				{
					break;
				}

				if( s.GetLength() <= 4 )
				{
					s = "...";
					break;
				}

				s = s.Left( s.GetLength()-4 );
				s += "...";
			}

		}

		pDC->DrawText( s , TextAreaRect , nFlags );
	}

//--------------------------
// flicker
//--------------------------
	MemDC.SetViewportOrg(0,0);
	pParsedDC->BitBlt( 0 , 0 , cr.Width() , cr.Height() , &MemDC , 0 , 0 , SRCCOPY );
//--------------------------


}