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. CMemDC help

CMemDC help

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiographicshelptutorial
6 Posts 4 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.
  • Z Offline
    Z Offline
    Zizilamoroso
    wrote on last edited by
    #1

    I'm having problems with the CMemDC inside a CStatic derived class. void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; } If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?


    using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
    D Z K 3 Replies Last reply
    0
    • Z Zizilamoroso

      I'm having problems with the CMemDC inside a CStatic derived class. void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; } If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?


      using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
      D Offline
      D Offline
      dan o
      wrote on last edited by
      #2

      hi, why do you use CMemDC, and not directly dc ? HBRUSH oldbrush=(HBRUSH)dc->SelectObject(brush); HPEN oldpen=(HPEN)dc->SelectObject(pen); dc->Rectangle(&r);

      Z 1 Reply Last reply
      0
      • D dan o

        hi, why do you use CMemDC, and not directly dc ? HBRUSH oldbrush=(HBRUSH)dc->SelectObject(brush); HPEN oldpen=(HPEN)dc->SelectObject(pen); dc->Rectangle(&r);

        Z Offline
        Z Offline
        Zizilamoroso
        wrote on last edited by
        #3

        Double Buffering...


        using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
        J 1 Reply Last reply
        0
        • Z Zizilamoroso

          Double Buffering...


          using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
          J Offline
          J Offline
          Jagadeesh VN
          wrote on last edited by
          #4

          Try this in OnDraw( CDC* dc ) like this CMemDC pDC(dc); if( !pDC->IsPrinting() ) { } "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

          1 Reply Last reply
          0
          • Z Zizilamoroso

            I'm having problems with the CMemDC inside a CStatic derived class. void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; } If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?


            using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
            Z Offline
            Z Offline
            Zizilamoroso
            wrote on last edited by
            #5

            I've changed it to a custom control derived from CWnd. Works fine now.


            using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
            1 Reply Last reply
            0
            • Z Zizilamoroso

              I'm having problems with the CMemDC inside a CStatic derived class. void MyStatic::OnPaint() { CPaintDC dc(this); CMemDC memDC(&dc); // tried with a rectangle param too CBrush brush(RGB(255,0,0)); CPen pen(PS_SOLID,1,RGB(0,0,0)); HBRUSH oldbrush=(HBRUSH)memDC->SelectObject(brush); HPEN oldpen=(HPEN)memDC->SelectObject(pen); memDC->Rectangle(&r); memDC->SelectObject(oldbrush); memDC->SelectObject(oldpen); } BOOL MyStatic::OnEraseBkgnd(CDC* pDC) { return TRUE; } If I use this inside a derived CSliderCtrl, for example, a nice red box will be drawn with a black outline on a gray dialog. Top! But inside a derived CStatic, the dialog is entirely white, nothing else. I've 2 different versions of CMemDC (both currently on codeproject), there's one that returns a white dialog, the other gives some random colors, like a corrupt bitmap. What am I doing wrong here?


              using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
              K Offline
              K Offline
              KaRl
              wrote on last edited by
              #6

              * If you want to set the background color, you should have a look to this article: http://www.codeproject.com/miscctrl/colorcontols.asp?target=ccolorstatic[^] On the use of MemDC: * To avoid flickering, OnEraseBkgnd should return FALSE. * you should use pointers with CDC::SelectObject CBrush *pOldBrush = memDC->SelectObject(&brush); CPen *pOldPen = memDC->SelectObject(&pen); ... memDC->SelectObject(pOldBrush); memDC->SelectObject(pOldPen);


              Every gun that is made, every warship launched, every rocket fired, signifies in the final sense a theft from those who hunger and are not fed, those who are cold and are not clothed - Dwight D. Eisenhower

              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