?
Solved

Delayed control refresh

Posted on 1998-06-01
10
Medium Priority
?
271 Views
Last Modified: 2013-11-19
I have a simple SDI app which has a CView with a single Active X control embedded (3-D plot) which fills the view. When the user resizes the view, I use MoveWindow() to tell the control to resize itself. The problem is that when the plot contains a large data set, and the user tries to drag one edge of the window to resize, the display goes dead until the control redraws. Hence, the user gets no visual feedback when he/she tries to resize the window. Is there a simple way to block redrawing of the control until the resize is done, or to force the view window to be redrawn first? SubclassWindow(), maybe, on the control?
0
Comment
Question by:jadcock
[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
10 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
ID: 1315900
One simple solution is to start a timer when the resize is being Started and keep it resetting it in on the next calls to the resize.  Then add the move window in the OnTimer part of code so the the windows will only redraw say .1 second after the last resize event.  To the user this should not be notiible but it will stop the control from redrawing itself everytime.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1315901
You may try sending the WM_SETREDRAW message to the control window.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1315902
I'v had exactly the same problem.

In my solution, while the user resizes the parent (CMainFrame) window i set a flag to prevent the view from drawing the actual data graph, but to only draw the x/y grid.

My views OnDraw function looks something like this:

    extern BOOL g_bWindowIsResizing;

    void CViewXXX::OnDraw(CPaintDC* pDC)
    {
        DrawXYGrid(pDC);
        if(!pDC->IsPrinting() && g_bWindowIsResizing)
        {
            // Skip drawing the actual data-graph if
            // frame window is currently resizing.
            return;
        }
   
        // Draw lines based on data.
        // Can take some time.
        DrawData(pDC);
    }

In order to know when the parent frame is resizing, you need to add handler for the WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE messages in your frame class.

Add these two lines to your frames message map (just above END_MESAGE_MAP):

      ON_MESSAGE(WM_ENTERSIZEMOVE, OnEnterSizeMove)
      ON_MESSAGE(WM_EXITSIZEMOVE, OnExitSizeMove)

Declare the functione in the header file, in the .h file:

      LRESULT            OnEnterSizeMove(WPARAM, LPARAM);
      LRESULT            OnExitSizeMove(WPARAM, LPARAM);

And in the .cpp file:

    BOOL g_bWindowIsResizing = FALSE;

    LRESULT CMainFrame::OnEnterSizeMove(WPARAM, LPARAM)
    {
        g_bWindowIsResizing = TRUE;
        return 0;
    }

    LRESULT COJGraphMDIFrame::OnExitSizeMove(WPARAM, LPARAM)
    {
        g_bWindowIsResizing = FALSE;
     
        // Get pointer to the view and invalidate it:
        CWnd* pWnd = GetDlgItem(AFX_IDW_PANE_FIRST);
        ASSERT_VALID(pWnd);
        pWnd->Invalidate();
        return 0;
    }
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:jadcock
ID: 1315903
Sorry about the delay, I've been out of town. Re the question, the chart is a 3rd-party OCX control (call it Chart), I don't "draw" it! All I do is call Chart::Create in the parent view's Create() function to attach it to the view. Even if I comment out the code which resizes the control, it still repaints when I resize the view. If I'm reading the MFC docs correctly, a WM_PAINT msg (or something similar) gets sent to the control, the view, and the frame, IN THAT ORDER, so the repaint of the control ties up the processor, causing the screen to go dead until the control's repaint finishes. I like piano_boxer's idea of detecting the start & end of resizing, but where do I block the redraw of the control until the resize is finished?
0
 

Author Comment

by:jadcock
ID: 1315904
Hurrah! I've finally figured it out; the answer is a combination of the piano_boxer and chensu answers:

1. Add message handlers to CMainFrame to process the WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE messages, a la piano_boxer, and
2. In the WM_ENTERSIZEMOVE handler, send a WM_SETREDRAW msg to the control to turn off redraw, and finally
3. In the WM_EXIT_SIZEMOVE handler, send another WM_SETREDRAW msg to the control to turn redraw back on.Code fragment below:

// CMainFrame message handlers
int CMainFrame::OnEnterSizeMove()
{
      // get pointer to view
      CView* pv = GetActiveView();
      if (pv)
      {
            // get pointer to chart
            CWnd* pw = pv->GetWindow(GW_CHILD);
            if (pw)
            {
                  // turn off control redraw
                  pw->SendMessage(WM_SETREDRAW,0,0);
            }
      }
      return 0;
}

int CMainFrame::OnExitSizeMove()
{
      // same as above, but turn control redraw back on
      CView* pv = GetActiveView();
      if (pv)
      {
            CWnd* pw = pv->GetWindow(GW_CHILD);
            if (pw)
            {
                  pw->SendMessage(WM_SETREDRAW,1,0);
                  pw->Invalidate();
            }
      }
      return 0;
}

Many thanks!!
0
 

Author Comment

by:jadcock
ID: 1315905
I sent a message to customer service a couple of weeks ago after I posted my solution to the problem (see command above), asking them to split the points between chensu & piano_boxer, but still no activity, the question is still posted as waiting for an answer. What gives?

.hello?... customer service? ... is anybody there? .... hello?...hello?...
0
 

Author Comment

by:jadcock
ID: 1315906
To all -- please ignore my previous comment; the question is still in my "personal" question list, but IS gone from the public list of waiting questions; hopefully they got their points...sorry about that
0
 
LVL 23

Expert Comment

by:chensu
ID: 1315907
linda answered your question at customer service on June 16 1998. You might not have received the email notification. Take a look at it.
0
 

Author Comment

by:jadcock
ID: 1315908
Right, I didn't get the E-mail for some reason; Chensu, please repost your answer and I'll OK it. Thanks.
0
 
LVL 23

Accepted Solution

by:
chensu earned 400 total points
ID: 1315909
Thank you. To be fair, can you please post another question to give points to piano_boxer as linda suggested?
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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