8

I'm very new with C#.

I was boring that sometimes I close a window and after few seconds I note that I need that window again, and is very frustrating to me to reopen Windows Explorer and navigate to that specific path.

So I want to create a little app that permits me store a list of the last closed windows. And with a key shortcut restore one by one the last closed windows (just like I do with browsers like Firefox) and with other key shorcut display a list with the last n windows.

I don't know how to get the paths of the windows and is important that the program gets also when the paths changed (when the user navigates).

Thanks for help.


I will post the link once the app will be finished.

Memochipan
  • 3,405
  • 5
  • 35
  • 60

1 Answers1

14

Taken from here:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

string filename;

foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
   filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();

   if ( filename.Equals( "explorer" ) )
   {
      // Save the location off to your application
      Console.WriteLine( "Explorer location : {0}", ie.LocationURL );

      // Setup a trigger for when the user navigates
      ie.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(handlerMethod);
   }
}
Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44
  • Thanks Garret. I get an error that said that can't found the namespace SHDocVw. – Memochipan Dec 15 '11 at 13:56
  • 1
    Add a reference to the Internet Explorer Controls COM object. See here for more info: http://omegacoder.com/?p=63. – Garrett Vlieger Dec 15 '11 at 13:58
  • Ok. I could imported the Internet Explorer Control COM object. Now I get this error: The type of interoperability 'SHDocVw.ShellWindowsClass' can not be embedded. Use the interface of its place. What is talking about? – Memochipan Dec 15 '11 at 14:30
  • Edited the code above: `SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();` – Garrett Vlieger Dec 15 '11 at 14:45
  • Now works perfect!! Only I have an error with **The name 'handlerMethod' does not exist in the current context** but is guess that I have to build a handlerMethod. Thank you very much. – Memochipan Dec 15 '11 at 15:02
  • Yep, you just need to define that method. Visual Studio will fill in the code for you, but it'll look like this: `void handlerMethod(object pDisp, ref object URL)` – Garrett Vlieger Dec 15 '11 at 15:04
  • After a long period of inactivity I'm trying to do this again, but I'm still lost. It is hard to find information about SHDocVw and how to implement it. I've been learning C# but this is not like doing forms in Visual Studio. For example, I wanted to detect the last closed window or to pass the URL object to textbox but I can't. In the first one it seems that I need a ¿hook? or use ¿WindowRevoked?. In the second one I get an error in runtime because the textbox is reached from a different process. Where can I learn in systematic way this topics, to understand what I'm doing? Thank you! – Memochipan Nov 03 '12 at 00:39
  • The `if` does not seem necessary, as `shellWindows.Count` shows just the number of explorer windows currently open, but not command terminal windows. – Roland Oct 19 '16 at 10:02