CQL_FIND_UI.frm 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. '// This is free and unencumbered software released into the public domain.
  2. '// For more information, please refer to https://github.com/hongwenjun
  3. #If VBA7 Then
  4. Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
  5. Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  6. Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  7. Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  8. Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  9. #Else
  10. Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
  11. Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
  12. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  13. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  14. Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
  15. #End If
  16. Private Const GWL_STYLE As Long = (-16)
  17. Private Const GWL_EXSTYLE = (-20)
  18. Private Const WS_CAPTION As Long = &HC00000
  19. Private Const WS_EX_DLGMODALFRAME = &H1&
  20. Private Sub UserForm_Initialize()
  21. Dim IStyle As Long
  22. Dim hWnd As Long
  23. hWnd = FindWindow("ThunderDFrame", Me.Caption)
  24. IStyle = GetWindowLong(hWnd, GWL_STYLE)
  25. IStyle = IStyle And Not WS_CAPTION
  26. SetWindowLong hWnd, GWL_STYLE, IStyle
  27. DrawMenuBar hWnd
  28. IStyle = GetWindowLong(hWnd, GWL_EXSTYLE) And Not WS_EX_DLGMODALFRAME
  29. SetWindowLong hWnd, GWL_EXSTYLE, IStyle
  30. With Me
  31. ' .StartUpPosition = 0
  32. ' .Left = 500
  33. ' .Top = 200
  34. .Width = 378
  35. .Height = 228
  36. End With
  37. txtInfo.text = "Usage: A->Left B->Right C->Ctrl"
  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. Debug.Print X, Y
  48. Me.Left = Me.Left - mx + X
  49. Me.Top = Me.Top - my + Y
  50. End If
  51. End Sub
  52. Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  53. Dim pos_x As Variant
  54. Dim pos_y As Variant
  55. pos_x = Array(307, 27)
  56. pos_y = Array(64, 126, 188, 200)
  57. If Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(0)) < 30 Then
  58. Call CQLSameUniformColor
  59. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(1)) < 30 Then
  60. Call CQLSameOutlineColor
  61. ElseIf Abs(X - pos_x(0)) < 30 And Abs(Y - pos_y(2)) < 30 Then
  62. Call CQLSameSize
  63. ElseIf Abs(X - pos_x(1)) < 30 And Abs(Y - pos_y(3)) < 30 Then
  64. API.WebHelp "https://262235.xyz/index.php/tag/vba/"
  65. End If
  66. '// 预置颜色轮廓选择 和 '// 彩蛋功能
  67. If Abs(X - 178) < 30 And Abs(Y - 118) < 30 = True Then
  68. Image1.Visible = False
  69. Close_Icon.Visible = False
  70. X_EXIT.Visible = True
  71. With CQL_FIND_UI
  72. .StartUpPosition = 0
  73. .Left = Val(GetSetting("LYVBA", "Settings", "Left", "400")) + 318
  74. .Top = Val(GetSetting("LYVBA", "Settings", "Top", "55")) - 2
  75. .Height = 30
  76. .Width = .Width - 20
  77. End With
  78. If OptBt.value Then
  79. frmSelectSame.Show 0
  80. Else
  81. CQLFindSame.CQLline_CM100
  82. End If
  83. Exit Sub
  84. End If
  85. CQL_FIND_UI.Hide
  86. End Sub
  87. Private Sub MADD_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  88. If Button = 2 Then
  89. Store_Instruction 2, "add"
  90. ElseIf Shift = fmCtrlMask Then
  91. Store_Instruction 1, "add"
  92. Else
  93. Store_Instruction 3, "add"
  94. End If
  95. txtInfo.text = StoreCount
  96. End Sub
  97. Private Sub MSUB_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  98. If Button = 2 Then
  99. Store_Instruction 2, "sub"
  100. ElseIf Shift = fmCtrlMask Then
  101. Store_Instruction 1, "sub"
  102. Else
  103. Store_Instruction 3, "sub"
  104. End If
  105. txtInfo.text = StoreCount
  106. End Sub
  107. Private Sub MRLW_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  108. If Button = 2 Then
  109. Store_Instruction 2, "lw"
  110. ElseIf Shift = fmCtrlMask Then
  111. Store_Instruction 1, "lw"
  112. Else
  113. Store_Instruction 3, "lw"
  114. End If
  115. txtInfo.text = StoreCount
  116. End Sub
  117. Private Sub MZERO_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  118. If Button = 2 Then
  119. Store_Instruction 2, "zero"
  120. ElseIf Shift = fmCtrlMask Then
  121. Store_Instruction 1, "zero"
  122. Else
  123. Store_Instruction 3, "zero"
  124. End If
  125. txtInfo.text = StoreCount
  126. End Sub
  127. Private Sub CQLSameSize()
  128. ActiveDocument.Unit = cdrMillimeter
  129. Dim s As Shape
  130. Set s = ActiveShape
  131. If s Is Nothing Then Exit Sub
  132. If OptBt.value = True Then
  133. ActiveDocument.ClearSelection
  134. OptBt.value = 0
  135. CQL_FIND_UI.Hide
  136. Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
  137. Dim Shift As Long
  138. Dim box As Boolean
  139. box = ActiveDocument.GetUserArea(x1, y1, x2, y2, Shift, 10, False, cdrCursorWeldSingle)
  140. If Not b Then
  141. ' MsgBox "选区范围: " & x1 & y1 & x2 & y2
  142. Set sh = ActivePage.SelectShapesFromRectangle(x1, y1, x2, y2, False)
  143. sh.Shapes.FindShapes(Query:="@width = {" & s.SizeWidth & " mm} and @height ={" & s.SizeHeight & "mm}").CreateSelection
  144. End If
  145. Else
  146. ActivePage.Shapes.FindShapes(Query:="@width = {" & s.SizeWidth & " mm} and @height ={" & s.SizeHeight & "mm}").CreateSelection
  147. End If
  148. End Sub
  149. Private Sub CQLSameOutlineColor()
  150. On Error GoTo err
  151. Dim colr As New Color, s As Shape
  152. Set s = ActiveShape
  153. If s Is Nothing Then Exit Sub
  154. colr.CopyAssign s.Outline.Color
  155. colr.ConvertToRGB
  156. ' 查找对象
  157. r = colr.RGBRed
  158. G = colr.RGBGreen
  159. b = colr.RGBBlue
  160. If OptBt.value = True Then
  161. ActiveDocument.ClearSelection
  162. OptBt.value = 0
  163. CQL_FIND_UI.Hide
  164. Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
  165. Dim Shift As Long
  166. Dim box As Boolean
  167. box = ActiveDocument.GetUserArea(x1, y1, x2, y2, Shift, 10, False, cdrCursorWeldSingle)
  168. If Not b Then
  169. ' MsgBox "选区范围: " & x1 & y1 & x2 & y2
  170. Set sh = ActivePage.SelectShapesFromRectangle(x1, y1, x2, y2, False)
  171. sh.Shapes.FindShapes(Query:="@Outline.Color.rgb[.r='" & r & "' And .g='" & G & "' And .b='" & b & "']").CreateSelection
  172. End If
  173. Else
  174. ActivePage.Shapes.FindShapes(Query:="@Outline.Color.rgb[.r='" & r & "' And .g='" & G & "' And .b='" & b & "']").CreateSelection
  175. End If
  176. Exit Sub
  177. err:
  178. MsgBox "对象轮廓为空。"
  179. End Sub
  180. Private Sub CQLSameUniformColor()
  181. On Error GoTo err
  182. Dim colr As New Color, s As Shape
  183. Set s = ActiveShape
  184. If s Is Nothing Then Exit Sub
  185. If s.Fill.Type = cdrFountainFill Then MsgBox "不支持渐变色。": Exit Sub
  186. colr.CopyAssign s.Fill.UniformColor
  187. colr.ConvertToRGB
  188. ' 查找对象
  189. r = colr.RGBRed
  190. G = colr.RGBGreen
  191. b = colr.RGBBlue
  192. If OptBt.value = True Then
  193. ActiveDocument.ClearSelection
  194. OptBt.value = 0
  195. CQL_FIND_UI.Hide
  196. Dim x1 As Double, y1 As Double, x2 As Double, y2 As Double
  197. Dim Shift As Long
  198. Dim box As Boolean
  199. box = ActiveDocument.GetUserArea(x1, y1, x2, y2, Shift, 10, False, cdrCursorWeldSingle)
  200. If Not b Then
  201. ' MsgBox "选区范围: " & x1 & y1 & x2 & y2
  202. Set sh = ActivePage.SelectShapesFromRectangle(x1, y1, x2, y2, False)
  203. sh.Shapes.FindShapes(Query:="@fill.color.rgb[.r='" & r & "' And .g='" & G & "' And .b='" & b & "']").CreateSelection
  204. End If
  205. Else
  206. ActivePage.Shapes.FindShapes(Query:="@fill.color.rgb[.r='" & r & "' And .g='" & G & "' And .b='" & b & "']").CreateSelection
  207. End If
  208. Exit Sub
  209. err:
  210. MsgBox "对象填充为空。"
  211. End Sub
  212. Private Sub X_EXIT_Click()
  213. Unload Me ' 关闭
  214. End Sub
  215. Private Sub Close_Icon_Click()
  216. Unload Me ' 关闭
  217. End Sub