Solved

VC++ - How to  Determine which scrollbar/window sends message

Posted on 1998-06-08
7
557 Views
Last Modified: 2010-05-18
I am overiding the ::OnVscroll() in my app to handle the actions from a slider control in my view. The problem is that when the View is minimized and its scrollbars appear they also send an ::OnVscroll() message. Within the OnVscroll() to test to see where the scroll event came from. How do I do this?  
0
Comment
Question by:englm
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1165444
I'm confussed.  There should be no scroll bars when the view is minimized.

If this helps, you can use the IsIconic() function to see if the windows is minimuzed.
0
 

Author Comment

by:englm
ID: 1165445
When the application window is made smaller (to a point where controls in the view extend past the window) scroll bars appear. In my app these are part of the CFormView.

In the MS help I found a section which says to use:

if (pScrollBar->IsKindOf(RUNTIME_CLASS( CSliderCtrl)))
    {
        CWnd::OnVScroll( nSBCode, nPos, pScrollBar );
    }

in the ::OnVscroll() function, but haven't made this work correctly.


0
 

Expert Comment

by:unmeshv
ID: 1165446
are u overriding OnVScroll event in your app object?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1165447
From the documentation:

"A slider control notifies its parent window of user actions by sending the parent WM_HSCROLL messages. You can override the parent's OnHScroll member function to handle these messages. This function will be passed a notification code, the position of the slider, and a pointer to the CSliderCtrl object. Note that the pointer is of type CScrollBar * even though it points to a CSliderCtrl object. You may need to typecast this pointer if you need to manipulate the slider control.

Rather than using the scroll bar notification codes, slider controls send a different set of notification codes. A slider control sends the TB_BOTTOM, TB_LINEDOWN, TB_LINEUP, and TB_TOP notification codes only when the user interacts with a slider control by using the keyboard. The TB_THUMBPOSITION and TB_THUMBTRACK notification messages are only sent when the user is using the mouse. The TB_ENDTRACK, TB_PAGEDOWN, and TB_PAGEUP notification codes are sent in both cases."

By comparing the pScrollBar parameter with the pointers of your slider controls, you are able to determine which slider control sends the notification message.
0
 

Author Comment

by:englm
ID: 1165448
chensu,

I understand the TB_ notifications of the slider. I was trrying to implement the code below which handles the slider ok, but with my code any movement of the scrollbars on the view window cause an exception to be thrown.

void CMyView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
         //if detect movement of slider           
         if (pScrollBar->IsKindOf( RUNTIME_CLASS( CSliderCtrl))) {        
         if(nSBCode == SB_ENDSCROLL && m_defbox.GetCurSel() == 1)
                //do something when slider move ends      
         CFormView::OnVScroll( nSBCode, nPos, pScrollBar);            
         }
         
         else
             //other scrollbar were moved  
             CFormView::OnVScroll( nSBCode, nPos, pScrollBar);      
}

0
 
LVL 23

Expert Comment

by:chensu
ID: 1165449
The parameter pScrollBar is NULL if the user clicked the scroll bar of the view window. It contains a pointer to the control only if the scroll message came from a scroll-bar or slider control.

So, you need to check

if (pScrollBar == NULL)
{
    // from the scroll bar of the view window
    ...
}
else
{
    // from the control
    ...
}

0
 

Author Comment

by:englm
ID: 1165450
chensu,

I came upon this yesterday myself - I can do what i need to. Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.

685 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