|
Post by dragonjim on Mar 26, 2012 4:07:10 GMT 1
Hi,
I wonder if anyone could tell me how to manipulate the scrollbar on a TextBox / ListView OCX control.
Thanks for any help
|
|
|
Post by 649psoft2 on Mar 27, 2012 11:11:55 GMT 1
use the win32 API
GetScrollInfo GetScrollRange SetScrollInfo SetScrollPos SetScrollRange WM_HSCROLL WM_VSCROLL
|
|
|
Post by dragonjim on Mar 29, 2012 14:04:59 GMT 1
Thanks for that...however, I'm having some trouble getting them to work without an Access Violation Error.
My trial program is as below (concatenated to make it shorter):
Type SCROLLINFO cbSize As Integer : fMask As Integer : nMin As Integer : nMax As Integer : nPage As Integer : nPos As Integer : nTrackPos As Integer EndType
'Declare Function GetScrollInfo Lib "User32.dll" (ByVal Hdl As Handle, ByVal fnbar As Integer, info As SCROLLINFO) As Integer 'Declare Function SetScrollInfo Lib "User32.dll" (ByVal Hdl As Handle, ByVal fnbar As Integer, ByVal nPos As Integer, ByVal Redraw As Boolean)
OpenW 1 Ocx ListView win1_lv1 = , 100, 100, 400, 200 win1_lv1.View = 3 Local a$, m, n Dim ch As ColumnHeader For n = 1 To 4 Set ch = win1_lv1.ColumnHeaders.Add( , n, "Column " & n) Next n For n = 1 To 100 win1_lv1.Add , n , "" : a$ = "" For m = 1 To 4 : a$ = a$ & "Col " & m & " Row " & n & ";" : Next m win1_lv1(n).AllText = a$ Next n
Dim sinfo As SCROLLINFO Local b = GetScrollInfo(win1_lv1.hWnd, SB_VERT, sinfo) Print b Print sinfo.cbSize : Print sinfo.fMask : Print sinfo.nMin : Print sinfo.nMax : Print sinfo.nPage Print sinfo.nPos : Print sinfo.nTrackPos
~SetScrollInfo(win1_lv1.hWnd, SB_VERT, 600, True)
Do Sleep Until Win_1 Is Nothing
As you can see I have tried declaring the Windows API functions, as well as using the GFA application of these functions.
With the first, the Access Violation error occurs with both GetScrollInfo and SetScrollInfo, while with the second, only with SetScrollInfo.
I would appreciate any guidance as to where I am going wrong.
|
|
|
Post by 649psoft2 on Apr 2, 2012 8:24:18 GMT 1
I rewrote your example.
According to MSDN the cbSize cbSize nPage members of the SCROLLINFO structure are UINT and Long is used in gb32.
Also according to MSDN SetScrollInfo sets the values in the structure but does not sent the message to the scrollbar window.
Sendmessage is used to move the listview scrollbar.
The third parameter in SetScrollInfo is the pointer to the SCROLLINFO structure.
Type SCROLLINFO cbSize As Long fMask As Long nMin As Int nMax As Int nPage As Long nPos As Int nTrackPos As Int End Type
OpenW 1 Ocx ListView win1_lv1 = , 100, 100, 400, 200 win1_lv1.View = 3 Local a$, m, n Dim ch As ColumnHeader For n = 1 To 4 Set ch = win1_lv1.ColumnHeaders.Add( , n, "Column " & n) Next n For n = 1 To 100 win1_lv1.Add , n , "" : a$ = "" For m = 1 To 4 : a$ = a$ & "Col " & m & " Row " & n & ";" : Next m win1_lv1(n).AllText = a$ Next n
Dim sinfo As SCROLLINFO
'Local b = GetScrollInfo(win1_lv1.hWnd, SB_VERT, sinfo) 'Print b 'Print sinfo.cbSize : Print sinfo.fMask : Print sinfo.nMin : Print sinfo.nMax : Print sinfo.nPage 'Print sinfo.nPos : Print sinfo.nTrackPos
'sets parameters in the SCROLLINFO structure 'but does not send a message to a window
~SetScrollInfo(win1_lv1.hWnd, SB_VERT, V:sinfo, 0) Local n& For n& = 1 To 50 ~SendMessage(win1_lv1.hWnd, WM_VSCROLL, SB_VERT, 0) Next n&
Do : Sleep : Until Win_1 Is Nothing
|
|
|
Post by dragonjim on Apr 2, 2012 20:45:58 GMT 1
Once again, much obliged for your help.
I noticed the UInt (or unsigned integer) in the MSDN documentation but saw a VB example where they exchanged them for Integer variables - hence the error.
I am also now aware that I could use the EnsureVisible Method on the ListView control, but this doesn't help if the subitem or column selected is off the screen horizontally (i.e. the list is wider than the screen).
Thank you again for your help. It is, as always, much appreciated.
|
|