voidtools

C#

Un ejemplo en C#.



form1.Designer.cs

namespace WindowsApplication1
{
	partial class Form1
	{
		/// <summary>
		/// Variable de diseñador necesaria.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
		
		/// <summary>
		/// Limpiar cualquier recurso siendo utilizado.
		/// </summary>
		/// <param name="disposing">true si los recursos manejados deben ser eliminados; de otra forma, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
	
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		
		/// <summary>
		/// Método necesario para soporte del Diseñador - no modificar
		/// el contenido de este método con el editor de código.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(250, 12);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(84, 20);
			this.button1.TabIndex = 0;
			this.button1.Text = "Search";
			this.button1.UseVisualStyleBackColor = true;
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// listBox1
			// 
			this.listBox1.FormattingEnabled = true;
			this.listBox1.Location = new System.Drawing.Point(12, 38);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(302, 199);
			this.listBox1.TabIndex = 2;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(12, 12);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(232, 20);
			this.textBox1.TabIndex = 3;
			// 
			// vScrollBar1
			// 
			this.vScrollBar1.Location = new System.Drawing.Point(317, 38);
			this.vScrollBar1.Name = "vScrollBar1";
			this.vScrollBar1.Size = new System.Drawing.Size(17, 199);
			this.vScrollBar1.TabIndex = 4;
			this.vScrollBar1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.vScrollBar1_Scroll);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(344, 245);
			this.Controls.Add(this.vScrollBar1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);
			this.PerformLayout();
			
		}
		
		#endregion
		
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.VScrollBar vScrollBar1;
	}
}



form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
	public partial class Form1 : Form
	{
		[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
		public static extern int Everything_SetSearchW(string lpSearchString);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetMatchPath(bool bEnable);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetMatchCase(bool bEnable);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetMatchWholeWord(bool bEnable);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetRegex(bool bEnable);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetMax(int dwMax);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetOffset(int dwOffset);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetReplyWindow(IntPtr hWnd);
		[DllImport("Everything32.dll")]
		public static extern void Everything_SetReplyID(int nId);
		
		[DllImport("Everything32.dll")]
		public static extern bool Everything_GetMatchPath();
		[DllImport("Everything32.dll")]
		public static extern bool Everything_GetMatchCase();
		[DllImport("Everything32.dll")]
		public static extern bool Everything_GetMatchWholeWord();
		[DllImport("Everything32.dll")]
		public static extern bool Everything_GetRegex();
		[DllImport("Everything32.dll")]
		public static extern UInt32 Everything_GetMax();
		[DllImport("Everything32.dll")]
		public static extern UInt32 Everything_GetOffset();
		[DllImport("Everything32.dll")]
		public static extern string Everything_GetSearch();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetLastError();
		[DllImport("Everything32.dll")]
		public static extern IntPtr Everything_GetReplyWindow();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetReplyID();
		
		[DllImport("Everything32.dll")]
		public static extern bool Everything_QueryW(bool bWait);
		
		[DllImport("Everything32.dll")]
		public static extern bool Everything_IsQueryReply(int message, IntPtr wParam, IntPtr lParam, uint nId);
		
		[DllImport("Everything32.dll")]
		public static extern void Everything_SortResultsByPath();
		
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetNumFileResults();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetNumFolderResults();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetNumResults();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetTotFileResults();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetTotFolderResults();
		[DllImport("Everything32.dll")]
		public static extern int Everything_GetTotResults();
		[DllImport("Everything32.dll")]
		public static extern bool Everything_IsVolumeResult(int nIndex);
		[DllImport("Everything32.dll")]
		public static extern bool Everything_IsFolderResult(int nIndex);
		[DllImport("Everything32.dll")]
		public static extern bool Everything_IsFileResult(int nIndex);
		[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
		public static extern void Everything_GetResultFullPathNameW(int nIndex, StringBuilder lpString, int nMaxCount);
		[DllImport("Everything32.dll")]
		public static extern void Everything_Reset();
		
		const int MY_REPLY_ID = 0;
		
		public Form1()
		{
			InitializeComponent();
		}
		
		protected override void WndProc(ref Message m)
		{
			// utilizar la id por defecto (0) para el parámetro nId.
			if (Everything_IsQueryReply(m.Msg, m.WParam, m.LParam, MY_REPLY_ID))
			{
				int i;
				const int bufsize = 260;
				StringBuilder buf = new StringBuilder(bufsize);
				
				// Respuesta a la consulta IPC.
				// limpiar la vieja lista de resultados			
				listBox1.Items.Clear();
				
				// establecer el título de ventana
				Text = textBox1.Text + " - " + Everything_GetTotResults() + " Results";
				
				// crear un lazo a través de los resultados, añadiendo cada uno al listbox.
				for (i = 0; i < Everything_GetNumResults(); i++)
				{
					// obtener la ubicación completa y nombre de archivo de los resultados.
					Everything_GetResultFullPathNameW(i, buf, bufsize);
					
					// añadirlos al listbox				
					listBox1.Items.Insert(i, buf);
				}				
				
				vScrollBar1.Minimum = 0;
				vScrollBar1.Maximum = Everything_GetTotResults() - 1; 
				vScrollBar1.SmallChange = 1;
				vScrollBar1.LargeChange = listBox1.ClientRectangle.Height / listBox1.ItemHeight;
			}
			
			base.WndProc(ref m);
			
		}
		
		private void button1_Click(object sender, EventArgs e)
		{
			// establecer la búsqueda
			Everything_SetSearchW(textBox1.Text);
			
			// establecer la ventana de respuesta (esta ventana) [NECESARIO si no se espera por los resultados en Everything_Query].
			Everything_SetReplyWindow(Handle);
			
			// establecer el id de respuesta.
			Everything_SetReplyID(MY_REPLY_ID);
			
			// configurar la ventana de resultados visibles.
			Everything_SetMax(listBox1.ClientRectangle.Height / listBox1.ItemHeight);
			
			// configurar la ventana de resultados visibles.
			Everything_SetOffset(vScrollBar1.Value);
			
			// ejecutar la consulta, no esperar por los resultados [NECESARIO]
			Everything_QueryW(false);
		}
		
		private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
		{
			button1_Click(sender,e);
		}
	}
}

Acerca de
© 2026 - Privacidad