;user32"(ByVal hwnd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32"() As Long
Private Declare Function ReleaseDC Lib "user32"(ByVal hwnd As Long,ByVal hdc As Long) As Long
Dim sWin,sDC,hd
Dim ImageWidth As Long,ImageHeight As Long
Dim DX,DY,SX,SY,PX,PY,DW,DH,MX,MY,X0,Y0,AMP
4.双击ImageWin对象,并在MouseMove事件和Mousedown事件中输入下面
程序,用于窗口图形的拖动滚动处理。
Private Sub ImageWin_MouseMove(Button As Integer,Shift As Integer,X As Single,Y As Single)
If (Button and vbLeftButton)>0 Then
''拖动鼠标滚动图像
MX=HScroll1.Value+(X-X0)
MY=VScroll1.Value+(Y-Y0)
If MX>0 and MX<HScroll1.Max Then HScroll1.Value=MX
If MY>0 and MY<VScroll1.Max Then VScroll1.Value=MY
End If
End Sub
Private Sub ImageWin_MouseDown(Button As Integer,Shift As Integer,X As Single,Y As Single)
X0=X:Y0=Y''拖动鼠标初值
End Sub
5.在ZoomIn控件和ZoomOut的Click事件中输入下列
程序,对窗口图像进行放大、缩小处理。
Private Sub ZoonIn_Click()
If AMP<5 Then AMP=2*AMP
''放大系数小于5,则放大图像
AppImage.ImageWin.PaintPicture ImageWin.Image,0,0,AMP*DX,AMP*DY,PX,PY,SX,SY
End Sub
Private Sub ZoomOut_Click()
AppImage.ImageWin.Cls
''清除窗口图像
If AMP>0.25 Then AMP=AMP/2
''放大系数大于0.25,则缩小图像
AppImage.ImageWin.PaintPicture ImageWin.Image,0,0,AMP*DX,AMP*DY,PX,PY,SX,SY
End Sub
6.在HScroll控件和VScroll控件的Change事件中输入下面
程序,对窗口图像进行滚动处理。
Private Sub HScroll1_Change()
PX=HScroll1.Value*DW/HScroll1.Max
''计算水平滚动位置
AppImage.ImageWin.PaintPicture ImageWin.Image,0,0,AMP*DX,AMP*DY,PX,PY,SX,SY
End Sub
Private Sub VScroll1_Change()
PY=VScroll1.Value*DH/VScroll1.Max
''计算垂直滚动位置
AppImage.ImageWin.PaintPicture ImageWin.Image,0,0,AMP*DX,AMP*DY,PX,PY,SX,SY
End Sub
7.在ExitButton控件的Click事件中输入下面程序,用于结束
程序、关闭窗口。
Private Sub ExitButton_Click()
End
End Sub
五、应用说明
窗口图像滚动是各种数据
查询系统、多媒体图形数据库系统开发中的基本功能之一,本文用Windows API函数实现了窗口图像缩放、滚动,该方法可适用于Visual C++等语言。本文全部
程序均在WIN98环境中Visual Basic5.0下调试通过。