Solved

detecting a vscrollbar in msflexgrid vb6

Posted on 2014-02-19
8
247 Views
Last Modified: 2014-02-19
I am trying to set the width of a Msflexgrid based on if it has a vertical scrollbar
Code:
Const GWL_STYLE = (-16)
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
 
Private Declare Function GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" ( _
        ByVal Hwnd As Long, _
        ByVal nIndex As Long) As Long
 
'==================================================================
Public Function IsHScrollVisible(Hwnd As Long) As Boolean
    Dim Style As Long
    Style = GetWindowLong(Hwnd, GWL_STYLE)
 
    If (Style And WS_HSCROLL) Then
        IsHScrollVisible = True
        Exit Function
    End If
 
End Function
 
'==================================================================
Public Function IsVScrollVisible(Hwnd As Long) As Boolean
    Dim Style As Long
    Style = GetWindowLong(Hwnd, GWL_STYLE)
 
    If (Style And WS_VSCROLL) Then
        IsVScrollVisible = True
        Exit Function
    End I
 
End Function
 



Sub PositionForm_Grid
gridStats.Width = 12184
       
  If IsVScrollVisible(gridStats.Hwnd) = False Then
    gridStats.Width = 11800 
  End If

Open in new window

The first time this Function is called it is false(this is correct)
The second time it reports true even though its not visible
Why is this ?
0
Comment
Question by:isnoend2001
[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
  • 4
  • 4
8 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39871012
Try this in line 14

IsHScrollVisible = False
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39871079
Actually it works fine as is for me so something else must be going on. Please attach your project in a zip file and tell me how to reproduce what you are seeing.
0
 

Author Comment

by:isnoend2001
ID: 39871336
Thanks martinLiss
I will upload the form as soon as i get it modified (Remove Ocx's etc)
The function is in a module
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:isnoend2001
ID: 39871614
martinLiss just click the button top left of form with caption '"Add text1 Rows"
will add the number of rows in text1 to grid
line 486 is the call
For-EE.zip
0
 

Author Comment

by:isnoend2001
ID: 39871791
This line is not always hit when false
 gridStats.Width = 11800 'shorten the width

 in Sub PositionForm_Grid()

If IsVScrollVisible(gridStats.HWND) = False Then
       gridStats.Width = 11800 'shorten the width
  End If

This works correctly
Private Sub Command2_Click()
MsgBox IsVScrollVisible(gridStats.HWND)
End Sub
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39871794
I don't see the problem. Here's what happens when I click Command1.

First click:
1.    Rows are added
2.    Scrollbar is added because the grid is currently too short
3.    Because of that isVScrollVisible(gridStats.HWND) is True so the Width is not changed
4.    gridStats.Rows < iMax_Nu_Rows so the height is adjusted
5.    Because of that the scrollbar disappears

(The width should be adjusted at this point but it isn't)
Second click:
1.    The width is decreased because the scrollbar isn't visible.


Given what i've pointed out if you need any help correctly thge problem please let me know.
0
 

Author Closing Comment

by:isnoend2001
ID: 39871808
Thanks
Easy fix
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39871824
You're welcome.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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