File Explorer Detection in Windows Explorer

On Windows, either on the desktop or in Windows Explorer, I want to determine when the file or folder is selected (highlighted). When this happens, I want to display a message box with the full name of the file or folder.

If multiple items are selected, I want to display all of them.

Please note that my solution should be written in C #.

+4
source share
2 answers

Take a look at this example to get a mouse click or selected events:

https://stackoverflow.com/questions/7222749/i-created-a-program-to-hide-desktop-icons-on-double-click-of-desktop-but-would-o

Join this with the following code. Do not forget to add a link to SHDocVW.dll and Shell32.dll, this will return all selected paths of elements and folders in each explorer.

public void GetListOfSelectedFilesAndFolderOfWindowsExplorer() { string filename; ArrayList selected = new ArrayList(); var shell = new Shell32.Shell(); //For each explorer foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindowsClass()) { filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (filename.ToLowerInvariant() == "explorer") { Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems(); foreach (Shell32.FolderItem item in items) { MessageBox.Show(item.Path.ToString()); selected.Add(item.Path); } } } } 
+3
source

Just adding something to Rainier's answer:

  • SHDocVW.dll and Shell32.dll are located in the folder C: \ Windows \ System32
  • If you get the SHDocVw.ShellWindowsClass () error, just right-click the SHDocVw link in your Solution Explorer, then select "Properties" and Paste interaction types into false
0
source

Source: https://habr.com/ru/post/1446710/


All Articles