Solved

saving private processor

Posted on 2003-12-12
5
195 Views
Last Modified: 2013-11-20
hi, below is my on draw...
it works fine as below...

code:
--------------------------------------------------------------------------------
void CEditorView::OnDraw(CDC* dc)
{
      CMemDC pDC(dc);
      OnPrepareDC(pDC);
          CEditorDoc* pDoc = GetDocument();
          ASSERT_VALID(pDoc);
          // TODO: add draw code for native data here - use pDC
           //as the device context to draw to
      
      //
      //Set the mapping mode to LOENGLISH
      //
      pDC->SetMapMode(MM_LOENGLISH);

      //
      //Convert arguments to coordinates to MM_LOENGLISH units.
      //
      CSize szTemp;
      szTemp.cx = pDoc->GetGridX();
      szTemp.cy = pDoc->GetGridY();
      pDC->DPtoLP(&szTemp);


      //
      // then draw the grid lines
      //
      CRect clipBoxRect;
      pDC->GetClipBox(&clipBoxRect);
      for(int x = 10 ; x <= pDoc->GetGridX() ; x += 10) {
            pDC->MoveTo(x, -10);
            pDC->LineTo(x, -pDoc->GetGridY());
      }
      
      for(int y = -10 ; y >= -pDoc->GetGridY() ; y -=10) {
            pDC->MoveTo(10, y);
            pDC->LineTo(pDoc->GetGridX(), y);
      }
}
--------------------------------------------------------------------------------

it works perfectly fine as below....
now the problem is i wanan add this to my above code

code:
--------------------------------------------------------------------------------
      //
      //Draw the squares
      //
      for(int i = 0 ; i < 500 ; i ++) {
            for(int j = 0 ; j < 750 ; j ++) {
                  COLORREF color = pDoc->GetSquareColor(i, j);
                  CBrush brush(color);
                  int x1 = (j * 10) + 10;
                  int y1 = (i * -10) - 10;
                  int x2 = x1 + 10;
                  int y2 = y1 - 10;
                  CRect rect(x1, y1, x2, y2);
                  pDC->FillRect(rect, &brush);
            }
      }
--------------------------------------------------------------------------------

when i do this...
all the processing power of the processor is eaten up by the processor....
can someone pls tell me a solution by which i can incorporate the above code to my View's OnDraw such that i can still retain my processing power????
tks a lot...
0
Comment
Question by:joseph-r-thomas
  • 4
5 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 9926763
With your code you are doing for every OnPaint event a iteration of 375000 FillRects. How often does the colors change? My suggestion is to replace the loop in some other function to fill a bitmap with that pattern and in the OnDraw handler you just BitBlt this bitmap into your device context. For updating this bitmap you should think about looking for changed colors and modify only those parts.
0
 
LVL 13

Expert Comment

by:SteH
ID: 9926853
This is highly related to your Q
www.expersts-exchange.com/Q20823821.html
The my answer there, it should solve this problem as well.
0
 
LVL 13

Expert Comment

by:SteH
ID: 9926867
0
 

Author Comment

by:joseph-r-thomas
ID: 9932738
hope u could pls drop me a line at
extremedotnet@yahoo.com.sg
i could send u m proj..its very small..
hope to hear from u soon...
tks a lot..
0
 
LVL 13

Accepted Solution

by:
SteH earned 20 total points
ID: 9940580
Solving problems with use of e-mail is forbidden by the membership agreement you signed as well. You could put it on a public www page, where everyone is able to see it as he wants to.

And I still feel that you should follow my suggestion I posted in
http://www.experts-exchange.com/Q_20823821.html
which merely is to fully understand the solution to
http://www.experts-exchange.com/Q_20817068.html
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now