void CMyChessTestView::OnDraw(CDC* pDC)
CMyChessTestDoc* pDoc = GetDocument();
// TODO: add draw code for native data here// Draw the empty board....
drawImage(pDC, 100, 100);
Here is the drawImage(...)
void CMyChessTestView::drawImage(CDC* pDC, int x, int y)
// load IDB_BITMAP1 from our resources
// Get the size of the bitmap
// Create an in-memory DC compatible with the// display DC we're using to paint
// Select the bitmap into the in-memory DC
CBitmap *pOldBitmap = dcMemory.SelectObject(&bmp);
// Find a centerpoint for the bitmap in the client area
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);
TRACE0("ERROR: Where's IDB_LADYPIC?\n");
Here is the drawEmptyBoard()
void CMyChessTestView::drawEmptyBoard(CDC* pDC)
CMyChessTestDoc* pBC = GetDocument();
//drawImage(pDC, 80, 80);
//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);
int x1 = (j * 70) + 35;
int y1 = (i * -70) - 35;
int x2 = x1 + 70;
int y2 = y1 - 70;
CRect rect(x1, y1, x2, y2);
// Now draw the bordersfor (int x = 35; x <= 595; x += 70)
for (int y = -35; y >= -595; y -= 70)
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)
drawImage(&dc, 105, -105); // note the negative y
While drawImage becomes
/*..*/::drawImage(CDC* pDC, int x, int y)
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
To make things more explicit, I would move the SetMapMode call out of drawEmptyBoard.
"In testa che avete, Signor di Ceprano?"
// Copy the bits from the memory DC into the current dc
pDC->BitBlt(20, 10, 436, 364, &MemDCLady, 0, 0, SRCCOPY);
is the culprit. Recall that you've set your coordinate system to low English which fixes the bassackwardness of drawing.
If you trace your board generation, you will see that your Y values go from 0 to negative values. Looking at the above line,
you are drawing off the top of your view window. Change the 364 to -364 and you'll see your image.
Of course, *I've* never done that
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
the following problem:
F&W Sdn Bhd is a packaging company. Write a program in C++ to help the company determine how many boxes that are needed for an item. For example, a boxof shampoo can have 30 bottles in it. 95 bottles of shampoo need to be packed into 3 boxes and 5 are left.
The number of each item and the number of an item that can be packed in a box are received as inputs. Display the number of boxes needed and the number of leftover items.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
If you are serious about learning to do this yourself then take your assignment in small steps:
1 Write a program that displays output. The traditional first program displays "Hello World".
2 Now write a program that takes a number as input and then displays that same number as output.
3 Now write a program that takes two numbers as input and then displays those same two numbers.
4 Study how to do division in C++ so you know how to handle the dividend, the divisor, the quotient, and the remainder.
5 Now write your assignment, taking two numbers as input, doing the division, and displaying the results.
Since this is a class assignment, the best answers are ones that help you learn. You need to ask specific questions that you do not understand. The best way to get help is to show you have made a reasonable effort to figure it out.
Put the 5 that are left in a new box, and tell the other guy you only need 30 at a time.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Last Visit: 31-Dec-99 19:00 Last Update: 29-Jan-23 18:21