Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. need help drawing to a meta DC

need help drawing to a meta DC

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    IGeorgeI
    wrote on last edited by
    #1

    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

    S P 2 Replies Last reply
    0
    • I IGeorgeI

      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

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      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 1 Reply Last reply
      0
      • S Shog9 0

        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 Offline
        I Offline
        IGeorgeI
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • I IGeorgeI

          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

          P Offline
          P Offline
          Paul M Watt
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups