Solved

detecting a vscrollbar in msflexgrid vb6

Posted on 2014-02-19
8
240 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
  • 4
  • 4
8 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Try this in line 14

IsHScrollVisible = False
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
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
 

Author Comment

by:isnoend2001
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:isnoend2001
Comment Utility
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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
Thanks
Easy fix
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
You're welcome.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now