Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delayed control refresh

Posted on 1998-06-01
10
Medium Priority
?
276 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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