-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #945 from MKKNinetyTwo/master
Implement Explorer.exe monitoring feature.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using ManagedShell.Common.Logging; | ||
using ManagedShell.Interop; | ||
using System; | ||
using System.Windows.Forms; | ||
|
||
namespace RetroBar.Utilities | ||
{ | ||
public class ExplorerMonitor : IDisposable | ||
{ | ||
private ExplorerMonitorWindow _explorerMonitorWindow; | ||
|
||
public void ExplorerMonitorStart(WindowManager windowManagerRef) | ||
{ | ||
if (_explorerMonitorWindow != null) { return; } // Prevent multiple monitors. | ||
|
||
_explorerMonitorWindow = new ExplorerMonitorWindow(windowManagerRef); // Start monitoring. | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_explorerMonitorWindow?.Dispose(); | ||
} | ||
|
||
private class ExplorerMonitorWindow : NativeWindow, IDisposable | ||
{ | ||
private readonly WindowManager _windowManagerRef; | ||
private static readonly int WM_TASKBARCREATEDMESSAGE = NativeMethods.RegisterWindowMessage("TaskbarCreated"); | ||
|
||
public ExplorerMonitorWindow(WindowManager windowManagerRef) | ||
{ | ||
_windowManagerRef = windowManagerRef; | ||
CreateHandle(new CreateParams()); | ||
} | ||
|
||
protected override void WndProc(ref Message m) | ||
{ | ||
if (m.Msg == WM_TASKBARCREATEDMESSAGE) | ||
{ | ||
try | ||
{ | ||
_windowManagerRef.ReopenTaskbars(); // Reopen taskbars if explorer.exe is restarted. | ||
} | ||
catch (Exception ex) | ||
{ | ||
ShellLogger.Warning($"Error handling TaskbarCreated message on ExplorerMonitor: {ex.Message}"); | ||
} | ||
} | ||
|
||
base.WndProc(ref m); // Call the base class to process other messages so we dont accidentally cause crashes or bugs. | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
DestroyHandle(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters