Solved

Dialog Box: Faster scrolling

Posted on 1998-12-08
6
309 Views
Last Modified: 2012-06-21
Hi,

I have written some code to implement scrolling within my dialog box, but is is very slow because I have over 100 controls in there. My code is below. What I am looking for is for a much faster and more robust piece of code to implement scrolling.

#########################################################
void DPRMYLDHKDdlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
      // TODO: Add your message handler code here and/or call default
      //##S

      int mdown = -450;
      int      mup = 450;
            
      #define      NUM_CTRL 109
      static      hkdidc[NUM_CTRL]={IDC_HkdFxRateSTATIC1,
      IDC_HkdCcySTATIC1,IDC_HkdValDateSTATIC1,IDC_HkdFxRateEDIT1,
      IDC_HkdCcyEDIT1,IDC_HkdValDateEDIT1,IDC_HkdStDcSTATIC1,
      IDC_HkdFutDcSTATIC1,IDC_HkdLtDcSTATIC1,IDC_HkdStDcEDIT1,
      IDC_HkdFutDcEDIT1,IDC_HkdLtDcEDIT1,IDC_HkdStBaseSTATIC1,
      IDC_HkdFutBaseSTATIC1,IDC_HkdLtBaseSTATIC1,IDC_HkdStBaseEDIT1,
      IDC_HkdFutBaseEDIT1,IDC_HkdLtBaseEDIT1,IDOK,
      IDC_HkdNumSTATIC1,IDC_HkdTenorSTATIC1,IDC_HkdInstruSTATIC1,
      IDC_HkdBidSTATIC1,IDC_HkdAskSTATIC1,IDC_HkdMidSTATIC1,
      IDC_HkdNum1STATIC1,IDC_HkdTenorEDIT1,IDC_HkdInstruEDIT1,
      IDC_HkdBidEDIT1,IDC_HkdAskEDIT1,IDC_HkdMidEDIT1,
      IDC_HkdNum2STATIC1,IDC_HkdTenorEDIT2,IDC_HkdInstruEDIT2,
      IDC_HkdBidEDIT2,IDC_HkdAskEDIT2,IDC_HkdMidEDIT2,
      IDC_HkdNum3STATIC1,IDC_HkdTenorEDIT3,IDC_HkdInstruEDIT3,
      IDC_HkdBidEDIT3,IDC_HkdAskEDIT3,IDC_HkdMidEDIT3,
      IDC_HkdNum4STATIC1,IDC_HkdTenorEDIT4,IDC_HkdInstruEDIT4,
      IDC_HkdBidEDIT4,IDC_HkdAskEDIT4,IDC_HkdMidEDIT4,
      IDC_HkdNum5STATIC1,IDC_HkdTenorEDIT5,IDC_HkdInstruEDIT5,
      IDC_HkdBidEDIT5,IDC_HkdAskEDIT5,IDC_HkdMidEDIT5,
      IDC_HkdNum6STATIC1,IDC_HkdTenorEDIT6,IDC_HkdInstruEDIT6,
      IDC_HkdBidEDIT6,IDC_HkdAskEDIT6,IDC_HkdMidEDIT6,
      IDC_HkdNum7STATIC1,IDC_HkdTenorEDIT7,IDC_HkdInstruEDIT7,
      IDC_HkdBidEDIT7,IDC_HkdAskEDIT7,IDC_HkdMidEDIT7,
      IDC_HkdNum8STATIC1,IDC_HkdTenorEDIT8,IDC_HkdInstruEDIT8,
      IDC_HkdBidEDIT8,IDC_HkdAskEDIT8,IDC_HkdMidEDIT8,
      IDC_HkdNum9STATIC1,IDC_HkdTenorEDIT9,IDC_HkdInstruEDIT9,
      IDC_HkdBidEDIT9,IDC_HkdAskEDIT9,IDC_HkdMidEDIT9,
      IDC_HkdNum10STATIC1,IDC_HkdTenorEDIT10,IDC_HkdInstruEDIT10,
      IDC_HkdBidEDIT10,IDC_HkdAskEDIT10,IDC_HkdMidEDIT10,
      IDC_HkdNum11STATIC1,IDC_HkdTenorEDIT11,IDC_HkdInstruEDIT11,
      IDC_HkdBidEDIT11,IDC_HkdAskEDIT11,IDC_HkdMidEDIT11,
      IDC_HkdNum12STATIC1,IDC_HkdTenorEDIT12,IDC_HkdInstruEDIT12,
      IDC_HkdBidEDIT12,IDC_HkdAskEDIT12,IDC_HkdMidEDIT12,
      IDC_HkdNum13STATIC1,IDC_HkdTenorEDIT13,IDC_HkdInstruEDIT13,
      IDC_HkdBidEDIT13,IDC_HkdAskEDIT13,IDC_HkdMidEDIT13,
      IDC_HkdNum14STATIC1,IDC_HkdTenorEDIT14,IDC_HkdInstruEDIT14,
      IDC_HkdBidEDIT14,IDC_HkdAskEDIT14,IDC_HkdMidEDIT14};

      CRect      hkdrect[NUM_CTRL];
      CWnd      *hkdpCtrl[NUM_CTRL];
      int i;
      for      (i = 0; i < NUM_CTRL; i++) {
            hkdpCtrl[i]=GetDlgItem(hkdidc[i]);
      }




      switch (nSBCode)
      {
            
      case SB_BOTTOM:

            break;

      case SB_TOP:

            break;

      case SB_PAGEDOWN:

            break;

      case SB_PAGEUP:

            break;

      case SB_LINEDOWN:

            for      (i = 0; i < NUM_CTRL; i++) {
                  hkdpCtrl[i]->GetWindowRect(&hkdrect[i]);
                  ScreenToClient(&hkdrect[i]);
                  hkdrect[i] += CPoint (0,mdown);
                  hkdpCtrl[i]->MoveWindow(hkdrect[i]);
            }
            //UpdateData(FALSE);
            Invalidate();


    break;

      case SB_LINEUP:

            for      (i = 0; i < NUM_CTRL; i++) {
                  hkdpCtrl[i]->GetWindowRect(&hkdrect[i]);
                  ScreenToClient(&hkdrect[i]);
                  hkdrect[i] += CPoint (0,mup);
                  hkdpCtrl[i]->MoveWindow(hkdrect[i]);
            }
            //UpdateData(FALSE);
            Invalidate();



            break;

      case SB_THUMBPOSITION:
            
            break;
      }
      //##E

      CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
##########################################################

Rgds,
A.
0
Comment
Question by:decornez
6 Comments
 
LVL 6

Accepted Solution

by:
stsanz earned 20 total points
ID: 1179531
Use BeginDeferWindowPos/EndDeferWindowPos WIN32 APIs to move simultaneously all your controls.




0
 
LVL 22

Expert Comment

by:nietod
ID: 1179532
Also associated with that, specify the flag that prevents the moved window from redrawing (I don't remember what it is called) and then scroll the window with ScrollWindow()  This will update the screen much faster.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1179533
You probably mean the WM_SETREDRAW message.

0
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

 
LVL 22

Expert Comment

by:nietod
ID: 1179534
No, I meant the DWP_NOTREDRAW flag to the DeferWindowPos() procedure.  It is much faster for the OS to move the windows without updating the screen and then just scroll the pixels on screen and finally just paint the small area exposed.
0
 

Author Comment

by:decornez
ID: 1179535
Going off on holiday until the 17th of dec.

I will try your suggestions when I get back and will let you know then.

Thanks,
A.
0
 

Author Comment

by:decornez
ID: 1179536
Stanz,

Thanks for your help.
I actually used Nietod's suggestion. I used ScrollWindow() in conjunction with UpdateWindow(). It is extremely fast, easy to implement, and there is no flickering.

Nietod,

Thanks for your suggestion.
I'll post some points for you.

Rgds,
A.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 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