BWarmuskerken
asked on
Memory DC, How?
I've been though a ton of sample source, and still am so confused on this. What I need to do seems so simple, yet I cannot seem to get the syntax down.
I have two DCs, hCurrentPage and hNextPage. Both DCs have the same dimensions. Here is what I need to do.
1. Create a memory DC
//set drawing rectangle to the dimensions of the pages
CRect rcDraw(0,0,sizeImage.cx,si zeImage.cy );
//create the memory DC
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCompatible = CreateCompatibleDC(hdcScre en);
HBITMAP hbmScreen = CreateCompatibleBitmap(hdc Screen,
GetDeviceCaps(hdcScreen, HORZRES), GetDeviceCaps(hdcScreen, VERTRES));
SelectObject(hdcCompatible , hbmScreen);
2. Copy the content of hNextPage into a memory DC using BitBlt SRCCOPY
::BitBlt(hdcCompatible, 0,0, rcDraw.Width(), rcDraw.Height()
, hNextPage, 0, 0, SRCCOPY);
3. Copy the content of hCurrentPage into the memory DC using BitBlt SRCCOPY
//In the actual program I deflate the rectangle, but for clarity I have ommitte that code
::BitBlt(hdcCompatible,rcD raw.left,r cDraw.top, rcDraw.Wid th(),rcDra w.Height()
, hCurrentPage,rcDraw.left,r cDraw.top, SRCCOPY);
4. Copy the combined content in the memory DC to hCurrentPage using BitBlt SRCCOPY
::BitBlt(hCurrentPage,rcNe w.left,rcN ew.top,rcN ew.Width() ,rcNew.Hei ght()
, hdcCompatible, rcNew.left, rcNew.top, SRCCOPY);
5. Delete the memory DC
DeleteDC(hdcCompatible);
What am I doing wrong? If it makes any difference, the above code is in a loop to perform a transition between hCurrentPage and hNextPage.
Thanks.
I have two DCs, hCurrentPage and hNextPage. Both DCs have the same dimensions. Here is what I need to do.
1. Create a memory DC
//set drawing rectangle to the dimensions of the pages
CRect rcDraw(0,0,sizeImage.cx,si
//create the memory DC
HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hdcCompatible = CreateCompatibleDC(hdcScre
HBITMAP hbmScreen = CreateCompatibleBitmap(hdc
GetDeviceCaps(hdcScreen, HORZRES), GetDeviceCaps(hdcScreen, VERTRES));
SelectObject(hdcCompatible
2. Copy the content of hNextPage into a memory DC using BitBlt SRCCOPY
::BitBlt(hdcCompatible, 0,0, rcDraw.Width(), rcDraw.Height()
, hNextPage, 0, 0, SRCCOPY);
3. Copy the content of hCurrentPage into the memory DC using BitBlt SRCCOPY
//In the actual program I deflate the rectangle, but for clarity I have ommitte that code
::BitBlt(hdcCompatible,rcD
, hCurrentPage,rcDraw.left,r
4. Copy the combined content in the memory DC to hCurrentPage using BitBlt SRCCOPY
::BitBlt(hCurrentPage,rcNe
, hdcCompatible, rcNew.left, rcNew.top, SRCCOPY);
5. Delete the memory DC
DeleteDC(hdcCompatible);
What am I doing wrong? If it makes any difference, the above code is in a loop to perform a transition between hCurrentPage and hNextPage.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think everone is starting with question which turn out to be stupid if one knows more. Thats just learning.
ASKER
SteH,
I know this is after the fact, but...
Im doing this in a For loop
for ()
{
HDC hdcCompatible = CreateCompatibleDC (hNextPage);
HBITMAP hbmDC = CreateCompatibleBitmap (hNextPage);
::BitBlt (hdcCompatible, 0, 0, rcDraw.Width(), rcDraw.Height(), hNextPage, 0, 0, SRCCOPY);
// Other code here to BitBlt
DeleteDC(hdcCompatible);
}
Is creating and deleteing the object going to cause me hassles?
I know this is after the fact, but...
Im doing this in a For loop
for ()
{
HDC hdcCompatible = CreateCompatibleDC (hNextPage);
HBITMAP hbmDC = CreateCompatibleBitmap (hNextPage);
::BitBlt (hdcCompatible, 0, 0, rcDraw.Width(), rcDraw.Height(), hNextPage, 0, 0, SRCCOPY);
// Other code here to BitBlt
DeleteDC(hdcCompatible);
}
Is creating and deleteing the object going to cause me hassles?
It should not harm if all memory is properly released.
You could change it to:
HDC hdcCompatible = CreateCompatibleDC (hNextPage);
HBITMAP hbmDC = CreateCompatibleBitmap (hNextPage);
for ()
{
::BitBlt (hdcCompatible, 0, 0, rcDraw.Width(), rcDraw.Height(), hNextPage, 0, 0, SRCCOPY);
// Other code here to BitBlt
}
DeleteDC(hdcCompatible);
What could be a problem is that the content of hNextPage and hCurrentPage change during the loop and the starting point in the second iteration might not be as desired. Perhaps you can store the images after each iteration and have a look at them.
You could change it to:
HDC hdcCompatible = CreateCompatibleDC (hNextPage);
HBITMAP hbmDC = CreateCompatibleBitmap (hNextPage);
for ()
{
::BitBlt (hdcCompatible, 0, 0, rcDraw.Width(), rcDraw.Height(), hNextPage, 0, 0, SRCCOPY);
// Other code here to BitBlt
}
DeleteDC(hdcCompatible);
What could be a problem is that the content of hNextPage and hCurrentPage change during the loop and the starting point in the second iteration might not be as desired. Perhaps you can store the images after each iteration and have a look at them.
ASKER
Putting those lines outside of the loop made all the difference in the world. It's smoothe.
ASKER
Thanks for the help, again. I guess I didn't realize I could use CreateCompatibleDC on the DC I already had. I have to admit that I feel a little stupd now. Hopefully, I won't be back to ask any more questions, but if I do, I know who to ask now.