Skip to content

Commit

Permalink
Merge pull request #2 from JxBP/feat-teams
Browse files Browse the repository at this point in the history
Handle MS Team's custom notification window.
  • Loading branch information
JxBP authored Nov 3, 2023
2 parents 8f44ced + 54af552 commit 0a63fc6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Toaster/WorkerThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Toaster
{
Expand All @@ -11,6 +12,9 @@ internal class WorkerThread
[DllImport("user32.dll", EntryPoint = "FindWindowW", CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll", EntryPoint = "FindWindowEx", CharSet = CharSet.Unicode)]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr hWndChildAfter, string className, string windowTitle);

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
Expand Down Expand Up @@ -61,16 +65,26 @@ public void Run()

private void Tick()
{
var hWndTeams = FindWindow("Chrome_WidgetWin_1", "Microsoft Teams Notification");
var hWndChrome = FindWindowEx(hWndTeams, IntPtr.Zero, "Chrome_RenderWidgetHostHWND", "Chrome Legacy Window");
if (hWndChrome != IntPtr.Zero)
{
MoveNotification(hWndTeams, config.Corner);
}

var hWnd = FindWindow("Windows.UI.Core.CoreWindow", config.ToastTitle);
if (hWnd == IntPtr.Zero)
if (hWnd != IntPtr.Zero)
{
return;
MoveNotification(hWnd, config.Corner);
}
}

private void MoveNotification(IntPtr hWnd, string corner)
{
GetWindowRect(hWnd, out RECT rect);
var screen = Screen.PrimaryScreen.Bounds;

switch (config.Corner)
switch (corner)
{
case TopLeft:
MoveWindow(hWnd, 0, 0);
Expand Down

0 comments on commit 0a63fc6

Please sign in to comment.