2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="ShowInactiveTopmost.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2020-03-28 08:43:16 +13:00
|
|
|
|
|
2020-03-30 06:26:45 +13:00
|
|
|
|
namespace SystemTrayMenu.DllImports
|
2020-03-28 08:43:16 +13:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// wraps the methodcalls to native windows dll's.
|
|
|
|
|
/// </summary>
|
2020-03-28 08:43:16 +13:00
|
|
|
|
public static partial class NativeMethods
|
|
|
|
|
{
|
|
|
|
|
private const int SW_SHOWNOACTIVATE = 4;
|
|
|
|
|
private const int HWND_TOPMOST = -1;
|
|
|
|
|
private const uint SWP_NOACTIVATE = 0x0010;
|
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
public static void User32ShowInactiveTopmost(Form form)
|
|
|
|
|
{
|
|
|
|
|
if (form != null)
|
|
|
|
|
{
|
|
|
|
|
_ = ShowWindow(form.Handle, SW_SHOWNOACTIVATE);
|
|
|
|
|
SetWindowPos(
|
|
|
|
|
form.Handle.ToInt32(),
|
|
|
|
|
HWND_TOPMOST,
|
|
|
|
|
form.Left,
|
|
|
|
|
form.Top,
|
|
|
|
|
form.Width,
|
|
|
|
|
form.Height,
|
|
|
|
|
SWP_NOACTIVATE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 08:43:16 +13:00
|
|
|
|
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
|
|
|
|
|
private static extern bool SetWindowPos(
|
|
|
|
|
int hWnd, // Window handle
|
|
|
|
|
int hWndInsertAfter, // Placement-order handle
|
|
|
|
|
int X, // Horizontal position
|
|
|
|
|
int Y, // Vertical position
|
|
|
|
|
int cx, // Width
|
|
|
|
|
int cy, // Height
|
|
|
|
|
uint uFlags); // Window positioning flags
|
|
|
|
|
}
|
|
|
|
|
}
|