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. Memory device context help

Memory device context help

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpperformancequestion
3 Posts 2 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.
  • J Offline
    J Offline
    JHAKAS
    wrote on last edited by
    #1

    Theme of code: Draw to Memdc in OnDraw Stretch over the clientDc Save the dc content to the image file Problem faced Well this code is executed in starting time i.e. 1-2 turn when the function is called it will display the things drawn on the view. Even when we save bitmap it does save to BMP file (3.6Mb) After 1-2 turns it makes screen blasnk and the MemDC contains nothing. Even when MemDC is saved as Bitmap file then it makes BMP file of 1*1 pixel and of size 70 bytes. What can be the problem? My MemDC is member variable of the class. void CMyView:rawWFRDiagram(int Velocity) { char cc[10]; int maxdelay = -1; CPatternDoc *pDoc = GetDocument(); CSize sizeTotal; sizeTotal.cx = 590; sizeTotal.cy = 1100; SetScrollSizes(MM_LOENGLISH, sizeTotal); CClientDC ClientDC(this); OnPrepareDC(&ClientDC); ClientDC.SetMapMode(MM_TEXT); m_WfrBmp -- Member of CMyView of type CBitmap m_WfrBmp.DeleteObject (); m_WfrBmp.CreateCompatibleBitmap(&ClientDC, 860, 1100); MemDC.CreateCompatibleDC(&ClientDC); CBitmap *pOldBitmap = MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_TEXT); MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); Draw anything further to the MemDC MemDC.SetMapMode(MM_LOENGLISH); // STRETCH THE DRAWING ON THE CANVAS I.E. VIEW if(ClientDC.StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY) == FALSE) AfxMessageBox("Failed to draw WFR diagram"); } OnDraw() { pDC->StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY); } Help me to solve this problem? Thanks in advance Sandeep Leave your mark wherever you go

    J 1 Reply Last reply
    0
    • J JHAKAS

      Theme of code: Draw to Memdc in OnDraw Stretch over the clientDc Save the dc content to the image file Problem faced Well this code is executed in starting time i.e. 1-2 turn when the function is called it will display the things drawn on the view. Even when we save bitmap it does save to BMP file (3.6Mb) After 1-2 turns it makes screen blasnk and the MemDC contains nothing. Even when MemDC is saved as Bitmap file then it makes BMP file of 1*1 pixel and of size 70 bytes. What can be the problem? My MemDC is member variable of the class. void CMyView:rawWFRDiagram(int Velocity) { char cc[10]; int maxdelay = -1; CPatternDoc *pDoc = GetDocument(); CSize sizeTotal; sizeTotal.cx = 590; sizeTotal.cy = 1100; SetScrollSizes(MM_LOENGLISH, sizeTotal); CClientDC ClientDC(this); OnPrepareDC(&ClientDC); ClientDC.SetMapMode(MM_TEXT); m_WfrBmp -- Member of CMyView of type CBitmap m_WfrBmp.DeleteObject (); m_WfrBmp.CreateCompatibleBitmap(&ClientDC, 860, 1100); MemDC.CreateCompatibleDC(&ClientDC); CBitmap *pOldBitmap = MemDC.SelectObject(&m_WfrBmp); MemDC.SetMapMode(MM_TEXT); MemDC.PatBlt(0, 0, 860, 1100, WHITENESS); Draw anything further to the MemDC MemDC.SetMapMode(MM_LOENGLISH); // STRETCH THE DRAWING ON THE CANVAS I.E. VIEW if(ClientDC.StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY) == FALSE) AfxMessageBox("Failed to draw WFR diagram"); } OnDraw() { pDC->StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY); } Help me to solve this problem? Thanks in advance Sandeep Leave your mark wherever you go

      J Offline
      J Offline
      JHAKAS
      wrote on last edited by
      #2

      Well in plain words my problem is that i have to draw on the view and also in the memory device context, which will be used for storing the device context conte to the image file If you can provide guideline and suggestions then it will be helpful. NOTE 1.0 I have to keep CDC MemDC ( Memory device context) member of the class so that i can write it in the drawing function and then i can use the same in another function of the class to store it in the image 2.0 In OnDraw i have to render the memdc content on the view. Thats what i was doing? On running the application and trying the drawing function 1-2 times it just draws, but after that it does not draw and same 1*1pixel bitmap OnDraw() { pDC->StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY); } 3.0 I want to know that does the following schema is ok? memdc.createcompatibledc() bmp.createcompatiblebitmap() CBitmap *old =memdc.selectobject(bmp); DO THE DRAWING HERE memdc.selectobject(old) another query related to this is that does this will not effect my memdc.stretchblt in the onDraw. What i mean is when i select anaother bitmap then does my mainbitmap on which i had drawn still carries the drawing and can i use that for saving as bitmap file? Would it not affect that bitmap file? If you can provide the sample code taking above points in consideration than i will be greatfull? Well also point out any mistake. Leave your mark wherever you go

      P 1 Reply Last reply
      0
      • J JHAKAS

        Well in plain words my problem is that i have to draw on the view and also in the memory device context, which will be used for storing the device context conte to the image file If you can provide guideline and suggestions then it will be helpful. NOTE 1.0 I have to keep CDC MemDC ( Memory device context) member of the class so that i can write it in the drawing function and then i can use the same in another function of the class to store it in the image 2.0 In OnDraw i have to render the memdc content on the view. Thats what i was doing? On running the application and trying the drawing function 1-2 times it just draws, but after that it does not draw and same 1*1pixel bitmap OnDraw() { pDC->StretchBlt(50, 0, 860, -1100, &MemDC, 0, 0, 860, -1100, SRCCOPY); } 3.0 I want to know that does the following schema is ok? memdc.createcompatibledc() bmp.createcompatiblebitmap() CBitmap *old =memdc.selectobject(bmp); DO THE DRAWING HERE memdc.selectobject(old) another query related to this is that does this will not effect my memdc.stretchblt in the onDraw. What i mean is when i select anaother bitmap then does my mainbitmap on which i had drawn still carries the drawing and can i use that for saving as bitmap file? Would it not affect that bitmap file? If you can provide the sample code taking above points in consideration than i will be greatfull? Well also point out any mistake. Leave your mark wherever you go

        P Offline
        P Offline
        PJ Arends
        wrote on last edited by
        #3

        You having a 1 X 1 pixel bitmap in your memdc tells me that the bitmap selected into it is the original default bitmap that all memdcs have. You have at some point selected your bitmap out of the memdc. If I were you, I would make the bitmap (CBitmap or HBITMAP) a member of your class. That way you only have to create it once. Select it into a memdc to draw on it, and select it out again when done. You can then pass that bitmap to your save function. Remember, it is the bitmap that stores your image, not the DC. The DC is just the means that you use to draw onto a bitmap.


        [

        ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

        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