Replace_UI.bas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Replace_UI
  3. Caption = "使剪贴板上的物件替换选择的目标物件"
  4. ClientHeight = 4560
  5. ClientLeft = 45
  6. ClientTop = 330
  7. ClientWidth = 7590
  8. OleObjectBlob = "Replace_UI.frx":0000
  9. StartUpPosition = 1 '所有者中心
  10. End
  11. Attribute VB_Name = "Replace_UI"
  12. Attribute VB_GlobalNameSpace = False
  13. Attribute VB_Creatable = False
  14. Attribute VB_PredeclaredId = True
  15. Attribute VB_Exposed = False
  16. #If VBA7 Then
  17. Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal Hwnd As Long) As Long
  18. Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
  19. Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  20. Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  21. Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  22. #Else
  23. Private Declare Function DrawMenuBar Lib "user32" (ByVal Hwnd As Long) As Long
  24. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long
  25. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  26. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  27. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  28. #End If
  29. Private Const GWL_STYLE As Long = (-16)
  30. Private Const GWL_EXSTYLE = (-20)
  31. Private Const WS_CAPTION As Long = &HC00000
  32. Private Const WS_EX_DLGMODALFRAME = &H1&
  33. Private Sub Close_Icon_Click()
  34. Unload Me ' 关闭
  35. End Sub
  36. Private Sub UserForm_Initialize()
  37. Dim IStyle As Long
  38. Dim Hwnd As Long
  39. Hwnd = FindWindow("ThunderDFrame", Me.Caption)
  40. IStyle = GetWindowLong(Hwnd, GWL_STYLE)
  41. IStyle = IStyle And Not WS_CAPTION
  42. SetWindowLong Hwnd, GWL_STYLE, IStyle
  43. DrawMenuBar Hwnd
  44. IStyle = GetWindowLong(Hwnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  45. SetWindowLong Hwnd, GWL_EXSTYLE, IStyle
  46. With Me
  47. ' .StartUpPosition = 0
  48. ' .Left = 500
  49. ' .Top = 200
  50. .Width = 378
  51. .Height = 228
  52. End With
  53. End Sub
  54. Private Sub LOGO_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  55. If Button Then
  56. mx = x
  57. my = y
  58. End If
  59. End Sub
  60. Private Sub LOGO_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  61. If Button Then
  62. Me.Left = Me.Left - mx + x
  63. Me.Top = Me.Top - my + y
  64. End If
  65. End Sub
  66. Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  67. Dim pos_x As Variant
  68. Dim pos_y As Variant
  69. pos_x = Array(307, 27)
  70. pos_y = Array(64, 126, 188, 200)
  71. If Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(0)) < 30 Then
  72. Call copy_shape_replace
  73. ElseIf Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(1)) < 30 Then
  74. Call copy_shape_replace_resize
  75. ElseIf Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(2)) < 30 Then
  76. Call image_replace
  77. ElseIf Abs(x - pos_x(1)) < 30 And Abs(y - pos_y(3)) < 30 Then
  78. CorelVBA.WebHelp "https://262235.xyz/index.php/tag/vba/"
  79. End If
  80. Replace_UI.Hide
  81. End Sub
  82. Private Sub image_replace()
  83. On Error GoTo ErrorHandler
  84. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  85. Dim image_path As String
  86. image_path = API.GetClipBoardString
  87. ActiveDocument.ReferencePoint = cdrCenter
  88. Dim sh As Shape, shs As Shapes, cs As Shape
  89. Dim x As Double, y As Double
  90. Set shs = ActiveSelection.Shapes
  91. cnt = 0
  92. For Each sh In shs
  93. If cnt = 0 Then
  94. ActiveDocument.ClearSelection
  95. ActiveLayer.Import image_path
  96. Set sc = ActiveSelection
  97. cnt = 1
  98. Else
  99. sc.Duplicate 0, 0
  100. End If
  101. sh.GetPosition x, y
  102. sc.SetPosition x, y
  103. sh.GetSize x, y
  104. sc.SetSize x, y
  105. sh.Delete
  106. Next sh
  107. '// 代码操作结束恢复窗口刷新
  108. ActiveDocument.EndCommandGroup
  109. Application.Optimization = False
  110. ActiveWindow.Refresh: Application.Refresh
  111. Exit Sub
  112. ErrorHandler:
  113. MsgBox "请先复制图片的完整路径,本工具能自动替换图片!"
  114. Application.Optimization = False
  115. On Error Resume Next
  116. End Sub
  117. Private Sub copy_shape_replace_resize()
  118. On Error GoTo ErrorHandler
  119. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  120. ActiveDocument.ReferencePoint = cdrCenter
  121. Dim sh As Shape, shs As Shapes, cs As Shape
  122. Dim x As Double, y As Double
  123. Set shs = ActiveSelection.Shapes
  124. cnt = 0
  125. For Each sh In shs
  126. If cnt = 0 Then
  127. Set sc = ActiveDocument.ActiveLayer.Paste
  128. cnt = 1
  129. Else
  130. sc.Duplicate 0, 0
  131. End If
  132. sh.GetPosition x, y
  133. sc.SetPosition x, y
  134. sh.GetSize x, y
  135. sc.SetSize x, y
  136. sh.Delete
  137. Next sh
  138. '// 代码操作结束恢复窗口刷新
  139. ActiveDocument.EndCommandGroup
  140. Application.Optimization = False
  141. ActiveWindow.Refresh: Application.Refresh
  142. Exit Sub
  143. ErrorHandler:
  144. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  145. Application.Optimization = False
  146. On Error Resume Next
  147. End Sub
  148. Private Sub copy_shape_replace()
  149. On Error GoTo ErrorHandler
  150. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  151. ActiveDocument.ReferencePoint = cdrCenter
  152. Dim sh As Shape, shs As Shapes, cs As Shape
  153. Dim x As Double, y As Double
  154. Set shs = ActiveSelection.Shapes
  155. cnt = 0
  156. For Each sh In shs
  157. If cnt = 0 Then
  158. Set sc = ActiveDocument.ActiveLayer.Paste
  159. cnt = 1
  160. Else
  161. sc.Duplicate 0, 0
  162. End If
  163. sh.GetPosition x, y
  164. sc.SetPosition x, y
  165. sh.Delete
  166. Next sh
  167. '// 代码操作结束恢复窗口刷新
  168. ActiveDocument.EndCommandGroup
  169. Application.Optimization = False
  170. ActiveWindow.Refresh: Application.Refresh
  171. Exit Sub
  172. ErrorHandler:
  173. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  174. Application.Optimization = False
  175. On Error Resume Next
  176. End Sub