Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/ManagedShell.WindowsTasks/TasksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ private ApplicationWindow addWindow(IntPtr hWnd, ApplicationWindow.WindowState i
// This is because if Explorer is running, it will send the message, so we don't need to
if (EnvironmentHelper.IsAppRunningAsShell) sendTaskbarButtonCreatedMessage(win.Handle);

ShellLogger.Debug($"TasksService: Added window {hWnd} ({win.Title})");

return win;
}

Expand All @@ -284,6 +286,8 @@ private void removeWindow(IntPtr hWnd)
ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWnd);
win.Dispose();
Windows.Remove(win);

ShellLogger.Debug($"TasksService: Removed window {hWnd} ({win.Title})");
}
while (Windows.Any(i => i.Handle == hWnd));
}
Expand All @@ -292,6 +296,7 @@ private void removeWindow(IntPtr hWnd)
private void redrawWindow(ApplicationWindow win)
{
win.UpdateProperties();
ShellLogger.Debug($"TasksService: Updated window {win.Handle} ({win.Title})");

foreach (ApplicationWindow wind in Windows)
{
Expand All @@ -313,7 +318,6 @@ private void ShellWinProc(Message msg)
switch ((HSHELL)msg.WParam.ToInt32())
{
case HSHELL.WINDOWCREATED:
ShellLogger.Debug("TasksService: Created: " + msg.LParam);
if (!Windows.Any(i => i.Handle == msg.LParam))
{
addWindow(msg.LParam);
Expand All @@ -326,12 +330,10 @@ private void ShellWinProc(Message msg)
break;

case HSHELL.WINDOWDESTROYED:
ShellLogger.Debug("TasksService: Destroyed: " + msg.LParam);
removeWindow(msg.LParam);
break;

case HSHELL.WINDOWREPLACING:
ShellLogger.Debug("TasksService: Replacing: " + msg.LParam);
if (Windows.Any(i => i.Handle == msg.LParam))
{
ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
Expand All @@ -344,15 +346,12 @@ private void ShellWinProc(Message msg)
}
break;
case HSHELL.WINDOWREPLACED:
ShellLogger.Debug("TasksService: Replaced: " + msg.LParam);
// TODO: If a window gets replaced, we lose app-level state such as overlay icons.
removeWindow(msg.LParam);
break;

case HSHELL.WINDOWACTIVATED:
case HSHELL.RUDEAPPACTIVATED:
ShellLogger.Debug("TasksService: Activated: " + msg.LParam);

foreach (var aWin in Windows.Where(w => w.State == ApplicationWindow.WindowState.Active))
{
aWin.State = ApplicationWindow.WindowState.Inactive;
Expand All @@ -367,6 +366,7 @@ private void ShellWinProc(Message msg)
win = Windows.First(wnd => wnd.Handle == msg.LParam);
win.State = ApplicationWindow.WindowState.Active;
win.SetShowInTaskbar();
ShellLogger.Debug($"TasksService: Activated window {win.Handle} ({win.Title})");
}
else
{
Expand Down Expand Up @@ -396,7 +396,6 @@ private void ShellWinProc(Message msg)
break;

case HSHELL.FLASH:
ShellLogger.Debug("TasksService: Flashing window: " + msg.LParam);
if (Windows.Any(i => i.Handle == msg.LParam))
{
ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
Expand All @@ -419,20 +418,17 @@ private void ShellWinProc(Message msg)
break;

case HSHELL.ENDTASK:
ShellLogger.Debug("TasksService: EndTask called: " + msg.LParam);
removeWindow(msg.LParam);
break;

case HSHELL.GETMINRECT:
ShellLogger.Debug("TasksService: GetMinRect called: " + msg.LParam);
SHELLHOOKINFO winHandle = (SHELLHOOKINFO)Marshal.PtrToStructure(msg.LParam, typeof(SHELLHOOKINFO));
winHandle.rc = new NativeMethods.Rect { Bottom = 100, Left = 0, Right = 100, Top = 0 };
Marshal.StructureToPtr(winHandle, msg.LParam, true);
msg.Result = winHandle.hwnd;
return; // return here so the result isnt reset to DefWindowProc

case HSHELL.REDRAW:
ShellLogger.Debug("TasksService: Redraw called: " + msg.LParam);
if (Windows.Any(i => i.Handle == msg.LParam))
{
ApplicationWindow win = Windows.First(wnd => wnd.Handle == msg.LParam);
Expand Down Expand Up @@ -471,7 +467,7 @@ private void ShellWinProc(Message msg)
ShellLogger.Debug("TasksService: TaskbarCreated received, setting ITaskbarList window");
setTaskbarListHwnd(_HookWin.Handle);
}
else
else if (msg.Msg >= (int)WM.USER)
{
// Handle ITaskbarList functions, most not implemented yet

Expand Down