Solved

Delayed control refresh

Posted on 1998-06-01
10
256 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
10 Comments
 
LVL 1

Expert Comment

by:Andy_Keys
Comment Utility
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
Comment Utility
You may try sending the WM_SETREDRAW message to the control window.
0
 
LVL 4

Expert Comment

by:piano_boxer
Comment Utility
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
 

Author Comment

by:jadcock
Comment Utility
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
Comment Utility
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
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).

 

Author Comment

by:jadcock
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
Thank you. To be fair, can you please post another question to give points to piano_boxer as linda suggested?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 64
Host to IP 7 73
format the code in java 6 72
pre4 challenge 19 88
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

17 Experts available now in Live!

Get 1:1 Help Now