ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 3316|回复: 4

[分享] 给一个好东西让大家分享!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2010-10-30 16:59 | 显示全部楼层 |阅读模式
'Option Explicit
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Type Point
    X As Long
    Y As Long
End Type
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Private Const TWIPSPERINCH = 1440
Private Declare Function GetCursorPos Lib "user32" (lpPoint As Point) As Long
Private XPixelsPerInch As Long
Private YPixelsPerInch As Long
Private Ratio As Single
Private Moving As Boolean
Private DragShp As Shape
Private TimerId As Long
Private HostObj As HostClass
Private OrigShpLeft As Single
Private OrigShpTop As Single
Private OrigMouseLocation As Point
Sub LoadShow()
    Dim iShapes As Shape
    Dim n As Integer
    n = 0
    With SlideShowWindows(1)
        .View.GotoSlide (.Presentation.Slides(2).SlideIndex)
    End With
   
    With ActivePresentation.Slides(2)
        For Each iShapes In .Shapes
            n = n + 1
            iShapes.Name = "Shape" & n
            iShapes.ActionSettings(ppMouseClick).Action = ppActionRunMacro
            iShapes.ActionSettings(ppMouseClick).Run = "MoveShape"
        Next
    End With
End Sub
Sub MoveShape(ByVal Shp As Shape)
    Dim hDC As Long
    On Error Resume Next
    If SlideShowWindows.Count > 0 Then
        If Moving Then
            EndMoveShape
        Else
            hDC = GetDC(0)
            XPixelsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
            YPixelsPerInch = GetDeviceCaps(hDC, 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
            Set HostObj = New HostClass
        End If
    End If
End Sub
Sub EndMoveShape()
    On Error Resume Next
    Set HostObj = Nothing
    Moving = False
    StopTimer
    Set DragShp = Nothing
End Sub
Private Sub StartTimer()
    On Error Resume Next
    TimerId = SetTimer(0, 0, 10, AddressOf TimerProc)
End Sub
Private Sub StopTimer()
    On Error Resume Next
    KillTimer 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 Next
    If Moving Then
        GetCursorPos CurMouseLocation
        DeltaX = (CurMouseLocation.X - OrigMouseLocation.X) * _
            TWIPSPERINCH / 20 / XPixelsPerInch / Ratio
        DeltaY = (CurMouseLocation.Y - OrigMouseLocation.Y) * _
            TWIPSPERINCH / 20 / XPixelsPerInch / Ratio
        DragShp.Left = OrigShpLeft + DeltaX
        DragShp.Top = OrigShpTop + DeltaY
    End If
End Sub

[ 本帖最后由 chuhaiou 于 2010-10-30 23:02 编辑 ]

TA的精华主题

TA的得分主题

发表于 2010-10-30 17:44 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2012-4-5 08:27 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Addressof不是只能调用标准模块中的宏的吗,为何又可以AddressOf TimerProc,TimerProc前面可是Private

TA的精华主题

TA的得分主题

发表于 2012-4-28 19:40 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2015-12-4 11:02 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-23 03:03 , Processed in 0.033651 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表