1
1

Replace_UI.frm 5.3 KB

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