Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnHScroll or OnVScroll executing twice

Tags:

c++

slider

mfc

I have an C++ MFC program and I'm trying to use a couple of horizontal sliders.

I already added ON_WM_HSCROLL() to my Message Map and I have this function to deal with changes in any slider:

void CAppDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{

    switch (pScrollBar->GetDlgCtrlID()) {
        case IDCAM1_ZOOMSLIDE:
            // do stuff
            return;
       case IDCAM2_ZOOMSLIDE:
            // do stuff
            return;
        default:
            return;
    }

    CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

I tried to put a breakpoint on the switch line and realized that every time I change the slider, OnHScroll() is executed 2 times.

Why is that and how can I change this behavior?

Thanks

like image 323
peugas Avatar asked Sep 18 '25 15:09

peugas


1 Answers

As Steve Wellens suggested,

I'm not using the nSBCode.

OnHScroll is being executed the first time with nSBCode=SB_PAGELEFT and a second time with nSBCode=SB_ENDSCROLL.

A simple switch or if is enough to deal with this.

like image 91
peugas Avatar answered Sep 21 '25 04:09

peugas