Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-14
2
Medium Priority
?
242 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Screencast - Getting to Know the Pipeline
Suggested Courses

581 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