Multimobile Development: Building Applications for any Smartphone
GetScrollInfo and Set ScrollInfo Issues
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.


Matthew Hazlett
GetScrollInfo works but I can not get setScrollInfo to wrok, it reports
Error 6 (Bad Handle). I use the same handle in GetScrollInfo as
SetScrollInfo, any ideas?

Const SBS_HORZ = 0
Const SBS_VERT = 1
Const SIF_RANGE = 1
Const SIF_PAGE = 2
Const SIF_POS = 4
Const SIF_DISABLENOSCROLL = 8
Const SIF_TRACKPOS = 10
Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)

' Structure to hold info
'
<StructLayout(LayoutKind.Sequential)> _
Public Structure SCROLLINFO
Public cbSize As Integer
Public fMask As Integer
Public nMin As Integer
Public nMax As Integer
Public nPage As Integer
Public nPos As Integer
Public nTrackPos As Integer
End Structure

' Imported Functions
'
Private Declare Function GetScrollInfo Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Integer, _
ByRef lpScrollInfo As SCROLLINFO) As Boolean

Private Declare Function SetScrollInfo Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nBar As Long, _
ByVal lpScrollInfo As SCROLLINFO, _
ByVal fRedraw As Boolean) As Boolean

Private Function getScroll(ByVal hWnd As IntPtr) As SCROLLINFO
Dim sc As New SCROLLINFO
sc.fMask = SIF_ALL
sc.cbSize = SizeOf(sc)

If GetScrollInfo(hWnd, SBS_VERT, sc) = False Then
Throw New Exception("Can not get scroll info (Err: " &
GetLastWin32Error() & ")")
Else
Console.WriteLine("Getting scroll info: Min=" & sc.nMin & " Max=" &
sc.nMax & " Pos=" & sc.nPos)
Return sc
End If
End Function

Private Sub scroll(ByVal hWnd As IntPtr, ByVal direction As Boolean)
Dim sc As SCROLLINFO = getScroll(hWnd)
sc.fMask = SIF_POS

If direction Then sc.nPos += 10 Else sc.nPos -= 10

Console.WriteLine("Setting scroll info: Min=" & sc.nMin & " Max=" &
sc.nMax & " Pos=" & sc.nPos)
If (Not SetScrollInfo(hWnd, SBS_VERT, sc, True)) Then
MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If
End Sub

Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Mattias Sjögren
Matthew,

[Original message clipped]


Should be Integer and ByRef respecitvely.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
 
System.Console
System.IntPtr
System.Runtime.InteropServices.LayoutKind




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734