Click here to Skip to main content
15,879,326 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: MFC. How to display a bitmap or a .png file Pin
CPallini17-Nov-22 19:57
mveCPallini17-Nov-22 19:57 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O18-Nov-22 12:36
BigSteve-O18-Nov-22 12:36 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Randor 19-Nov-22 9:55
professional Randor 19-Nov-22 9:55 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O19-Nov-22 11:41
BigSteve-O19-Nov-22 11:41 
QuestionRe: MFC. How to display a bitmap or a .png file Pin
Randor 19-Nov-22 13:39
professional Randor 19-Nov-22 13:39 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O20-Nov-22 7:21
BigSteve-O20-Nov-22 7:21 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Victor Nijegorodov20-Nov-22 8:04
Victor Nijegorodov20-Nov-22 8:04 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini20-Nov-22 22:10
mveCPallini20-Nov-22 22: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 4:56
BigSteve-O21-Nov-22 4:56 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
CPallini21-Nov-22 4:59
mveCPallini21-Nov-22 4:59 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
Graham Breach14-Nov-22 10:57
Graham Breach14-Nov-22 10:57 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O14-Nov-22 11:53
BigSteve-O14-Nov-22 11:53 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
Richard MacCutchan14-Nov-22 21:44
mveRichard MacCutchan14-Nov-22 21:44 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
charlieg15-Nov-22 0:23
charlieg15-Nov-22 0:23 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
BigSteve-O15-Nov-22 13:15
BigSteve-O15-Nov-22 13:15 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg17-Nov-22 11:44
charlieg17-Nov-22 11:44 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg18-Nov-22 8:44
charlieg18-Nov-22 8:44 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg18-Nov-22 9:38
charlieg18-Nov-22 9:38 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
Richard MacCutchan15-Nov-22 21:25
mveRichard MacCutchan15-Nov-22 21:25 
GeneralRe: MFC. How to display a bitmap or a .png file Pin
charlieg16-Nov-22 5:17
charlieg16-Nov-22 5:17 
AnswerRe: MFC. How to display a bitmap or a .png file Pin
charlieg22-Nov-22 16:15
charlieg22-Nov-22 16:15 
QuestionDisplay balance Pin
Muhd Hakim9-Nov-22 5:40
Muhd Hakim9-Nov-22 5:40 
AnswerRe: Display balance Pin
jeron19-Nov-22 6:06
jeron19-Nov-22 6:06 
AnswerRe: Display balance Pin
Richard MacCutchan9-Nov-22 6:22
mveRichard MacCutchan9-Nov-22 6:22 
AnswerRe: Display balance Pin
Craig Robbins9-Nov-22 7:49
Craig Robbins9-Nov-22 7: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.