Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-06-08
7
Medium Priority
?
592 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 clear a vector as well as how to detect empty vectors in C++.

715 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