need help drawing to a meta DC
-
At one point in my app, I have a bitmap and an enhanced meta DC I want to copy the bitmap into the meta Dc so that I can copy to the clipboard. I can't seem to get this to work. here is my code if ( OpenClipboard(hdc) ) { EmptyClipboard(); //create the metafile DC CMetaFileDC * cDC = new CMetaFileDC(); cDC->CreateEnhanced(GetDC(),NULL,NULL,NULL); //call draw routine here that makes GDI calls int cDC // my bitmap is here!! //close meta CMetafileDC and get its handle HENHMETAFILE handle = cDC->CloseEnhanced(); //place it on the clipboard SetClipboardData(CF_ENHMETAFILE,handle); CloseClipboard(); //delete the dc delete cDC; } I am stumped, any help appreciated IGeorgeI George W
-
At one point in my app, I have a bitmap and an enhanced meta DC I want to copy the bitmap into the meta Dc so that I can copy to the clipboard. I can't seem to get this to work. here is my code if ( OpenClipboard(hdc) ) { EmptyClipboard(); //create the metafile DC CMetaFileDC * cDC = new CMetaFileDC(); cDC->CreateEnhanced(GetDC(),NULL,NULL,NULL); //call draw routine here that makes GDI calls int cDC // my bitmap is here!! //close meta CMetafileDC and get its handle HENHMETAFILE handle = cDC->CloseEnhanced(); //place it on the clipboard SetClipboardData(CF_ENHMETAFILE,handle); CloseClipboard(); //delete the dc delete cDC; } I am stumped, any help appreciated IGeorgeI George W
I think you might need to detach the metafile before deleting it:
cDC->Detach();
//delete the dc
delete cDC;BTW: you might as well create the CMetaFileDC on the stack instead of using
new
. Also BTW: It is possible to put bitmaps on the clipboard directly. --------_**I'm not sick, but i'm not well And i'm so hot, 'cause i'm in hell...
**_
Harvey Danger, Flagpole Sitta
-
I think you might need to detach the metafile before deleting it:
cDC->Detach();
//delete the dc
delete cDC;BTW: you might as well create the CMetaFileDC on the stack instead of using
new
. Also BTW: It is possible to put bitmaps on the clipboard directly. --------_**I'm not sick, but i'm not well And i'm so hot, 'cause i'm in hell...
**_
Harvey Danger, Flagpole Sitta
Thanks for reply but that didn't work. I have captured one of my components and saved it in memory as a bitmap. The class that I am using to capture, saves it as a bitmap so I have no choice but to work with bitmaps. I can already copy it as a bitmap to the clipboard and paste into other applications. That works great. I want to now copy it into the clipboard as an enhaced meta file. I have been trying to stretchBlt the bitmap to the EMF but that seems to work sort of but there is offsets and distortion that occurs. I just want to know if there is a propper way to copy the bitmap to an Enhanced meta file. I am really stumped here. IGeorgeI:confused: George W
-
At one point in my app, I have a bitmap and an enhanced meta DC I want to copy the bitmap into the meta Dc so that I can copy to the clipboard. I can't seem to get this to work. here is my code if ( OpenClipboard(hdc) ) { EmptyClipboard(); //create the metafile DC CMetaFileDC * cDC = new CMetaFileDC(); cDC->CreateEnhanced(GetDC(),NULL,NULL,NULL); //call draw routine here that makes GDI calls int cDC // my bitmap is here!! //close meta CMetafileDC and get its handle HENHMETAFILE handle = cDC->CloseEnhanced(); //place it on the clipboard SetClipboardData(CF_ENHMETAFILE,handle); CloseClipboard(); //delete the dc delete cDC; } I am stumped, any help appreciated IGeorgeI George W
Are you asking how to do it? If so, this is what you need to do:
// I would change this line
// cDC->CreateEnhanced(GetDC(),NULL,NULL,NULL);
// to this:
cDC->CreateEnhanced(hdc,NULL,NULL,NULL);
// this will help avoid a memory leak with DCs.//call draw routine here that makes GDI calls int cDC
...
// my bitmap is here!!CDC dcMem;
CBitmap *bmpOld;
// This creates a memory DC to use the bitmap with.
dcMem.CreateCompatibleDC(hdc);
bmpOld = dcMem.SelectObject(&cBitmap/*your CBitmap object*/);BITMAP bm;
cBitmap.GetBitmap(&bm);
// Paint your bitmap at (x,y), for the same with and height as the bitmap.
cDC.BitBlt(x, y, bm.bmWidth, bm.bmHeight, dcMem, 0,0, SRCCOPY);// Select the old bitmap into the memDC.
dcMem.SelectObject(bmpOld);//close meta CMetaFileDC and get its handle
...GoodLuck
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!