Solved

detecting a vscrollbar in msflexgrid vb6

Posted on 2014-02-19
8
245 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 46

Expert Comment

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

IsHScrollVisible = False
0
 
LVL 46

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 46

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 46

Expert Comment

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

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

777 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