Toolbar.bas 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.Move Me.Left - mX + x, Me.TOP - mY + y
  48. End If
  49. End Sub
  50. Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
  51. Dim pos_x As Variant
  52. Dim pos_y As Variant
  53. pos_x = Array(307, 27)
  54. pos_y = Array(64, 126, 188, 200)
  55. If Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(0)) < 30 Then
  56. Call copy_shape_replace
  57. ElseIf Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(1)) < 30 Then
  58. Call copy_shape_replace_resize
  59. ElseIf Abs(x - pos_x(0)) < 30 And Abs(y - pos_y(2)) < 30 Then
  60. Call image_replace
  61. ElseIf Abs(x - pos_x(1)) < 30 And Abs(y - pos_y(3)) < 30 Then
  62. CorelVBA.WebHelp "https://262235.xyz/index.php/tag/vba/"
  63. End If
  64. Replace_UI.Hide
  65. End Sub
  66. Private Sub image_replace()
  67. On Error GoTo ErrorHandler
  68. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  69. Dim image_path As String
  70. image_path = API.GetClipBoardString
  71. ActiveDocument.ReferencePoint = cdrCenter
  72. Dim sh As Shape, shs As Shapes, cs As Shape
  73. Dim x As Double, y As Double
  74. Set shs = ActiveSelection.Shapes
  75. cnt = 0
  76. For Each sh In shs
  77. If cnt = 0 Then
  78. ActiveDocument.ClearSelection
  79. ActiveLayer.Import image_path
  80. Set sc = ActiveSelection
  81. cnt = 1
  82. Else
  83. sc.Duplicate 0, 0
  84. End If
  85. sh.GetPosition x, y
  86. sc.SetPosition x, y
  87. sh.GetSize x, y
  88. sc.SetSize x, y
  89. sh.Delete
  90. Next sh
  91. '// 代码操作结束恢复窗口刷新
  92. ActiveDocument.EndCommandGroup
  93. Application.Optimization = False
  94. ActiveWindow.Refresh: Application.Refresh
  95. Exit Sub
  96. ErrorHandler:
  97. MsgBox "请先复制图片的完整路径,本工具能自动替换图片!"
  98. Application.Optimization = False
  99. On Error Resume Next
  100. End Sub
  101. Private Sub copy_shape_replace_resize()
  102. On Error GoTo ErrorHandler
  103. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  104. ActiveDocument.ReferencePoint = cdrCenter
  105. Dim sh As Shape, shs As Shapes, cs As Shape
  106. Dim x As Double, y As Double
  107. Set shs = ActiveSelection.Shapes
  108. cnt = 0
  109. For Each sh In shs
  110. If cnt = 0 Then
  111. Set sc = ActiveDocument.ActiveLayer.Paste
  112. cnt = 1
  113. Else
  114. sc.Duplicate 0, 0
  115. End If
  116. sh.GetPosition x, y
  117. sc.SetPosition x, y
  118. sh.GetSize x, y
  119. sc.SetSize x, y
  120. sh.Delete
  121. Next sh
  122. '// 代码操作结束恢复窗口刷新
  123. ActiveDocument.EndCommandGroup
  124. Application.Optimization = False
  125. ActiveWindow.Refresh: Application.Refresh
  126. Exit Sub
  127. ErrorHandler:
  128. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  129. Application.Optimization = False
  130. On Error Resume Next
  131. End Sub
  132. Private Sub copy_shape_replace()
  133. On Error GoTo ErrorHandler
  134. ActiveDocument.BeginCommandGroup: Application.Optimization = True
  135. ActiveDocument.ReferencePoint = cdrCenter
  136. Dim sh As Shape, shs As Shapes, cs As Shape
  137. Dim x As Double, y As Double
  138. Set shs = ActiveSelection.Shapes
  139. cnt = 0
  140. For Each sh In shs
  141. If cnt = 0 Then
  142. Set sc = ActiveDocument.ActiveLayer.Paste
  143. cnt = 1
  144. Else
  145. sc.Duplicate 0, 0
  146. End If
  147. sh.GetPosition x, y
  148. sc.SetPosition x, y
  149. sh.Delete
  150. Next sh
  151. '// 代码操作结束恢复窗口刷新
  152. ActiveDocument.EndCommandGroup
  153. Application.Optimization = False
  154. ActiveWindow.Refresh: Application.Refresh
  155. Exit Sub
  156. ErrorHandler:
  157. MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  158. Application.Optimization = False
  159. On Error Resume Next
  160. End Sub