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

x
?
Solved

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

Posted on 1998-06-08
7
Medium Priority
?
602 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
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 23

Accepted Solution

by:
chensu earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

963 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