|
本帖最后由 shenjianrong163 于 2024-3-6 12:57 编辑
郁闷!只有WPS才可用。修改如下:
- Private Type POINTAPI
- x As Long
- y As Long
- End Type
- Private Type Rectangle
- topLeft As POINTAPI
- bottomRight As POINTAPI
- End Type
- #If Win64 And VBA7 Then
- Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
- Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
- Private Declare PtrSafe Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
- #Else
- Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
- Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
- 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 ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
- #End If
- Private Function TransformShape(osh As Shape) As Rectangle
- Dim zoomFactor As Double
- On Error Resume Next
- zoomFactor = ActivePresentation.slideShowWindow.View.Zoom / 100
- Dim hndDC&
- hndDC = GetDC(0)
- Dim deviceCapsX As Double
- deviceCapsX = GetDeviceCaps(hndDC, 88) / 72 ' pixels per pt horizontal (1 pt = 1/72')
- Dim deviceCapsY As Double
- deviceCapsY = GetDeviceCaps(hndDC, 90) / 72 ' pixels per pt vertical (1 pt = 1/72')
- With TransformShape
- ' calculate:
- .topLeft.x = osh.Left * deviceCapsX * zoomFactor
- .topLeft.y = osh.Top * deviceCapsY * zoomFactor
- .bottomRight.x = (osh.Left + osh.Width) * deviceCapsX * zoomFactor
- .bottomRight.y = (osh.Top + osh.Height) * deviceCapsY * zoomFactor
- ' translate:
- Dim lngStatus As Long
- lngStatus = ClientToScreen(hndDC, .topLeft)
- lngStatus = ClientToScreen(hndDC, .bottomRight)
- End With
- ReleaseDC 0, hndDC
- End Function
- Sub SlideShape_Click()
- Dim pointerPos As POINTAPI
- Dim shapeAsRect As Rectangle
- Dim sld As Slide
- Dim shp As Shape
- Dim p As Long
- On Error Resume Next
- p = SlideShowWindows(1).View.Slide.slideIndex '获取当前播放的幻灯片编号
- Set sld = ActivePresentation.Slides(p) '指定要操作的幻灯片页数(这里为播放状态的那张)
- For Each shp In sld.Shapes
- 'If shp.Type = msoPicture Then '判断形状类型是否为图片(WPS适用)
- shapeAsRect = TransformShape(shp)
- GetCursorPos pointerPos '获取鼠标指针坐标
- If ((pointerPos.x <= shapeAsRect.topLeft.x) Or (pointerPos.x >= shapeAsRect.bottomRight.x) Or _
- (pointerPos.y <= shapeAsRect.topLeft.y) Or (pointerPos.y >= shapeAsRect.bottomRight.y)) Then
- ' 图片不在鼠标所点区域
- Else ' 图片在鼠标所点区域
- MsgBox "你点击了第" & p & "页的“" & shp.Name & "”图片!"
- Exit For
- End If
- 'End If
- Next
- End Sub
复制代码
|
|