Schwebendes Bild, wenn eine andere App übertrieben istC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Schwebendes Bild, wenn eine andere App übertrieben ist

Post by Anonymous »

Was ich jetzt seit ein paar Tagen versuche, ist, ein cooles extrudierendes Bild von meiner App in WPF zu erstellen, konnte jedoch nicht in der Lage sein, das schwimmende Bild zu diskutieren, wenn ich eine App öffne oder eine App über meine App bewege. Ich bin nicht der Beste, es zu erklären, aber das meine ich einfacher zu zeigen. Startet "src =" https Floating Transpatant -Fenster nannte es dann aus dem Verarbeitungsfenster mit Verankerungsbreite und Höhe < /p>
Das Problem, das ich habe, ist, als ich es eingerichtet habe. Ich habe es eingerichtet. Wenn eine App über den Bildschirm geht, wird es das Bild los.using System;
< /code>
Verwendung von System.Windows;
Verwenden von System.Windows.input; _isdragging = false; < /p>
public FloatingImageWindow(ProcessingWindow parentWindow)
{
InitializeComponent();
_parentWindow = parentWindow;
PositionWindow(); // Align on startup

// Update position when ProcessingWindow moves or resizes
_parentWindow.LocationChanged += ParentWindow_LocationChanged;
_parentWindow.SizeChanged += ParentWindow_LocationChanged;
}

private void PositionWindow()
{
this.UpdateLayout(); // Ensure layout updates correctly

// Move the floating window to be exactly at the bottom-right corner of ProcessingWindow
this.Left = _parentWindow.Left + _parentWindow.Width - this.Width + 40; // Small right offset
this.Top = _parentWindow.Top + _parentWindow.Height - this.Height; // Align to bottom
}

private void ParentWindow_LocationChanged(object sender, EventArgs e)
{

////PositionWindow(); // Adjust position if parent moves

}

private void FloatingWindow_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
_isDragging = true;
}
}

private void FloatingWindow_MouseUp(object sender, MouseButtonEventArgs e)
{
_isDragging = false;
}
}
< /code>
} < /p>
Dann in der ProcessingWindow < /p>
private FloatingImageWindow _floatingWindow;
private System.Windows.Threading.DispatcherTimer _visibilityTimer;
private bool _isFloatingWindowVisible = true; // Track current visibility state

// Windows API for detecting focus
private const int WM_ACTIVATEAPP = 0x001C;
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);

// Import Windows API

[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();

[DllImport("user32.dll")]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
private void ProcessingWindow_Loaded(object sender, RoutedEventArgs e)
{
ShowFloatingWindow();
HookWindowFocusEvents();
CheckIfButtonShouldBeRemoved();
}

private void HookWindowFocusEvents()
{
IntPtr hwnd = new WindowInteropHelper(this).Handle;
HwndSource source = HwndSource.FromHwnd(hwnd);
if (source != null)
{
source.AddHook(WndProc);
}
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_ACTIVATEAPP)
{
bool isActivated = wParam.ToInt32() != 0;

if (isActivated)
{
ShowFloatingWindowSmoothly();
}
else
{
HideFloatingWindowSmoothly();
}
}
return IntPtr.Zero;
}

private void ShowFloatingWindowSmoothly()
{
if (!_isFloatingWindowVisible)
{
_floatingWindow?.Show();
_isFloatingWindowVisible = true;
}
}
private void HideFloatingWindowSmoothly()
{
if (_isFloatingWindowVisible)
{
_floatingWindow?.Hide();
_isFloatingWindowVisible = false;
}
}

private void ShowFloatingWindow()
{
if (_floatingWindow == null)
{
_floatingWindow = new FloatingImageWindow(this)
{
WindowStartupLocation = WindowStartupLocation.Manual,
AllowsTransparency = true,
ShowInTaskbar = false // Prevents showing separately in the taskbar

};

_floatingWindow.Show();
}
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
_floatingWindow?.Close(); // Close Image Before closing process window.
_floatingWindow = null;
Close();
}
< /code>
Also im Grunde genommen das Problem, das ich habe, ist, dass dies größtenteils funktioniert, aber ich habe 3 Monitore, und wenn ich auf eine App auf den zweiten oder dritten Monitor klicke, wird das Bild auch vom Prozessfenster dispidieren. Ich möchte nur, dass das Bild nur dann überlagert, wenn ein App das Programm überlagert, aber wenn ich mich mit dem BR /P. -BR /P> -Plaud und dem, wie es in der Lage ist, zu einem A -BR -Fenster, und wenn es sich um eine gleiche Art und Weise handelt. Bild 2 Das ist besser, bitte lassen Sie es mich wissen, weil ich überall gesucht habe.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post