?
Solved

Delteing an item from memoryDc.......................

Posted on 2003-03-14
2
Medium Priority
?
239 Views
Last Modified: 2013-11-20
hi,
my question regards using bitmap and memorydc to avoid window flickering.  I have  created a memorydc that stores a bitmap which in turn contains a user defined rectangle (using CreateCompatbleDC & CreateCompatibleBitmap). How can i remove the rectangle that is drawn on memorydc and place another new rectactangle in the MemoryDc? This is because when i zoom the rectagle  i want to get the zoomed image only, but now iam getting zoomed rectangle drawn on previous one. My coding is given below.

#include <afxwin.h>
#include  <stdio.h>
int x1 =100,y1=100,x2=200,y2=200;
CRect rcClient;
CDC dcMem;

class CMainWnd : public CFrameWnd {
   public:
      CMainWnd() {
          Create(0, "Rectangle Change", WS_OVERLAPPEDWINDOW,
          rectDefault,NULL,NULL);
         r1.left   =  100;
          r1.top    =  100;
         r1.bottom =  200;
         r1.right  =  200;
         CPaintDC dc(this);
            CBitmap bmMem;
            CBitmap* oldBitmap;
            CBrush cb(RGB(100,100,100));
            rcClient.top = 0;
            rcClient.left = 0;
            rcClient.bottom = 700;
         rcClient.right  = 700;
            dcMem.CreateCompatibleDC(&dc);
            bmMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
       
                oldBitmap = dcMem.SelectObject(&bmMem);
            dcMem.FillRect(rcClient,&cb);
        }


     void OnPaint(){
           
               CPaintDC dc(this);
            CBrush newbrush;
            CBrush* oldbrush;
            CPen newpen;
            CPen* oldpen;
            col = RGB(0,0,255);
            newpen.CreatePen (PS_SOLID,1,col);
            oldpen=dcMem.SelectObject (&newpen);
            newbrush.CreateSolidBrush (col);
            oldbrush = dcMem.SelectObject (&newbrush);
                   dcMem.Rectangle (r1);      
               BitBlt(dc,rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), dcMem, 0, 0, SRCCOPY);

    }


       void OnLButtonDown(UINT c, CPoint p) {
            //Zoom out the rectangle
               x1 += 20;
            y1 += 20;
            y2 -= 20;
            x2 -= 20;
            r1.left = x1;
            r1.top  = y1;
            r1.bottom = y2;
            r1.right = x2;
            Invalidate();    
       }
     
       void OnRButtonDown(UINT,CPoint p){
       // Zoom in the rectangle
            x1 -= 20;
            y1 -= 20;
            y2 += 20;
            x2 += 20;
            r1.left = x1;
            r1.top  = y1;
            r1.bottom = y2;
            r1.right = x2;
            Invalidate();    
      }

     bool OnEraseBkgnd(CDC* pDC){
            return true;
      }

     DECLARE_MESSAGE_MAP()
};


class myframe : public CWinApp {
      public:
      BOOL InitInstance()
      {
            m_pMainWnd = new CMainWnd();
            m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
            m_pMainWnd->UpdateWindow();
            return  TRUE;
      }
};

BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
         ON_WM_ERASEBKGND()  
         ON_WM_PAINT()
         ON_WM_LBUTTONDOWN()
         ON_WM_LBUTTONUP()
           ON_WM_RBUTTONDOWN()
         ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()

myframe a;

 Let knoe how to delete an item drawn on memorydc before writing new item.

0
Comment
Question by:hemanexp26
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 75 total points
ID: 8136927
You can always erase a memory DC bay drawing a rect with teh background color in a bitmap just before you draw the new rectangle.

Just add to the OnPaint function

CRect rcClient;
CBrush brBackground(::GetSysColor(COLOR_WINDOW))

GetClientRect(rcClient);
dcMem.FillRect(rcClient, &brBackground);


before actually drawing the rectangle.
0
 

Author Comment

by:hemanexp26
ID: 8210372
Thanx KurtVon. It is working.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question