voidtools

C#

A C# example.


form1.Designer.cs

namespace WindowsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}

base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </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
{
const int EVERYTHING_OK = 0;
const int EVERYTHING_ERROR_MEMORY = 1;
const int EVERYTHING_ERROR_IPC = 2;
const int EVERYTHING_ERROR_REGISTERCLASSEX = 3;
const int EVERYTHING_ERROR_CREATEWINDOW = 4;
const int EVERYTHING_ERROR_CREATETHREAD = 5;
const int EVERYTHING_ERROR_INVALIDINDEX = 6;
const int EVERYTHING_ERROR_INVALIDCALL = 7;

const int EVERYTHING_REQUEST_FILE_NAME = 0x00000001;
const int EVERYTHING_REQUEST_PATH = 0x00000002;
const int EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = 0x00000004;
const int EVERYTHING_REQUEST_EXTENSION = 0x00000008;
const int EVERYTHING_REQUEST_SIZE = 0x00000010;
const int EVERYTHING_REQUEST_DATE_CREATED = 0x00000020;
const int EVERYTHING_REQUEST_DATE_MODIFIED = 0x00000040;
const int EVERYTHING_REQUEST_DATE_ACCESSED = 0x00000080;
const int EVERYTHING_REQUEST_ATTRIBUTES = 0x00000100;
const int EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = 0x00000200;
const int EVERYTHING_REQUEST_RUN_COUNT = 0x00000400;
const int EVERYTHING_REQUEST_DATE_RUN = 0x00000800;
const int EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = 0x00001000;
const int EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = 0x00002000;
const int EVERYTHING_REQUEST_HIGHLIGHTED_PATH = 0x00004000;
const int EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000;

const int EVERYTHING_SORT_NAME_ASCENDING = 1;
const int EVERYTHING_SORT_NAME_DESCENDING = 2;
const int EVERYTHING_SORT_PATH_ASCENDING = 3;
const int EVERYTHING_SORT_PATH_DESCENDING = 4;
const int EVERYTHING_SORT_SIZE_ASCENDING = 5;
const int EVERYTHING_SORT_SIZE_DESCENDING = 6;
const int EVERYTHING_SORT_EXTENSION_ASCENDING = 7;
const int EVERYTHING_SORT_EXTENSION_DESCENDING = 8;
const int EVERYTHING_SORT_TYPE_NAME_ASCENDING = 9;
const int EVERYTHING_SORT_TYPE_NAME_DESCENDING = 10;
const int EVERYTHING_SORT_DATE_CREATED_ASCENDING = 11;
const int EVERYTHING_SORT_DATE_CREATED_DESCENDING = 12;
const int EVERYTHING_SORT_DATE_MODIFIED_ASCENDING = 13;
const int EVERYTHING_SORT_DATE_MODIFIED_DESCENDING = 14;
const int EVERYTHING_SORT_ATTRIBUTES_ASCENDING = 15;
const int EVERYTHING_SORT_ATTRIBUTES_DESCENDING = 16;
const int EVERYTHING_SORT_FILE_LIST_FILENAME_ASCENDING = 17;
const int EVERYTHING_SORT_FILE_LIST_FILENAME_DESCENDING = 18;
const int EVERYTHING_SORT_RUN_COUNT_ASCENDING = 19;
const int EVERYTHING_SORT_RUN_COUNT_DESCENDING = 20;
const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_ASCENDING = 21;
const int EVERYTHING_SORT_DATE_RECENTLY_CHANGED_DESCENDING = 22;
const int EVERYTHING_SORT_DATE_ACCESSED_ASCENDING = 23;
const int EVERYTHING_SORT_DATE_ACCESSED_DESCENDING= 24;
const int EVERYTHING_SORT_DATE_RUN_ASCENDING = 25;
const int EVERYTHING_SORT_DATE_RUN_DESCENDING = 26;

const int EVERYTHING_TARGET_MACHINE_X86 = 1;
const int EVERYTHING_TARGET_MACHINE_X64 = 2;
const int EVERYTHING_TARGET_MACHINE_ARM = 3;

[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern int Everything_SetSearch(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(UInt32 dwMax);
[DllImport("Everything32.dll")]
public static extern void Everything_SetOffset(UInt32 dwOffset);

[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", CharSet = CharSet.Unicode)]
public static extern string Everything_GetSearch();
[DllImport("Everything32.dll")]
public static extern int Everything_GetLastError();

[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern bool Everything_Query(bool bWait);

[DllImport("Everything32.dll")]
public static extern void Everything_SortResultsByPath();

[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetNumFileResults();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetNumFolderResults();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetNumResults();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetTotFileResults();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetTotFolderResults();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetTotResults();
[DllImport("Everything32.dll")]
public static extern bool Everything_IsVolumeResult(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern bool Everything_IsFolderResult(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern bool Everything_IsFileResult(UInt32 nIndex);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern void Everything_GetResultFullPathName(UInt32 nIndex, StringBuilder lpString, UInt32 nMaxCount);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultPath(UInt32 nIndex);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultFileName(UInt32 nIndex);

[DllImport("Everything32.dll")]
public static extern void Everything_Reset();
[DllImport("Everything32.dll")]
public static extern void Everything_CleanUp();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetMajorVersion();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetMinorVersion();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetRevision();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetBuildNumber();
[DllImport("Everything32.dll")]
public static extern bool Everything_Exit();
[DllImport("Everything32.dll")]
public static extern bool Everything_IsDBLoaded();
[DllImport("Everything32.dll")]
public static extern bool Everything_IsAdmin();
[DllImport("Everything32.dll")]
public static extern bool Everything_IsAppData();
[DllImport("Everything32.dll")]
public static extern bool Everything_RebuildDB();
[DllImport("Everything32.dll")]
public static extern bool Everything_UpdateAllFolderIndexes();
[DllImport("Everything32.dll")]
public static extern bool Everything_SaveDB();
[DllImport("Everything32.dll")]
public static extern bool Everything_SaveRunHistory();
[DllImport("Everything32.dll")]
public static extern bool Everything_DeleteRunHistory();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetTargetMachine();

// Everything 1.4
[DllImport("Everything32.dll")]
public static extern void Everything_SetSort(UInt32 dwSortType);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetSort();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetResultListSort();
[DllImport("Everything32.dll")]
public static extern void Everything_SetRequestFlags(UInt32 dwRequestFlags);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetRequestFlags();
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetResultListRequestFlags();
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultExtension(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultSize(UInt32 nIndex, out long lpFileSize);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultDateCreated(UInt32 nIndex, out long lpFileTime);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultDateModified(UInt32 nIndex, out long lpFileTime);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultDateAccessed(UInt32 nIndex, out long lpFileTime);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetResultAttributes(UInt32 nIndex);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultFileListFileName(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetResultRunCount(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultDateRun(UInt32 nIndex, out long lpFileTime);
[DllImport("Everything32.dll")]
public static extern bool Everything_GetResultDateRecentlyChanged(UInt32 nIndex, out long lpFileTime);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultHighlightedFileName(UInt32 nIndex);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultHighlightedPath(UInt32 nIndex);
[DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
public static extern string Everything_GetResultHighlightedFullPathAndFileName(UInt32 nIndex);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_GetRunCountFromFileName(string lpFileName);
[DllImport("Everything32.dll")]
public static extern bool Everything_SetRunCountFromFileName(string lpFileName, UInt32 dwRunCount);
[DllImport("Everything32.dll")]
public static extern UInt32 Everything_IncRunCountFromFileName(string lpFileName);

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
UInt32 i;
const int bufsize = 260;
StringBuilder buf = new StringBuilder(bufsize);

// set the search
Everything_SetSearch(textBox1.Text);

// request name and size
Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH | EVERYTHING_REQUEST_SIZE);

// sort by size
Everything_SetSort(EVERYTHING_SORT_SIZE_DESCENDING);

// use our own custom scrollbar...
// Everything_SetMax(listBox1.ClientRectangle.Height / listBox1.ItemHeight);
// Everything_SetOffset(VerticalScrollBarPosition...);

// execute the query
Everything_Query(true);

// sort by path
// Everything_SortResultsByPath();

// clear the old list of results
listBox1.Items.Clear();

// set the window title
Text = textBox1.Text + " - " + Everything_GetNumResults() + " Results";

// loop through the results, adding each result to the listbox.
for (i = 0; i < Everything_GetNumResults(); i++)
{
long size;

// get the result's full path and file name.
Everything_GetResultFullPathName(i, buf, bufsize);

Everything_GetResultSize(i, out size);

// add it to the list box
listBox1.Items.Insert((int)i, buf + " " + size.ToString());
}
}
}
}

© 2018 - Privacy