|
-
March 19th, 2012, 05:06 PM
#1
Another Memory DC question.
Although the code below works, I cannot understand why. Can someome try the code and explain to me why it works. It is the BitBlt function that I am most confused about because in the MSDN documentation it states that the first x and y arguments refer to the "logical ? coordinate of the upper-left corner of the destination rectangle.". Note, that I am specifying the "bottom" for the y value. Also, I am specifying a negative height. Not because I know to do this, but because I just happened to come across this through trial-and-error. If anyone can help me understand why the code below works, it would be greatly appreciated.
Code:
void ProfileCtrl::OnPaint()
{
CRect rect;
GetClientRect(&rect);
CPaintDC paintDc(this);
paintDc.SetMapMode(MM_ISOTROPIC);
paintDc.SetWindowExt(rect.Size());
paintDc.SetViewportExt(rect.Width(), -rect.Height());
paintDc.SetViewportOrg(rect.left, rect.bottom);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&paintDc, rect.Width(), rect.Height());
CDC memDc;
memDc.CreateCompatibleDC(&paintDc);
memDc.SetMapMode(paintDc.GetMapMode());
memDc.SetWindowExt(paintDc.GetWindowExt());
memDc.SetViewportExt(paintDc.GetViewportExt());
memDc.SetViewportOrg(paintDc.GetViewportOrg());
CBitmap* pOldBitmap = memDc.SelectObject(&bitmap);
memDc.DPtoLP(&rect);
memDc.FillSolidRect(&rect, RGB(0,0,0));
CPen pen(PS_SOLID, 1, RGB(255,0,0));
memDc.SelectObject(&pen);
memDc.LineTo(100,100);
paintDc.BitBlt(rect.left, rect.bottom, rect.Width(), -rect.Height(), &memDc, 0, 0, SRCCOPY);
memDc.SelectObject(pOldBitmap);
}
-
March 20th, 2012, 12:21 PM
#2
Re: Another Memory DC question.
Not without the rest of the code. How do you exepct us to generate the project?
"Effective teaching is the essence of leadership..."
"There is no substitute for a carefully thought-out design."
If you have found this post to be useful, please Rate it.
-
March 20th, 2012, 12:26 PM
#3
Re: Another Memory DC question.
 Originally Posted by mlgoff
Not without the rest of the code. How do you exepct us to generate the project?
It is the OnPaint handler. I would expect that it would be quicker and easier to throw the code into any window controls OnPaint handler. The project I am working with is an AutoCad arx extension dll so posting that would probably be useless as well.
Mike B
-
March 20th, 2012, 03:50 PM
#4
Re: Another Memory DC question.
 Originally Posted by MikeB
I would expect that it would be quicker and easier to throw the code into any window controls OnPaint handler.
That might be…
However, if you do not have a throw-away project with unneeded window control handy, one would have to create it from scratch.
If it IS that easy – why won’t you create a test project that demonstrates your issue (what is it, by the way?) and attach it here?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
March 20th, 2012, 06:32 PM
#5
Re: Another Memory DC question.
Your code is blt'ing a solid black square, which is totally symetrical and might be giving confusing results.
Try again with a shape (or line sequence) that is completely asymetrical, and you might gain a better understanding of what's happening.
Incidentally, I have no direct knowledge of what you're trying to accomplish, but isn't it also necessary to call SetWindowOrg()?
Mike
-
March 20th, 2012, 11:30 PM
#6
Re: Another Memory DC question.
 Originally Posted by MikeB
It is the OnPaint handler. I would expect that it would be quicker and easier to throw the code into any window controls OnPaint handler.
Well, isn't that what you should be doing to further isolate the problem? If something doesn't work, you step away from the larger program, isolate the problem, create a small app, and investigate why the smaller program is behaving the way it is. Then you have a small sample to experiment with, debug, etc, instead of a multi-module monster program that has all sorts of other stuff going on in it that you need to recompile over and over just to test something.
By saying it's part of a larger program increases the chances that it could be something external to this code that is having an effect on the results you're seeing.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; March 20th, 2012 at 11:34 PM.
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
|