Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dialog Box: Faster scrolling

Posted on 1998-12-08
6
Medium Priority
?
317 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 60 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
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.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

916 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