Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
 
System.Console
System.IntPtr
System.Runtime.InteropServices.LayoutKind




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734