导航:首页 > 编程语言 > 在编程中如何将图片放大

在编程中如何将图片放大

发布时间:2025-01-23 04:24:09

❶ 请教:用vb编程如何实现用鼠标滚轮扩大和缩小窗体上的图片

添加一个模块,输入以下代码:

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Public Const GWL_WNDPROC = -4&
Public Const WM_MOUSEWHEEL = &H20A

Public Type POINTAPI
x As Long
y As Long
End Type

Public OldWindowProc As Long
Public ohwnd As Long

Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error Resume Next
If Msg = WM_MOUSEWHEEL Then
Dim CurPoint As POINTAPI, hwndUnderCursor As Long
GetCursorPos CurPoint
hwndUnderCursor = WindowFromPoint(CurPoint.x, CurPoint.y)
If hwndUnderCursor = ohwnd Then
If wParam = -7864320 Then
If Form1.Picture1.Width < Form1.ScaleWidth Then Form1.Picture1.Width = Form1.Picture1.Width + 300
If Form1.Picture1.Height < Form1.ScaleHeight Then Form1.Picture1.Height = Form1.Picture1.Height + 240
ElseIf wParam = 7864320 Then
If Form1.Picture1.Width > 600 Then Form1.Picture1.Width = Form1.Picture1.Width - 300
If Form1.Picture1.Height > 480 Then Form1.Picture1.Height = Form1.Picture1.Height - 240
End If
End If
Else
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End If
End Function

在Form1中放入一个Picture1控件,然后输入以下代码:

Private Sub Form_Load()
Picture1.AutoRedraw = True
Picture1.Picture = LoadPicture("e:\tmp\cd1.gif") '图片文件名,自己改
Picture1.Move 0, 0, 6000, 4800
ohwnd = Picture1.hwnd
OldWindowProc = GetWindowLong(Picture1.hwnd, GWL_WNDPROC)
Call SetWindowLong(Picture1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub

Private Sub Picture1_Resize()
Picture1.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight
End Sub

阅读全文

与在编程中如何将图片放大相关的资料

热点内容
gear2刷android 浏览:79
怎么用安卓下载樱校 浏览:580
现在什么app可以赚钱 浏览:155
基础梁钢筋图纸未标注加密区间距 浏览:469
通达信指标源码公式半透明 浏览:956
开发什么手机app好 浏览:319
csgo如何在游戏里进入完美服务器 浏览:190
编程教育老师成长心态 浏览:257
音频采集单片机 浏览:590
加密管的优点 浏览:280
dock基础命令 浏览:345
java编程爱好者 浏览:723
做外包程序员怎么样 浏览:865
程序员技术门槛 浏览:473
路由花生壳搭建web服务器地址 浏览:541
小米传送文件用什么app 浏览:103
哪个领域算法好 浏览:380
用命令行编译java 浏览:677
笔趣阁app哪个是正版手机app 浏览:427
程序员这个工作好吗 浏览:898