Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
11 KiB

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Main
  4. Caption = "Query Sample"
  5. ClientHeight = 8592
  6. ClientLeft = 168
  7. ClientTop = 456
  8. ClientWidth = 9432
  9. LinkTopic = "Form1"
  10. ScaleHeight = 8592
  11. ScaleWidth = 9432
  12. StartUpPosition = 3 'Windows Default
  13. Begin MSComctlLib.ListView ListView1
  14. Height = 7575
  15. Left = 120
  16. TabIndex = 12
  17. Top = 1320
  18. Width = 9255
  19. _ExtentX = 16320
  20. _ExtentY = 13356
  21. LabelWrap = -1 'True
  22. HideSelection = -1 'True
  23. _Version = 393217
  24. ForeColor = -2147483640
  25. BackColor = -2147483643
  26. BorderStyle = 1
  27. Appearance = 1
  28. NumItems = 0
  29. End
  30. Begin VB.ComboBox Dialect
  31. Height = 315
  32. ItemData = "VBQuery.frx":0000
  33. Left = 4200
  34. List = "VBQuery.frx":000D
  35. TabIndex = 11
  36. Text = "Dialect 2"
  37. Top = 840
  38. Width = 2295
  39. End
  40. Begin VB.CommandButton Browse
  41. Caption = "..."
  42. BeginProperty Font
  43. Name = "MS Sans Serif"
  44. Size = 13.8
  45. Charset = 0
  46. Weight = 700
  47. Underline = 0 'False
  48. Italic = 0 'False
  49. Strikethrough = 0 'False
  50. EndProperty
  51. Height = 315
  52. Left = 8760
  53. TabIndex = 10
  54. Top = 480
  55. Width = 495
  56. End
  57. Begin VB.TextBox Scope
  58. Height = 315
  59. Left = 840
  60. TabIndex = 9
  61. Text = "\"
  62. Top = 480
  63. Width = 7815
  64. End
  65. Begin VB.TextBox CatalogName
  66. BackColor = &H80000013&
  67. Height = 285
  68. Left = 840
  69. Locked = -1 'True
  70. TabIndex = 8
  71. Top = 9000
  72. Width = 2775
  73. End
  74. Begin VB.ComboBox Sort
  75. Height = 315
  76. ItemData = "VBQuery.frx":002C
  77. Left = 840
  78. List = "VBQuery.frx":002E
  79. Style = 2 'Dropdown List
  80. TabIndex = 4
  81. Top = 840
  82. Width = 3255
  83. End
  84. Begin VB.CommandButton Clear
  85. Caption = "&Clear"
  86. Height = 375
  87. Left = 8040
  88. TabIndex = 3
  89. Top = 840
  90. Width = 1215
  91. End
  92. Begin VB.TextBox QueryText
  93. Height = 315
  94. Left = 840
  95. TabIndex = 1
  96. Top = 150
  97. Width = 8415
  98. End
  99. Begin VB.CommandButton Go
  100. Caption = "&Go!"
  101. Default = -1 'True
  102. Height = 375
  103. Left = 6720
  104. TabIndex = 0
  105. Top = 840
  106. Width = 1095
  107. End
  108. Begin VB.Label CatalogLabel
  109. Caption = "Catalog:"
  110. Height = 255
  111. Left = 120
  112. TabIndex = 7
  113. Top = 9015
  114. Width = 735
  115. End
  116. Begin VB.Label Label3
  117. Caption = "Scope:"
  118. Height = 255
  119. Left = 120
  120. TabIndex = 6
  121. Top = 510
  122. Width = 495
  123. End
  124. Begin VB.Label Label2
  125. Caption = "Sort:"
  126. Height = 255
  127. Left = 120
  128. TabIndex = 5
  129. Top = 840
  130. Width = 375
  131. End
  132. Begin VB.Label Label1
  133. Caption = "Query:"
  134. Height = 255
  135. Left = 120
  136. TabIndex = 2
  137. Top = 180
  138. Width = 615
  139. End
  140. End
  141. Attribute VB_Name = "Main"
  142. Attribute VB_GlobalNameSpace = False
  143. Attribute VB_Creatable = False
  144. Attribute VB_PredeclaredId = True
  145. Attribute VB_Exposed = False
  146. '+-------------------------------------------------------------------------
  147. '
  148. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  149. ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  150. ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  151. ' PARTICULAR PURPOSE.
  152. '
  153. ' Copyright 1998-1999, Microsoft Corporation. All Rights Reserved.
  154. '
  155. ' PROGRAM: VBQuery
  156. '
  157. ' PURPOSE: Illustrates how to execute Indexing Service queries using
  158. ' Visual Basic and the Query Helper/OLE DB Helper APIs.
  159. '
  160. ' PLATFORM: Windows 2000
  161. '
  162. '--------------------------------------------------------------------------
  163. Private mItem As ListItem
  164. Private InitialWidth As Integer
  165. Private InitialHeight As Integer
  166. Private FormWidth As Integer
  167. Private FormHeight As Integer
  168. Private NonListViewWidth As Integer
  169. Private NonListViewHeight As Integer
  170. Private CatalogLabelTop As Integer
  171. Private CatalogNameTop As Integer
  172. ' LocateCatalogs is used to locate an Indexing Services
  173. ' catalog that covers the specified scope.
  174. Private Declare Function LocateCatalogs Lib "Query" Alias "LocateCatalogsA" _
  175. (ByVal Scope As String, _
  176. ByVal Bmk As Long, _
  177. ByVal Machine As String, _
  178. ByRef ccMachine As Long, _
  179. ByVal Catalog As String, _
  180. ByRef ccCatalog As Long) As Long
  181. ' Bring up the browser dialog when the button is pressed.
  182. Private Sub Browse_Click()
  183. DirBrowse.Show vbModal, Main
  184. If DirBrowse.OK Then
  185. Scope.Text = DirBrowse.Dir1.Path
  186. End If
  187. End Sub
  188. ' Clear the text box when the clear button is pressed.
  189. Private Sub Clear_Click()
  190. QueryText.Text = ""
  191. End Sub
  192. ' All the action happens in DoQuery
  193. Private Sub DoQuery()
  194. Main.MousePointer = 11
  195. ' Set up call to OLE DB Helper API.
  196. Dim Machine As String
  197. Machine = String(255, Chr(0))
  198. ccMachine = Len(Machine)
  199. Dim Catalog As String
  200. Catalog = String(255, Chr(0))
  201. ccCatalog = Len(Catalog)
  202. ' Look for a suitable catalog.
  203. sc = LocateCatalogs(Scope.Text, 0, Machine, ccMachine, Catalog, ccCatalog)
  204. Machine = Left(Machine, ccMachine - 2) ' Workaround (1)
  205. Catalog = Left(Catalog, ccCatalog - 2) ' Workaround (1)
  206. If 0 = sc Then
  207. If ccMachine > 3 Then ' Workaround (2)
  208. CatalogName.Text = "query://" + Machine + "/" + Catalog
  209. Else
  210. CatalogName.Text = Catalog
  211. End If
  212. Else
  213. CatalogName.Text = "<default>"
  214. End If
  215. ' Clear previous query.
  216. ListView1.ListItems.Clear
  217. Dim RS As Object
  218. ' "Dialect" (Indexing Service query language).
  219. If InStr(Dialect.Text, "Dialect") <> 0 Then
  220. ' Create the query and execute.
  221. Dim Q As Object
  222. Set Q = CreateObject("ixsso.Query")
  223. Dim Util As Object
  224. Set Util = CreateObject("ixsso.Util")
  225. Q.Query = QueryText.Text
  226. Q.Columns = "Filename, Path, Size, Write"
  227. If Sort.ListIndex = 2 Then
  228. Q.SortBy = "Rank[d]"
  229. Else
  230. Q.SortBy = Sort.Text
  231. End If
  232. Util.AddScopeToQuery Q, Scope.Text, "DEEP"
  233. If 0 = sc Then
  234. Q.Catalog = CatalogName.Text
  235. End If
  236. If StrComp(Dialect.Text, "Dialect 2") = 0 Then
  237. Q.Dialect = 2 ' Dialect 2.
  238. Else
  239. Q.Dialect = 1 ' Dialect 1.
  240. End If
  241. ' Debug message
  242. Debug.Print "Catalog = " + Q.Catalog
  243. Debug.Print "Query = " + Q.Query
  244. Debug.Print "Columns = " + Q.Columns
  245. Debug.Print "SortBy = " + Q.SortBy
  246. Debug.Print "Scope = " + Scope.Text
  247. Set RS = Q.CreateRecordSet("sequential")
  248. ' Not "Dialect" is SQL query language.
  249. Else
  250. Const adOpenForwardOnly = 0
  251. Connect = "provider=msidxs"
  252. CommandText = "SELECT Filename, Path, Size, Write FROM Scope('" + Chr(34) + Scope.Text + Chr(34) + "') WHERE " + QueryText.Text + " ORDER BY " + Sort.Text
  253. ' Debug message
  254. Debug.Print CommandText
  255. Set RS = CreateObject("ADODB.RecordSet")
  256. RS.Open CommandText, Connect, adOpenForwardOnly
  257. End If
  258. If RS.EOF Then
  259. Set mItem = ListView1.ListItems.Add()
  260. mItem.Text = "No matches found..."
  261. mItem.Ghosted = True
  262. End If
  263. ' Fill in the ListView.
  264. Do Until RS.EOF
  265. Set mItem = ListView1.ListItems.Add()
  266. mItem.Text = RS("Filename")
  267. mItem.SubItems(1) = RS("Path")
  268. mItem.SubItems(2) = RS("Size")
  269. mItem.SubItems(3) = RS("Write")
  270. RS.MoveNext
  271. Loop
  272. ' Make sure we see everything!
  273. ListView1.View = lvwReport
  274. Main.MousePointer = 0
  275. End Sub
  276. ' Prime the query text with a sample.
  277. Private Sub Dialect_Click()
  278. If StrComp(Dialect.Text, "Dialect 1") = 0 Then
  279. QueryText.Text = "Indexing Service"
  280. ElseIf StrComp(Dialect.Text, "Dialect 2") = 0 Then
  281. QueryText.Text = "{prop name=Contents}Indexing Service{/prop}"
  282. Else
  283. QueryText.Text = "CONTAINS('" + Chr(34) + "Indexing Service" + Chr(34) + "')"
  284. End If
  285. End Sub
  286. ' Initialization.
  287. Private Sub Form_Load()
  288. ' Prime text box.
  289. QueryText.Text = "{prop name=Contents}Indexing Service{/prop}"
  290. ' Create column headers.
  291. ListView1.ColumnHeaders.Clear
  292. ListView1.ColumnHeaders.Add , , "Filename"
  293. ListView1.ColumnHeaders.Add , , "Path"
  294. ListView1.ColumnHeaders.Add , , "Size"
  295. ListView1.ColumnHeaders.Add , , "Write"
  296. Sort.AddItem "Filename"
  297. Sort.AddItem "Path"
  298. Sort.AddItem "Rank DESC"
  299. Sort.AddItem "Size"
  300. Sort.AddItem "Write"
  301. Sort.ListIndex = 2
  302. ' For resize.
  303. InitialWidth = Main.Width
  304. InitialHeight = Main.Height
  305. FormWidth = Main.Width
  306. FormHeight = Main.Height
  307. NonListViewWidth = Main.Width - ListView1.Width
  308. NonListViewHeight = Main.Height - ListView1.Height
  309. CatalogLabelTop = Main.Height - CatalogLabel.Top
  310. CatalogNameTop = Main.Height - CatalogName.Top
  311. End Sub
  312. ' Adjust the ListView and Catalog positions on resize.
  313. Private Sub Form_Resize()
  314. If Main.Width < InitialWidth Then
  315. Main.Width = InitialWidth
  316. End If
  317. If Main.Height < 5000 Then
  318. If FormHeight < InitialHeight Then
  319. Main.Height = FormHeight
  320. Else
  321. Main.Height = InitialHeight
  322. End If
  323. End If
  324. FormWidth = Main.Width
  325. FormHeight = Main.Height
  326. ListView1.Width = Main.Width - NonListViewWidth
  327. ListView1.Height = Main.Height - NonListViewHeight
  328. CatalogLabel.Top = Main.Height - CatalogLabelTop
  329. CatalogName.Top = Main.Height - CatalogNameTop
  330. End Sub
  331. Private Sub Go_Click()
  332. DoQuery
  333. End Sub
  334. Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
  335. Sort.Text = ColumnHeader.Text
  336. DoQuery
  337. End Sub