Private Declare Function SetScrollPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal nBar As Long, _
ByVal nPos As Long, _
ByVal bRedraw As Long) As LongPrivate Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_BOTH = 3Private Sub Command1_Click()
SetScrollPos Text1.hwnd, SB_HORZ, 2, True '水平
SetScrollPos Text1.hwnd, SB_VERT, 20, True '垂直
End Sub
(ByVal hwnd As Long, _
ByVal nBar As Long, _
ByVal nPos As Long, _
ByVal bRedraw As Long) As LongPrivate Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_BOTH = 3Private Sub Command1_Click()
SetScrollPos Text1.hwnd, SB_HORZ, 2, True '水平
SetScrollPos Text1.hwnd, SB_VERT, 20, True '垂直
End Sub
解决方案 »
- 关于Twip和POINTS2D
- 找不到DLL入口点,各位大哥们帮帮忙。着急着急!!!!!!!!!!!
- 奇怪,keyup事件能用TAB键吗
- 在ActiveX DLL中如何终止当前应用程序?
- 巨简单问题,关于查询,在线等
- 怎样得到别的程序的控件名
- 关于可插入式对象Excel的操作问题
- VB连接Oracle时出错!非常奇怪的问题!
- 超急!什么是FTP服务器,它有什么特性,要使一台DOS系统的机变成FTP服务器要装什么软件?(注:DOS机的HARD DISK很小只有32M)
- Set anotherform.MSFlexGrid.datasource = Adodc1
- 请各位发表一下在程序中碰到的各个error以及如何对程序中各error进行控制和处理
- 如何做网站的客户端程序?急,请帮忙。
The SetScrollInfo function sets the parameters of a scroll bar, including the minimum and maximum scrolling positions, the page size, and the position of the scroll box (thumb). The function also redraws the scroll bar, if requested.int SetScrollInfo(
HWND hwnd, // handle to window with scroll bar
int fnBar, // scroll bar flag
LPSCROLLINFO lpsi,
// pointer to structure with scroll parameters
BOOL fRedraw // redraw flag
);
Parameters
hwnd
Handle to a scroll bar control or a window with a standard scroll bar, depending on the value of the fnBar parameter.
fnBar
Specifies the type of scroll bar for which to set parameters. This parameter can be one of the following values: Value Meaning
SB_CTL Sets the parameters of a scroll bar control. The hwnd parameter must be the handle to the scroll bar control.
SB_HORZ Sets the parameters of the given window's standard horizontal scroll bar.
SB_VERT Sets the parameters of the given window's standard vertical scroll bar.
lpsi
Pointer to a SCROLLINFO structure. Before calling SetScrollInfo, set the cbSize member of the structure to sizeof(SCROLLINFO), set the fMask member to indicate the parameters to set, and specify the new parameter values in the appropriate members.
The fMask member can be a combination of the following values: Value Meaning
SIF_DISABLENOSCROLL Disables the scroll bar instead of removing it, if the scroll bar's new parameters make the scroll bar unnecessary.
SIF_PAGE Sets the scroll page to the value specified in the nPage member of the SCROLLINFO structure pointed to by lpsi.
SIF_POS Sets the scroll position to the value specified in the nPos member of the SCROLLINFO structure pointed to by lpsi.
SIF_RANGE Sets the scroll range to the value specified in the nMin and nMax members of the SCROLLINFO structure pointed to by lpsi. fRedraw
Specifies whether the scroll bar is redrawn to reflect the changes to the scroll bar. If this parameter is TRUE, the scroll bar is redrawn, otherwise, it is not redrawn.
Return Values
The return value is the current position of the scroll box. Res
The SetScrollInfo function performs range checking on the values specified by the nPage and nPos members of the SCROLLINFO structure. The nPage member must specify a value from 0 to nMax - nMin +1. The nPos member must specify a value between nMin and nMax - max(nPage – 1, 0). If either value is beyond its range, the function sets it to a value that is just within the range. Windows CE: In Windows CE 2.0, if you pass a null pointer in the lpsi parameter, SetScrollInfo returns zero, rather than the current position of the scroll box. QuickInfo
Windows NT: Requires version 3.51 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.
Import Library: Use user32.lib.
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End TypePublic Const SB_BOTH = 3
Public Const SB_HORZ = 0
Public Const SB_VERT = 1
Public Const SIF_ALL = 23
Public Const SIF_RANGE = 1
Public Const SIF_PAGE = 2
Public Const SIF_POS = 4
Public Const SIF_TRACKPOS = 16'用法示例
'Dim si As SCROLLINFO
'si.cbSize = Len(si)
'si.fMask = SIF_ALL
'si.nMax = 100
'si.nMin = 0
'si.nPage = 50
'si.nPos = 20
'SetScrollInfo hwnd, SB_VERT, si, True
而是在MDI窗体的“MDIClient”控件上你可以用FindWindowEx去查找它的句柄
http://www.csdn.net/expert/topic/1050/1050384.xml?temp=.4546167
在MDI子窗体中放置一个按键(Command1)、一个文本框(Text1),文本框的MultiLine设为True
MDIForm1:Private Sub MDIForm_Load()
Form1.Show
End Sub
Form1:Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As LongPrivate Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End TypePrivate Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_CTL = 2
Private Const SB_BOTH = 3Private Const SIF_RANGE = 1
Private Const SIF_PAGE = 2
Private Const SIF_POS = 4
Private Const SIF_TRACKPOS = &H10
Private Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOSPrivate Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPrivate Sub Command1_Click()
Dim SI As SCROLLINFO
Dim TemphWnd As Long
TemphWnd = FindWindowEx(MDIForm1.hWnd, 0, "MDIClient", vbNullString)
'Debug.Print TemphWnd
Text1.Text = ""
SI.cbSize = Len(SI)
SI.fMask = SIF_ALL
GetScrollInfo TemphWnd, SB_HORZ, SI
Text1.Text = Text1.Text + "水平滚动条:" + vbCrLf
Text1.Text = Text1.Text & "nMin:" & SI.nMin & vbCrLf
Text1.Text = Text1.Text & "nMax:" & SI.nMax & vbCrLf
Text1.Text = Text1.Text & "nPage:" & SI.nPage & vbCrLf
Text1.Text = Text1.Text & "nPos:" & SI.nPos & vbCrLf
Text1.Text = Text1.Text & "nTrackPos:" & SI.nTrackPos & vbCrLf
Text1.Text = Text1.Text + vbCrLf
SI.cbSize = Len(SI)
SI.fMask = SIF_ALL
GetScrollInfo TemphWnd, SB_VERT, SI
Text1.Text = Text1.Text + "垂直滚动条:" + vbCrLf
Text1.Text = Text1.Text & "nMin:" & SI.nMin & vbCrLf
Text1.Text = Text1.Text & "nMax:" & SI.nMax & vbCrLf
Text1.Text = Text1.Text & "nPage:" & SI.nPage & vbCrLf
Text1.Text = Text1.Text & "nPos:" & SI.nPos & vbCrLf
Text1.Text = Text1.Text & "nTrackPos:" & SI.nTrackPos & vbCrLf
End SubPrivate Sub Form_Load()
Command1.Caption = "取得信息"
End Sub
MDI窗体的滚动条就是通过nMin、nMax设定的
而不是像一般程序那样用nPos
另外,不论用SetScrollInfo还是SetScrollPos来移动滚动条后,滚动块的位置是变化了,可是窗口内容并没有随着卷动.在没有找到其它的方法来自动同时移动滚动条和窗口内容的情况下我只好做了个循环调用SendMessage来一次卷动一行,可是太不专业了,有谁有更好的办法请告诉我.
(不要用SetScrollInfo,只发送消息,估计移动的量去改变wParam)
WM_HSCROLL
The WM_HSCROLL message is sent to a window when a scroll event occurs in the window's standard horizontal scroll bar. This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control. WM_HSCROLL
nScrollCode = (int) LOWORD(wParam); // scroll bar value
nPos = (short int) HIWORD(wParam); // scroll box position
hwndScrollBar = (HWND) lParam; // handle to scroll bar
Parameters
nScrollCode
Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values: Value Meaning
SB_ENDSCROLL Ends scroll.
SB_LEFT Scrolls to the upper left.
SB_RIGHT Scrolls to the lower right.
SB_LINELEFT Scrolls left by one unit.
SB_LINERIGHT Scrolls right by one unit.
SB_PAGELEFT Scrolls left by the width of the window.
SB_PAGERIGHT Scrolls right by the width of the window.
SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.
SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.
nPos
Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.
hwndScrollBar
Value of lParam. If the message is sent by a scroll bar, then hwndScrollBar is the handle to the scroll bar control. If the message is not sent by a scroll bar, hwndScrollBar is NULL.
Return Values
If an application processes this message, it should return zero. Res
The SB_THUMBTRACK notification message is typically used by applications that provide feedback as the user drags the scroll box. If an application scrolls the content of the window, it must also reset the position of the scroll box by using the SetScrollPos function. Note that the WM_HSCROLL message carries only 16 bits of scroll box position data. Thus, applications that rely solely on WM_HSCROLL (and WM_VSCROLL) for scroll position data have a practical maximum position value of 65,535. However, because the SetScrollInfo, SetScrollPos, SetScrollRange, GetScrollInfo, GetScrollPos, and GetScrollRange functions support 32-bit scroll bar position data, there is a way to circumvent the 16-bit barrier of the WM_HSCROLL and WM_VSCROLL messages. See GetScrollInfo for a description of the technique. QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in winuser.h.