mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 13:05:38 +02:00
#282: capture current dir of explorer window for restore from db
This commit is contained in:
parent
6bc6588727
commit
7f70dda590
3 changed files with 37 additions and 6 deletions
|
@ -27,6 +27,7 @@ namespace PersistentWindows.Common.Models
|
|||
public string ClassName { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Dir { get; set; }
|
||||
public bool IsFullScreen { get; set; }
|
||||
public bool IsMinimized { get; set; }
|
||||
public bool IsInvisible { get; set; }
|
||||
|
|
|
@ -220,7 +220,6 @@ namespace PersistentWindows.Common
|
|||
process = Process.GetCurrentProcess();
|
||||
processPriority = process.PriorityClass;
|
||||
|
||||
|
||||
while (String.IsNullOrEmpty(GetDisplayKey()))
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
|
@ -2260,6 +2259,9 @@ namespace PersistentWindows.Common
|
|||
curDisplayMetrics.Guid = vd.GetWindowDesktopId(hWnd);
|
||||
}
|
||||
|
||||
if (curDisplayMetrics.ClassName.Equals("CabinetWClass"))
|
||||
curDisplayMetrics.Dir = GetExplorerFolderPath(hWnd);
|
||||
|
||||
if (displayKey != dbDisplayKey)
|
||||
curDisplayMetrics.Id = 0; //reset db id
|
||||
|
||||
|
@ -2870,7 +2872,7 @@ namespace PersistentWindows.Common
|
|||
|
||||
private void HideWindow(IntPtr hWnd)
|
||||
{
|
||||
User32.SendMessage(hWnd, User32.WM_SYSCOMMAND, User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, User32.WM_SYSCOMMAND, User32.SC_MINIMIZE, null);
|
||||
uint style = (uint)User32.GetWindowLong(hWnd, User32.GWL_STYLE);
|
||||
style &= ~(uint)WindowStyleFlags.VISIBLE;
|
||||
User32.SetWindowLong(hWnd, User32.GWL_STYLE, style);
|
||||
|
@ -3366,7 +3368,7 @@ namespace PersistentWindows.Common
|
|||
int taskbarMovable = (int)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced", "TaskbarSizeMove", 1);
|
||||
if (taskbarMovable == 0)
|
||||
{
|
||||
User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, null);
|
||||
}
|
||||
bool changed_edge = MoveTaskBar(hWnd, rect);
|
||||
bool changed_width = false;
|
||||
|
@ -3376,7 +3378,7 @@ namespace PersistentWindows.Common
|
|||
restoredWindows.Add(hWnd);
|
||||
if (taskbarMovable == 0)
|
||||
{
|
||||
User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, User32.WM_COMMAND, User32.SC_TOGGLE_TASKBAR_LOCK, null);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
@ -3398,7 +3400,7 @@ namespace PersistentWindows.Common
|
|||
bool action_taken = false;
|
||||
if (!IsMinimized(hWnd))
|
||||
{
|
||||
User32.SendMessage(hWnd, User32.WM_SYSCOMMAND, User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32.SendMessage(hWnd, User32.WM_SYSCOMMAND, User32.SC_MINIMIZE, null);
|
||||
action_taken = true;
|
||||
}
|
||||
|
||||
|
@ -3835,6 +3837,34 @@ namespace PersistentWindows.Common
|
|||
return result;
|
||||
}
|
||||
|
||||
private string GetExplorerFolderPath(IntPtr hwnd)
|
||||
{
|
||||
string path = "";
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr toolbar;
|
||||
toolbar = User32.FindWindowEx(hwnd, IntPtr.Zero, "WorkerW", null);
|
||||
toolbar = User32.FindWindowEx(toolbar, IntPtr.Zero, "ReBarWindow32", null);
|
||||
toolbar = User32.FindWindowEx(toolbar, IntPtr.Zero, "Address Band Root", null);
|
||||
toolbar = User32.FindWindowEx(toolbar, IntPtr.Zero, "msctls_progress32", null);
|
||||
toolbar = User32.FindWindowEx(toolbar, IntPtr.Zero, "Breadcrumb Parent", null);
|
||||
toolbar = User32.FindWindowEx(toolbar, IntPtr.Zero, "ToolbarWindow32", null);
|
||||
if (toolbar != IntPtr.Zero)
|
||||
{
|
||||
path = GetWindowTitle(toolbar, use_cache: false);
|
||||
if (path.StartsWith("Address: "))
|
||||
path = path.Substring(9);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.Error(ex.ToString());
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
private void TestSetWindowPos()
|
||||
{
|
||||
IntPtr[] w = GetWindows("notepad").ToArray();
|
||||
|
|
|
@ -476,7 +476,7 @@ namespace PersistentWindows.Common.WinApiBridge
|
|||
public const string IDI_APPLICATION = "#32512";
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, StringBuilder lParam);
|
||||
public const int WM_COMMAND = 0x0111;
|
||||
public const int WM_SYSCOMMAND = 0x0112;
|
||||
public const int WM_GETICON = 0x7F;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue