实现在PPT演示过程中用鼠标拖动图片_第1页
实现在PPT演示过程中用鼠标拖动图片_第2页
实现在PPT演示过程中用鼠标拖动图片_第3页
实现在PPT演示过程中用鼠标拖动图片_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实现在ppt演示过程中,用鼠标拖动图片1新建一个ppt空白文档。2点击菜单:“工具宏宏”,出现对话框。3对话框中“宏名”写:drop(其他也可以),再点“创建”,就进入代码模式。4“sub drop() 宏由番茄花园创建,日期 2010-4-8。end sub”,类似的三句全删掉。把下面的代码全拷贝进去。option explicitdeclare function getkeystate lib user32 (byval nvirtkey as long) as integerprivate declare function windowfrompoint lib user32 (byva

2、l xpoint as long, byval ypoint as long) as longprivate declare function getwindowrect lib user32 (byval hwnd as long, lprect as rect) as longprivate declare function getcursorpos lib user32 (lppoint as pointapi) as longprivate declare function setcursorpos lib user32 (byval x as long, byval y as lon

3、g) as longpublic declare function monitorfrompoint lib user32.dll (byval x as long, byval y as long, byval dwflags as long) as longprivate declare function getsystemmetrics lib user32 (byval nindex as long) as longprivate const sm_screenx = 0private const sm_screeny = 1private const sigproc = drag &

4、 droppublic const vk_shift = &h10public const vk_ctrl = &h11public const vk_alt = &h12private type pointapi x as long y as longend typepublic type rect left as long top as long right as long bottom as longend typepublic mpoint as pointapi, dpoint as pointapipublic activeshape as shapedim dragmode as

5、 booleandim dx as double, dy as doublesub draganddrop(sh as shape) dragmode = not dragmode if dragmode then drag shend subprivate sub drag(sh as shape)dim i as integer, sx as integer, sy as integerdim mwnd as long, wr as rectdx = getsystemmetrics(sm_screenx): dpoint.x = dxdy = getsystemmetrics(sm_sc

6、reeny): dpoint.y = dygetcursorpos mpointwith activepresentation.slideshowwindow mwnd = windowfrompoint(mpoint.x, mpoint.y) getwindowrect mwnd, wr sx = wr.left sy = wr.top dx = (wr.right - wr.left) / activepresentation.pagesetup.slidewidth dy = (wr.bottom - wr.top) / activepresentation.pagesetup.slid

7、eheightend withif dx dy then sx = sx + (dx - dy) * activepresentation.pagesetup.slidewidth / 2 dx = dyend ifif dy dx then sy = sy + (dy - dx) * activepresentation.pagesetup.slideheight / 2 dy = dxend ifwhile dragmode getcursorpos mpoint sh.left = (mpoint.x - sx) / dx - sh.width / 2 sh.top = (mpoint.

8、y - sy) / dy - sh.height / 2 doevents i = i + 1: if i 2000 then dragmode = false: exit subwendend sub5点击保存后,关闭代码模式,回到ppt设计页面。在你需要拖动的图片上点右键,选择“动作设置单击鼠标运行宏确定”。然后就看效果吧。option explicit 声明模块中将要使用的 win32的 api 函数private declare function getdc lib user32 (byval hwnd as long) as longprivate declare function

9、releasedc lib user32 ( _byval hwnd as long, _byval hdc as long) as longprivate declare function getdevicecaps lib gdi32 ( _byval hdc as long, _byval nindex as long) as longprivate declare function settimer lib user32 ( _byval hwnd as long, _byval nidevent as long, _byval uelapse as long, _byval lpti

10、merfunc as long) as longprivate declare function killtimer lib user32 ( _byval hwnd as long, _byval nidevent as long) as longprivate declare function getcursorpos lib user32 (lppoint as point) as long声明 point类型,将用来定义存储位置坐标的变量type pointx as longy as longend type 定义函数及过程中要使用的常量private const logpixelsx

11、 = 88让 getdevicecaps 函数返回像素/逻辑英寸(水平)private const logpixelsy = 90让 getdevicecaps 函数返回像素/逻辑英寸(垂直)private const twipsperinch = 1440 每英寸约等于 1440 twip(缇)定义相关变量private xpixelsperinch as long 存储每逻辑英寸对应的水平像素点数private ypixelsperinch as long 存储每逻辑英寸对应的水平像素点数private ratio as single 存储窗口或屏幕的缩放比率private moving

12、as boolean 存储判断移动是否正在进行的标志private dragshp as shape 存储被拖移的形状对象private timerid as long 存储计时器标识符private origshpleft as single 存储形状被拖动前的水平坐标private origshptop as single 存储形状被拖动前的垂直坐标private origmouselocation as point 存储鼠标点击形并开始拖动形状时的坐标点定义移动形状的过程sub moveshape(byval shp as shape)dim hdc as long 定义用于存储设备场景

13、的变量on error resume nextif slideshowwindows.count 0 then 只有当幻灯片放映时才进行处理if moving then 如果 moving为 true则停止移动endmoveshapeelse moving 为 false 则让形状跟随鼠标移动hdc = getdc(0) 获取整个屏幕的设备场景(程序窗口外),dc 即:device context。xpixelsperinch = getdevicecaps(hdc, logpixelsx) 取得每逻辑英寸 对应的水平像素点数ypixelsperinch = getdevicecaps(hdc

14、, logpixelsy) 取得每逻辑英寸 对应的垂直像素点数releasedc 0, hdc 释放整个屏幕的设备场景ratio = shp.parent.parent.slideshowwindow.view.zoom / 100# 取得 放映窗口的缩放比率set dragshp = shp 获取当前将要被拖动的形状origshpleft = shp.left 保存形状的初始水平坐标origshptop = shp.top 保存形状的初始垂直坐标getcursorpos origmouselocation 获取鼠标的当前位置starttimer 调用启动计时器的过程moving = true

15、 设置移动正在进行的标志为trueend ifend ifend sub 定义结束形状移动的过程sub endmoveshape()on error resume nextmoving = false 设置移动正在进行的标志为falsestoptimer 终止计时器set dragshp = nothing 清除定义的对象变量end sub 启动计时器的过程private sub starttimer()on error resume next 启动计时器,并调用 timerproc 过程来实现形状对鼠标的跟随timerid = settimer(0, 0, 10, addressof tim

16、erproc)end sub 停止计时器的过程private sub stoptimer()on error resume nextkilltimer 0, timerid 销毁计时器,释放系统资源end sub 在计时器过程中被调用来处理鼠标位置及移动形状的过程private sub timerproc(byval hwnd as long, _byval umsg as long, _byval wparam as long, _byval lparam as long)dim curmouselocation as point 存储鼠标的当前位置dim deltax as single 存储鼠标水平移动的距离dim deltay as single 存储鼠标垂直移动的距离on error resume nextif moving then 移动正在进行的标志为真时进行处理getcursorpos curmouselocation 获取鼠标的当前坐标deltax = (curmouselocation.x - origmouselocation.x) * _twipsperinch / 20 / xpixelsperinch

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论