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

C / C++ / MFC

 
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 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini20-Nov-22 23:10
mveCPallini20-Nov-22 23:10 
OK, I was able to reproduce your issue, and with a bit of luck, to fix it.
The problem arises when you change the DC mapping mode. Now while I am not an expert of mapping modes, this code displays the bitmap over the empty board:
Inside OnDraw (is actually OnPaint in my test app)
C++
//..
drawEmptyBoard(&dc);
drawImage(&dc, 105, -105); // note the negative y
//..

While drawImage becomes
C++
/*..*/::drawImage(CDC* pDC, int x, int y)
{
	CBitmap bmp;
	if (bmp.LoadBitmap(IDB_LADYPIC))
	{
		BITMAP bmpInfo;
		bmp.GetBitmap(&bmpInfo);

		CDC dcMemory;

		dcMemory.CreateCompatibleDC(pDC);
		dcMemory.SetMapMode(pDC->GetMapMode()); // as weird as it looks, the map mode is not the same, after CreateCompatibleDC

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

		pDC->StretchBlt(x, y, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,0, 0, bmpInfo.bmWidth, -bmpInfo.bmHeight, SRCCOPY); // note the negative height of the bitmap

		dcMemory.SelectObject(pOldBitmap);
	}
}


To make things more explicit, I would move the SetMapMode call out of drawEmptyBoard.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto

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 
QuestionDisplay balance Pin
Muhd Hakim9-Nov-22 6:40
Muhd Hakim9-Nov-22 6:40 
AnswerRe: Display balance Pin
jeron19-Nov-22 7:06
jeron19-Nov-22 7:06 
AnswerRe: Display balance Pin
Richard MacCutchan9-Nov-22 7:22
mveRichard MacCutchan9-Nov-22 7:22 
AnswerRe: Display balance Pin
Craig Robbins9-Nov-22 8:49
Craig Robbins9-Nov-22 8:49 

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.