Replace_UI.frm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. API.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. API.BeginOpt
  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. ErrorHandler:
  93. '// MsgBox "请先复制图片的完整路径,本工具能自动替换图片!"
  94. API.EndOpt
  95. End Sub
  96. Private Sub copy_shape_replace_resize()
  97. On Error GoTo ErrorHandler
  98. API.BeginOpt
  99. ActiveDocument.ReferencePoint = cdrCenter
  100. Dim sh As Shape, shs As Shapes, cs As Shape
  101. Dim X As Double, Y As Double
  102. Set shs = ActiveSelection.Shapes
  103. cnt = 0
  104. For Each sh In shs
  105. If cnt = 0 Then
  106. Set sc = ActiveDocument.ActiveLayer.Paste
  107. cnt = 1
  108. Else
  109. sc.Duplicate 0, 0
  110. End If
  111. sh.GetPosition X, Y
  112. sc.SetPosition X, Y
  113. sh.GetSize X, Y
  114. sc.SetSize X, Y
  115. sh.Delete
  116. Next sh
  117. ErrorHandler:
  118. '// MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  119. API.EndOpt
  120. End Sub
  121. Private Sub copy_shape_replace()
  122. On Error GoTo ErrorHandler
  123. API.BeginOpt
  124. ActiveDocument.ReferencePoint = cdrCenter
  125. Dim sh As Shape, shs As Shapes, cs As Shape
  126. Dim X As Double, Y As Double
  127. Set shs = ActiveSelection.Shapes
  128. cnt = 0
  129. For Each sh In shs
  130. If cnt = 0 Then
  131. Set sc = ActiveDocument.ActiveLayer.Paste
  132. cnt = 1
  133. Else
  134. sc.Duplicate 0, 0
  135. End If
  136. sh.GetPosition X, Y
  137. sc.SetPosition X, Y
  138. sh.Delete
  139. Next sh
  140. ErrorHandler:
  141. '// MsgBox "请先复制Ctrl+C,然后选择要替换的物件运行本工具!"
  142. API.EndOpt
  143. End Sub