1
1

Replace_UI.frm 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Replace_UI
  3. ClientHeight = 4560
  4. ClientLeft = 45
  5. ClientTop = 330
  6. ClientWidth = 7590
  7. OleObjectBlob = "Replace_UI.frx":0000
  8. StartUpPosition = 1 'CenterOwner
  9. End
  10. Attribute VB_Name = "Replace_UI"
  11. Attribute VB_GlobalNameSpace = False
  12. Attribute VB_Creatable = False
  13. Attribute VB_PredeclaredId = True
  14. Attribute VB_Exposed = False
  15. #If VBA7 Then
  16. Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
  17. Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  18. Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  19. Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  20. Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  21. #Else
  22. Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
  23. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
  24. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  25. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  26. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  27. #End If
  28. Private Const GWL_STYLE As Long = (-16)
  29. Private Const GWL_EXSTYLE = (-20)
  30. Private Const WS_CAPTION As Long = &HC00000
  31. Private Const WS_EX_DLGMODALFRAME = &H1&
  32. Private Sub Close_Icon_Click()
  33. Unload Me '// 关闭
  34. End Sub
  35. Private Sub UserForm_Initialize()
  36. Dim IStyle As Long
  37. Dim hwnd As Long
  38. hwnd = FindWindow("ThunderDFrame", Me.Caption)
  39. IStyle = GetWindowLong(hwnd, GWL_STYLE)
  40. IStyle = IStyle And Not WS_CAPTION
  41. SetWindowLong hwnd, GWL_STYLE, IStyle
  42. DrawMenuBar hwnd
  43. IStyle = GetWindowLong(hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  44. SetWindowLong hwnd, GWL_EXSTYLE, IStyle
  45. With Me
  46. ' .StartUpPosition = 0
  47. ' .Left = 500
  48. ' .Top = 200
  49. .width = 378
  50. .Height = 228
  51. End With
  52. LNG_CODE = API.GetLngCode
  53. Init_Translations Me, LNG_CODE
  54. End Sub
  55. Private Sub LOGO_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  56. If Button Then
  57. mx = X
  58. my = Y
  59. End If
  60. End Sub
  61. Private Sub LOGO_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  62. If Button Then
  63. Me.Left = Me.Left - mx + X
  64. Me.Top = Me.Top - my + Y
  65. End If
  66. End Sub
  67. Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  68. Dim pos_x As Variant
  69. Dim pos_y As Variant
  70. pos_x = Array(307, 27)
  71. pos_y = Array(64, 126, 188, 200)
  72. If Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(0)) < 30 Then
  73. Call copy_shape_replace
  74. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(1)) < 30 Then
  75. Call copy_shape_replace_resize
  76. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(2)) < 30 Then
  77. Call image_replace
  78. ElseIf Abs(X - pos_x(1)) < 30 And Abs(Y - pos_y(3)) < 30 Then
  79. '// API.WebHelp "https://262235.xyz/index.php/tag/vba/"
  80. End If
  81. Replace_UI.Hide
  82. End Sub
  83. Private Sub image_replace()
  84. On Error GoTo ErrorHandler
  85. API.BeginOpt
  86. Dim image_path As String
  87. image_path = API.GetClipBoardString
  88. ActiveDocument.ReferencePoint = cdrCenter
  89. Dim sh As Shape, shs As Shapes, cs As Shape
  90. Dim X As Double, Y As Double
  91. Set shs = ActiveSelection.Shapes
  92. cnt = 0
  93. For Each sh In shs
  94. If cnt = 0 Then
  95. ActiveDocument.ClearSelection
  96. ActiveLayer.Import image_path
  97. Set sc = ActiveSelection
  98. cnt = 1
  99. Else
  100. sc.Duplicate 0, 0
  101. End If
  102. sh.GetPosition X, Y
  103. sc.SetPosition X, Y
  104. sh.GetSize X, Y
  105. sc.SetSize X, Y
  106. sh.Delete
  107. Next sh
  108. ErrorHandler:
  109. '// MsgBox "请先复制图片的完整路径,本工具能自动替换图片!"
  110. API.EndOpt
  111. End Sub
  112. Private Sub copy_shape_replace_resize()
  113. On Error GoTo ErrorHandler
  114. API.BeginOpt
  115. Set sr = ActiveSelectionRange
  116. If OptBt.value = True Then
  117. If Select_A_Shape = True Then Set sc = ActiveSelectionRange(1)
  118. OptBt.value = False
  119. Else
  120. Set sc = ActiveLayer.Paste
  121. ActiveDocument.ClearSelection
  122. End If
  123. For Each s In sr.ReverseRange
  124. vsh_SizeReplace sc, s
  125. Next s
  126. sc.Delete
  127. ErrorHandler:
  128. API.EndOpt
  129. End Sub
  130. Private Sub copy_shape_replace()
  131. On Error GoTo ErrorHandler
  132. API.BeginOpt
  133. Set sr = ActiveSelectionRange
  134. If OptBt.value = True Then
  135. If Select_A_Shape = True Then Set sc = ActiveSelectionRange(1)
  136. OptBt.value = False
  137. Else
  138. Set sc = ActiveLayer.Paste
  139. ActiveDocument.ClearSelection
  140. End If
  141. For Each s In sr.ReverseRange
  142. vsh_Replace sc, s
  143. Next s
  144. sc.Delete
  145. ErrorHandler:
  146. API.EndOpt
  147. End Sub
  148. '// 使用虚拟形状替换: 目标 dst 替换成 源物件src
  149. Private Function vsh_Replace(src, dst)
  150. Dim X As Double, Y As Double
  151. Dim vsh As Shape
  152. ' 获取 目标dst 形状的中心位置
  153. dst.GetPositionEx cdrCenter, X, Y
  154. ' 创建 源物件src 虚拟副本,并将其定位到目标dst的中心位置
  155. Set vsh = src.TreeNode.GetCopy().VirtualShape
  156. vsh.SetPositionEx cdrCenter, X, Y
  157. ' 用虚拟形状替换第二个形状
  158. dst.ReplaceWith vsh
  159. End Function
  160. '// 使用虚拟形状替换: 目标 dst 替换成 源物件src ,并且尺寸相同
  161. Private Function vsh_SizeReplace(src, dst)
  162. Dim X As Double, Y As Double
  163. Dim vsh As Shape
  164. ' 创建 源物件src 虚拟副本,并将其定位到目标dst的中心位置
  165. Set vsh = src.TreeNode.GetCopy().VirtualShape
  166. ' 尺寸相同,中心点相同
  167. dst.GetSize X, Y: vsh.SetSize X, Y
  168. dst.GetPositionEx cdrCenter, X, Y
  169. vsh.SetPositionEx cdrCenter, X, Y
  170. ' 用虚拟形状替换第二个形状
  171. dst.ReplaceWith vsh
  172. End Function
  173. ' 选择一个物件对象
  174. Private Function Select_A_Shape() As Boolean
  175. Dim X As Double, Y As Double
  176. Dim Shift As Long
  177. Dim b As Boolean
  178. Dim sel As Shape
  179. b = False ' 初始化布尔变量以控制循环
  180. ' 等待用户点击以选择对象
  181. While Not b
  182. b = ActiveDocument.GetUserClick(X, Y, Shift, 10, False, cdrCursorWeldSingle)
  183. If Not b Then
  184. ' 获取点击位置的对象
  185. Set sel = ActiveDocument.ActivePage.SelectShapesAtPoint(X, Y, False)
  186. ' 检查是否找到对象
  187. If Not sel Is Nothing Then
  188. Select_A_Shape = True ' 返回成功状态
  189. Exit Function
  190. Else
  191. MsgBox "未找到对象,请在对象上点击。"
  192. End If
  193. End If
  194. Wend
  195. Select_A_Shape = False ' 返回失败状态
  196. End Function