在picture1中放一个picture2
vscroll,hscroll都放在picture1中!Private Sub VScroll1_Change()
Picture2.Top = -VScroll1.Value
End SubPrivate Sub HScroll1_Change()
Picture2.Left = -HScroll1.Value
End Sub
vscroll,hscroll都放在picture1中!Private Sub VScroll1_Change()
Picture2.Top = -VScroll1.Value
End SubPrivate Sub HScroll1_Change()
Picture2.Left = -HScroll1.Value
End Sub
PictureBox:Name = ImageWin, Appearance = 1-3D, ScaleMode = 3
CommandButton:Name = ZoomIn, Caption="Zoom In"
CommandButton:Name = ZoomOut, Caption="Zoom Out"
CommandButton:Name = ExitButton, Caption="Exit" 2.双击FORM窗口,并将下面程序输入到Form对象的Load事件中。该程序用于读取图像的宽度和高度,初始化常用参数,载入窗口图像,并将图像复制到FORM窗口的PictureBox图形控件容器中显示。
Private Sub Form_Load()
Dim FileName As String
FileName = "C:\SAMP.BMP"
Open FileName For Binary As #1
Get #1, 19, ImageWidth: Get #1, , ImageHeight '读取位图的宽度和高度
Close #1DW = 15 * ImageWidth - ImageWin.Width '将像点转换为Twip(微点)DH = 15 * I
mageHeight - ImageWin.Height
ImageWin.Width = 15 * ImageWidth
ImageWin.Height = 15 * ImageHeight
AppImage.AutoRedraw = True
AppImage.Caption = FileName '改变Form窗标题
HScroll1.SmallChange = 100 '设置滚动最小步距
VScroll1.SmallChange = 100
DX = ImageWin.Width: DY = ImageWin.Height '设置复制图像尺寸
SX = ImageWin.Width: SY = ImageWin.Height
AMP = 1 '设置缩放比例为1
sWin = GetDesktopWindow() '获取桌面窗口句柄
sDC = GetDC(sWin) '转换为描述表句柄
hd = BitBlt(ImageWin.hdc, 0, 0, Image.Width, Image.Height, sDC, 0, 0, &HCC0020)h
d = ReleaseDC(sWin, sDC) '释放窗口描述表
AppImage.ImageWin = LoadPicture(FileName) '载入图像显示
End Sub 3.在General对象的Declaration过程中声明本程序所使用的WIN95 API函数和和过程,以及各事件程序所使用的全局变量等。
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As L
ong, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC A
s Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As LongPriva
te Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As LongPrivate Declar
e Function GetDesktopWindow Lib "user32" () As LongPrivate Declare Function Relea
seDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As LongDim sWin, sDC, h
d
Dim ImageWidth As Long, ImageHeight As Long
Dim DX, DY, SX, SY, PX, PY, DW, DH, MX, MY, X0, Y0, AMP 4.双击ImageWin对象,并在MouseMove事件和Mouse_down事件中输入下面程序,用于窗口图形的拖动滚动处理。
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
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_BOTH = 3showscrollbar picture1.hwnd,SB_BOTH,TRUE自已处理窗口过程
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
Private Const SB_HORZ = 0
Private Const SB_VERT = 1
Private Const SB_BOTH = 3
Private Const WM_HSCROLL = &H114
Private Const WM_VSCROLL = &H
Private Sub Form_Load()
ShowScrollBar picture1.hwnd, SB_BOTH, True
end sub