Fast View braucht einen Neuanfang

Nachdem ich in den letzten Tagen endlich mal wieder ein paar Stunden für Fast View gefunden habe, hat sich herausgestellt, dass der Code viel zu unübersichtlich und verschachtelt ist. Kleine Kostprobe gefällig?

private static IntPtr _hookID = IntPtr.Zero;
 private static LowLevelKeyboardProc _proc = new LowLevelKeyboardProc(InterceptKeys.HookCallback);
 private static Form1 form;
 private const int WH_KEYBOARD_LL = 13;
 private const int WM_KEYDOWN = 0x100;

 [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
 private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
 private static string GetExplorerPath()
 {
 try
 {
 ShellWindows shellWindows = new ShellWindowsClass();
 int foregroundHandle = GetForegroundWindow().ToInt32();
 foreach (InternetExplorer ie in shellWindows)
 {
 if (ie.HWND == foregroundHandle)
 {
 return ((IShellFolderViewDual2) ie.Document).FocusedItem.Path;
 }
 }
 }
 catch (Exception)
 {
 return null;
 }
 return null;
 }

 [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
 private static extern IntPtr GetForegroundWindow();
 [DllImport("user32.dll")]
 [return: MarshalAs(UnmanagedType.Bool)]
 static extern bool SetForegroundWindow(IntPtr hWnd);
 [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
 private static extern IntPtr GetModuleHandle(string lpModuleName);
 private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
 if (((nCode >= 0) && (wParam == ((IntPtr) 0x100))) && (Marshal.ReadInt32(lParam) == 0x20))
 {
 form.SpacePressed(GetExplorerPath());
 }
 return CallNextHookEx(_hookID, nCode, wParam, lParam);
 }

Weiterlesen