?
Solved

detecting a vscrollbar in msflexgrid vb6

Posted on 2014-02-19
8
Medium Priority
?
250 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 49

Expert Comment

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

IsHScrollVisible = False
0
 
LVL 49

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

Expert Comment

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month10 days, 6 hours left to enroll

765 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