-
March 18th, 2012, 12:36 PM
#1
Memory DC Help
I have a static derived class which I want to implement custom drawing in MM_ISOTROPIC mapping mode. For the life of me, I cannot figure out how to do this using a memory dc. I have reviewed and copied several "double buffering" routines, i.e. CMemDC but none of them work when I change the mapping mode.
The following code simply draws a line from the origin (low left corner) to 100,100. It is a simple test. If I use the CPaintDC all is fine, but using a memory dc, nothing shows up.
Code:
void DrawCtrl::OnPaint()
{
CPaintDC dc(this);
PrepareDc(&dc);
CDC memDc;
memDc.CreateCompatibleDC(&dc);
PrepareDc(&memDc);
CRect rect;
dc.GetClipBox(&rect);
CBitmap bm;
bm.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
CBitmap* pOld = memDc.SelectObject(&bm);
CPen wht (PS_SOLID, 1, RGB(255,255,255));
memDc.SelectObject(&wht);
memDc.LineTo(100,100);
dc.BitBlt(rect.left, rect.bottom, rect.Width(), rect.Height(), &memDc, rect.left, rect.bottom, SRCCOPY);
memDc.SelectObject(pOld);
}
void DrawCtrl::PrepareDc(CDC* pDc)
{
CRect rect;
GetClientRect(&rect);
pDc->FillSolidRect(&rect, RGB(0,0,0));
pDc->SetMapMode(MM_ISOTROPIC);
pDc->SetWindowExt(rect.Size());
pDc->SetViewportExt(rect.Width(), -rect.Height());
pDc->SetViewportOrg(rect.left, rect.bottom);
}
Any ideas to help me out?
Mike B
-
March 19th, 2012, 05:50 AM
#2
Re: Memory DC Help
From what I read in MSDN, the first two parameters for BitBlt should be the X and Y of the top left corner. Perhaps this is the problem?
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
March 19th, 2012, 07:32 AM
#3
Re: Memory DC Help
Originally Posted by krmed
From what I read in MSDN, the first two parameters for BitBlt should be the X and Y of the top left corner. Perhaps this is the problem?
Well, as you have pointed out, not only is it the top left corner, but it should be specified in "Logical Units". The width and height also need to be specified in logical units. I have tried every variation I could for the x and y but, I didn't convert the rect to logical units. That was the first mistake. The second is that I had to specify the height as negative. Haven't yet wrapped my head around this yet, but I suppose it is because I specify the 'Y' direction as positive in the 'UP' direction.
Code:
dc.DPtoLP(&rect);
dc.BitBlt(rect.left, rect.top, rect.Width(), -rect.Height(), &memDc, 0, 0, SRCCOPY);
Thanks, it works.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|