How to determine if scrollbar is ON/OFF
Quang Ngo -- quang@psnw.com
Wednesday, August 28, 1996
Environment: Windows95 MSVC4.0
I need an easy way to determine if the scrollbar of a CListCtrl control
is ON or OFF. When the control is resized small enough that all of its
content is not visible the scrollbar is ON. The scrollbar is OFF when
all of the content is visible. Any ideas?
/*--------------------------------------------------------------------------
* Quang Ngo
* quang@valleynet.com
* 89-XJ6 89-300E P90 A3000/25 A1000 SNES PSX C C++ UNIX NT WIN95
*------------------------------------------------------------------------*/
Deepak Saxena -- Deepak_Saxena@ccm.ch.intel.com
Friday, August 30, 1996
Text item:
Subclass the ListCtrl's scrollbar with your own scrollbar and then overide
either OnEnable or OnShow for your scrollbar and then have it send a
notification message to whatever window you want to receive the notification.
To figure out what message to handle, use Spy++.
hmmm...there's gotta be an easier way?
Deepak
______________________________ Reply Separator _________________________________
Subject: How to determine if scrollbar is ON/OFF
Author: owner-mfc-l@majordomo.netcom.com at SMTPGATE
Date: 8/28/96 10:56 PM
Environment: Windows95 MSVC4.0
I need an easy way to determine if the scrollbar of a CListCtrl control
is ON or OFF. When the control is resized small enough that all of its
content is not visible the scrollbar is ON. The scrollbar is OFF when
all of the content is visible. Any ideas?
/*--------------------------------------------------------------------------
* Quang Ngo
* quang@valleynet.com
* 89-XJ6 89-300E P90 A3000/25 A1000 SNES PSX C C++ UNIX NT WIN95
*------------------------------------------------------------------------*/
Alex R. Moon -- odin@mdn.com
Sunday, September 01, 1996
Alternately, you can simply check if the rectangle returned by
CListCtrl::GetViewRect() is contained within the rectangle returned by
CListCtrl::GetClientRect().
For example:
CListCtrl ctlMyList;
CRect rcView, rcClient;
ctlMyList.GetViewRect( &rcView );
ctlMyList.GetClientRect( &rcClient );
if( CRect::UnionRect( &rcClient, &rcView ) == rcClient )
; // The scrollbar is off
else
; // the scrollbar is on
--
Alex R. Moon | "If you explain something so clearly that
odin@mdn.com | no one can misunderstand, someone will."
amoon@odin.mdn.com |
----------
> From: Deepak Saxena
> To: mfc-l@netcom.com
> Subject: Re: How to determine if scrollbar is ON/OFF
> Date: Friday, August 30, 1996 5:30 PM
>
> Subclass the ListCtrl's scrollbar with your own scrollbar and then overide
> either OnEnable or OnShow for your scrollbar and then have it send a
> notification message to whatever window you want to receive the
notification.
> To figure out what message to handle, use Spy++.
>
> hmmm...there's gotta be an easier way?
>
> Deepak
Dicky Singh -- Dicky@landmark.com
Tuesday, September 03, 1996
BOOL bSBVisible = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
----------
From: Quang Ngo[SMTP:quang@psnw.com]
Sent: Thursday, August 29, 1996 1:56 a
To: mfc-l@netcom.com
Subject: How to determine if scrollbar is ON/OFF
Environment: Windows95 MSVC4.0
I need an easy way to determine if the scrollbar of a CListCtrl control
is ON or OFF. When the control is resized small enough that all of its
content is not visible the scrollbar is ON. The scrollbar is OFF when
all of the content is visible. Any ideas?
/*--------------------------------------------------------------------------
* Quang Ngo
* quang@valleynet.com
* 89-XJ6 89-300E P90 A3000/25 A1000 SNES PSX C C++ UNIX NT WIN95
*------------------------------------------------------------------------*/
--------------------
Dicky Singh, Dicky@Landmark.COM
Dragon Team. Landmark Systems Inc.
8000 Towers Crescent, Vienna VA 22182
Quang Ngo -- quang@psnw.com
Tuesday, September 03, 1996
Hi Dicky,
Thanks for your response.
Apparently, you misunderstood my question. The WS_VSCROLL bit is there,
therefore, bSBVisible will be TRUE. What I am trying to determine is
whether the scrollbar (part of the list/tree control) is shown or not
shown. Technically, the scrollbar shows up when the control is small
enough that NOT all of its content fits in the client area.
Someone suggested to use GetViewRect(&rcView) and GetClientRect(&rcClient)
then compare... Actually, this method will not work since GetViewRect only
works for icon views, not list or report views.
-Quang
----------
> From: Dicky Singh
> To: 'mfc-l@netcom.com'
> Subject: RE: How to determine if scrollbar is ON/OFF
> Date: Tuesday, September 03, 1996 8:19 AM
>
> BOOL bSBVisible = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
>
> ----------
> From: Quang Ngo[SMTP:quang@psnw.com]
> Sent: Thursday, August 29, 1996 1:56 a
> To: mfc-l@netcom.com
> Subject: How to determine if scrollbar is ON/OFF
>
> Environment: Windows95 MSVC4.0
>
> I need an easy way to determine if the scrollbar of a CListCtrl control
> is ON or OFF. When the control is resized small enough that all of its
> content is not visible the scrollbar is ON. The scrollbar is OFF when
> all of the content is visible. Any ideas?
>
>
/*--------------------------------------------------------------------------
>
> * Quang Ngo
> * quang@valleynet.com
> * 89-XJ6 89-300E P90 A3000/25 A1000 SNES PSX C C++ UNIX NT WIN95
>
*------------------------------------------------------------------------*/
>
> --------------------
> Dicky Singh, Dicky@Landmark.COM
> Dragon Team. Landmark Systems Inc.
> 8000 Towers Crescent, Vienna VA 22182
Dicky Singh -- Dicky@landmark.com
Wednesday, September 04, 1996
[Mini-digest: 3 responses]
I probably got confused with ON / OFF.
I have used something similar to:
BOOL bSBVisible = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
in a List box, and it seemed to work.
Anyway, why don't you try the following lines (based on what you say:
"Technically, the scrollbar shows up when the control is small enough that
NOT all of its content fits in the client area.")
m_ListCtrl.GetClientRect(&rClient);
m_ListCtrl.GetItemRect(0, &rFirstRow, LVIR_BOUNDS);
m_ListCtrl.GetItemRect(m_ListCtrl.GetItemCount()-1, &rLastRow,
LVIR_BOUNDS);
If rFirstRow and rLastRow both are inside the client rect rClient then
there is no scroll bar. You may want to do an union rect on rFirstRow and
rLastRow and compare with rClient. check it out it may work with Report
Views.
I added a ListBox (m_List) and a ListCtrl (m_ListCtrl with Report View) to
an about box dialog. Here is OnInitDialog. Step thru' using a debugger
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_List.AddString("aaaa");
m_List.AddString("aaaa");
BOOL b=FALSE;
b = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
m_List.AddString("aaaa");
m_List.AddString("aaaa");
m_List.AddString("aaaa");
m_List.AddString("aaaa");
m_List.AddString("aaaa");
m_List.AddString("aaaa");
b = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
m_ListCtrl.InsertColumn(0, "aa", LVCFMT_LEFT, 30);
int i=0;
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
CRect r0, r1, rc;
m_ListCtrl.GetClientRect(&rc);
m_ListCtrl.GetItemRect(0, &r0, LVIR_BOUNDS);
m_ListCtrl.GetItemRect(m_ListCtrl.GetItemCount()-1, &r1, LVIR_BOUNDS);
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.InsertItem(i++, "sdsdsd");
m_ListCtrl.GetItemRect(0, &r0, LVIR_BOUNDS);
m_ListCtrl.GetItemRect(m_ListCtrl.GetItemCount()-1, &r1, LVIR_BOUNDS);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
-----From: Deepak Saxena
CListCtrl ctrlList;
BOOL bScrollVisible = ( ctrlList.GetCountPerPage() < ctrlList.GetItemCount() );
Note that this will only work for list and report views and not for icon views.
Deepak
-----From: dima@ssm6000.samsung.ru (Dulepov Dmitry)
[Mailer: "Groupware E-Mail". Version 1.0]
Try to use Spy++ on list/tree views with scroll bar and without=
it. In 'Styles'
dialog tab you will see that when the view has no scroll bar, it ha=
s no
WS_?SCROLL style and WS_?SCROLL is set when scroll bar is visible.
You may find an example of this processing in file VIEWSCRL.CPP=
in
MFC\SRC directory in "CScrollView::OnScrollBy" function. Although i=
t is not
list/tree view, but the logic is the same.
Dicky Singh was right.
Dmitry A. Dulepov
Groupware Group
Samsung Electronics Co., Ltd., Russian Research Center
Tel.: +7(095)213-9207
Fax.: +7(095)213-9196
E-Mail (Internet): dima@src.samsung.ru
Greg D. Tighe -- gdt@eng.aisinc.com
Thursday, September 05, 1996
How about calling GetScrollRange()/GetScrollInfo() ?
If nMin and nMax are both zero then your scrollbar is hidden,
otherwise it will be visible.
Note that this method will not notify you when the hidden/visible
state of the scrollbar changes - you will need to check for this in
all places where hiding/showing the scrollbar could happen, such as
OnSize(), inserting/deleting items, etc.
-Greg Tighe
Applied Intelligent Systems, Inc.
Ann Arbor, MI
gdt@aisinc.com
Grant Shirreffs Great Elk -- Grant.S@greatelk.co.nz
Friday, September 06, 1996
[Mini-digest: 2 responses]
Although sometimes nMax is 100 rather than zero if the scrollbars are
hidden.
----------
How about calling GetScrollRange()/GetScrollInfo() ?
If nMin and nMax are both zero then your scrollbar is hidden,
otherwise it will be visible.
Note that this method will not notify you when the hidden/visible
state of the scrollbar changes - you will need to check for this in
all places where hiding/showing the scrollbar could happen, such as
OnSize(), inserting/deleting items, etc.
-Greg Tighe
Applied Intelligent Systems, Inc.
Ann Arbor, MI
gdt@aisinc.com
-----From: "Quang Ngo"
> I have used something similar to:
> BOOL bSBVisible = (WS_VSCROLL == (m_List.GetStyle() & WS_VSCROLL));
> in a List box, and it seemed to work.
This method actually works. I tested and it worked just fine. The
WS_?SCROLL bit is toggled as the scrollbar appears and disappears.
Many thanks to Dicky and others.
-Quang
/*--------------------------------------------------------------------------
* Quang Ngo
* quang@valleynet.com
* 89-XJ6 89-300E P90 A3000/25 A1000 SNES PSX C C++ UNIX NT WIN95
*------------------------------------------------------------------------*/
| Вернуться в корень Архива
|