Click here to Skip to main content
15,566,522 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Victor Nijegorodov16-Nov-22 21:22
Victor Nijegorodov16-Nov-22 21:22 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Victor Nijegorodov16-Nov-22 21:36
Victor Nijegorodov16-Nov-22 21:36 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini17-Nov-22 4:02
mveCPallini17-Nov-22 4:02 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O17-Nov-22 12:31
BigSteve-O17-Nov-22 12:31 
QuestionRe: MFC. How to display a bitmap or a .png file Pin
CPallini17-Nov-22 20:57
mveCPallini17-Nov-22 20:57 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O18-Nov-22 13:36
BigSteve-O18-Nov-22 13:36 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Randor 19-Nov-22 10:55
professional Randor 19-Nov-22 10:55 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O19-Nov-22 12:41
BigSteve-O19-Nov-22 12:41 
Here is my onDraw()

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

	// TODO: add draw code for native data here
	// Draw the empty board....
	drawImage(pDC, 100, 100);
	drawEmptyBoard(pDC);
}




Here is the drawImage(...)

void CMyChessTestView::drawImage(CDC* pDC, int x, int y)
{

	// load IDB_BITMAP1 from our resources
	CBitmap bmp;
	if (bmp.LoadBitmap(IDB_LADYPIC))
	{
		// Get the size of the bitmap
		BITMAP bmpInfo;
		bmp.GetBitmap(&bmpInfo);

		// Create an in-memory DC compatible with the
		// display DC we're using to paint
		CDC dcMemory;
		
		dcMemory.CreateCompatibleDC(pDC);

		// Select the bitmap into the in-memory DC
		CBitmap *pOldBitmap = dcMemory.SelectObject(&bmp);

		// Find a centerpoint for the bitmap in the client area
		CRect rect;
		GetClientRect(&rect);
		int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
		int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

		// Copy the bits from the in-memory DC into the on-
		// screen DC to actually do the painting. Use the centerpoint
		// we computed for the target offset.
		pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
			0, 0, SRCCOPY);

		dcMemory.SelectObject(pOldBitmap);
	}
	else
	{
		TRACE0("ERROR: Where's IDB_LADYPIC?\n");
	}
}



Here is the drawEmptyBoard()

void CMyChessTestView::drawEmptyBoard(CDC* pDC)
{
	CMyChessTestDoc* pBC = GetDocument();
	ASSERT_VALID(pBC);
	if (!pBC)
		return;
	//drawImage(pDC, 80, 80);
	pDC->SetMapMode(MM_LOENGLISH);
	pDC->SetWindowExt(800, 800);
	//pDC->SetViewportOrg(testrec.Width(), testrec.Height());

	for (int i = 0; i < 8; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			COLORREF color = pBC->getSquare(i, j);
			CBrush brush(color);
			int x1 = (j * 70) + 35;
			int y1 = (i * -70) - 35;
			int x2 = x1 + 70;
			int y2 = y1 - 70;
			CRect rect(x1, y1, x2, y2);
			pDC->FillRect(rect, &brush);
			//pDC->Rectangle(rect);
		}
	}
	// Now draw the borders
	for (int x = 35; x <= 595; x += 70)
	{
		pDC->MoveTo(x, -35);
		pDC->LineTo(x, -595);
	}
	for (int y = -35; y >= -595; y -= 70)
	{
		pDC->MoveTo(35, y);
		pDC->LineTo(595, y);
	}

QuestionRe: MFC. How to display a bitmap or a .png file Pin
Randor 19-Nov-22 14:39
professional Randor 19-Nov-22 14:39 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O20-Nov-22 8:21
BigSteve-O20-Nov-22 8:21 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Victor Nijegorodov20-Nov-22 9:04
Victor Nijegorodov20-Nov-22 9:04 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini20-Nov-22 23:10
mveCPallini20-Nov-22 23:10 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O21-Nov-22 5:56
BigSteve-O21-Nov-22 5:56 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini21-Nov-22 5:59
mveCPallini21-Nov-22 5:59 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
Graham Breach14-Nov-22 11:57
Graham Breach14-Nov-22 11:57 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O14-Nov-22 12:53
BigSteve-O14-Nov-22 12:53 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
Richard MacCutchan14-Nov-22 22:44
mveRichard MacCutchan14-Nov-22 22:44 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
charlieg15-Nov-22 1:23
charlieg15-Nov-22 1:23 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O15-Nov-22 14:15
BigSteve-O15-Nov-22 14:15 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg17-Nov-22 12:44
charlieg17-Nov-22 12:44 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg18-Nov-22 9:44
charlieg18-Nov-22 9:44 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg18-Nov-22 10:38
charlieg18-Nov-22 10:38 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Richard MacCutchan15-Nov-22 22:25
mveRichard MacCutchan15-Nov-22 22:25 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg16-Nov-22 6:17
charlieg16-Nov-22 6:17 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
charlieg22-Nov-22 17:15
charlieg22-Nov-22 17:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.