Solved

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

Posted on 1998-06-08
7
546 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
Comment Utility
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
Comment Utility
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
Comment Utility
are u overriding OnVScroll event in your app object?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
chensu,

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

Featured Post

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

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

728 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

9 Experts available now in Live!

Get 1:1 Help Now