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

C / C++ / MFC

 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
arnold_w5-Dec-22 3:05
arnold_w5-Dec-22 3:05 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
CPallini5-Dec-22 3:54
mveCPallini5-Dec-22 3:54 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
arnold_w5-Dec-22 4:32
arnold_w5-Dec-22 4:32 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
Mircea Neacsu5-Dec-22 3:54
Mircea Neacsu5-Dec-22 3:54 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
CPallini5-Dec-22 8:44
mveCPallini5-Dec-22 8:44 
AnswerRe: Proper way to put a C++ object inside a struct initialization? Pin
Mircea Neacsu5-Dec-22 2:30
Mircea Neacsu5-Dec-22 2:30 
GeneralRe: Proper way to put a C++ object inside a struct initialization? Pin
arnold_w5-Dec-22 3:07
arnold_w5-Dec-22 3:07 
QuestionMFC. How to display a bitmap or a .png file Pin
BigSteve-O14-Nov-22 9:44
BigSteve-O14-Nov-22 9:44 
Good Morning.

In my view class in the onDraw() function, I am drawing the board and filling in the squares as follows:

	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);
		}
	}
	// 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);
	}

This all works well, and I have my board coming up.

Now I want to draw the chess pieces on the board, and have written some code, just to load 1 bitgmap and display it on the screen. However, nothing gets drawn to the screen. (All I see is just the chessboard)

This is the test code to display my bitmap on the screen:

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

	CPaintDC dc(this); // device context for painting

	// TODO: Add your message handler code here
	CBitmap BmpLady;
	CDC MemDCLady;

	// Load the bitmap from the resource
	BmpLady.LoadBitmap(IDB_BISHOP_WHITE);
	// Create a memory device compatible with the above CPaintDC variable
	MemDCLady.CreateCompatibleDC(/*&dc*/pDC);
	// Select the new bitmap
	CBitmap *BmpPrevious = MemDCLady.SelectObject(&BmpLady);

	// Copy the bits from the memory DC into the current dc
	pDC->BitBlt(20, 10, 436, 364, &MemDCLady, 0, 0, SRCCOPY);

	// Restore the old bitmap
	pDC->SelectObject(BmpPrevious);
	// Do not call CView::OnPaint() for painting messages


The bitmap is not drwan to the screen. I have tried using both the CPaintDC dc or the pDC* but to no avail. I cannot get the bitmap to display.

Any suggestions will be greatly appreciated.
QuestionRe: MFC. How to display a bitmap or a .png file Pin
CPallini14-Nov-22 10:25
mveCPallini14-Nov-22 10:25 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O14-Nov-22 10:57
BigSteve-O14-Nov-22 10:57 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Victor Nijegorodov14-Nov-22 11:52
Victor Nijegorodov14-Nov-22 11:52 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O14-Nov-22 12:29
BigSteve-O14-Nov-22 12:29 
QuestionRe: MFC. How to display a bitmap or a .png file Pin
CPallini15-Nov-22 2:58
mveCPallini15-Nov-22 2:58 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O16-Nov-22 14:45
BigSteve-O16-Nov-22 14:45 
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 
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 

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.