Replace_UI.bas 5.7 KB

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