Solved

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

Posted on 1998-06-08
7
577 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
Independent Software Vendors: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

622 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