- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当应用程序的主要 Form
- 传递给 Application.Run()
的那个 - 有
this.ShowInTaskBar = false;
然后,表示该应用程序的 Process
实例具有 0
的 MainWindowHandle
,这意味着 Process.CloseMainWindow()
不起作用。
我该如何解决这个问题?我需要通过 Process
实例彻底关闭 Form
。
最佳答案
我找到了一种替代方法,即回到 Win32 并使用窗口标题。它很乱,但它适用于我的情况。
该示例具有一个应用程序实例的上下文菜单,关闭该应用程序的所有实例。
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsCallback x, int y);
public delegate bool EnumWindowsCallback(int hwnd, int lParam);
[DllImport("user32.dll")]
public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
private void ContextMenu_Quit_All(object sender, EventArgs ea)
{
EnumWindowsCallback itemHandler = (hwnd, lParam) =>
{
StringBuilder sb = new StringBuilder(1024);
GetWindowText(hwnd, sb, sb.Capacity);
if ((sb.ToString() == MainWindow.APP_WINDOW_TITLE) &&
(hwnd != mainWindow.Handle.ToInt32())) // Don't close self yet
{
PostMessage(new IntPtr(hwnd), /*WM_CLOSE*/0x0010, 0, 0);
}
// Continue enumerating windows. There may be more instances to close.
return true;
};
EnumWindows(itemHandler, 0);
// Close self ..
}
关于c# - Form.ShowInTaskBar/Process.MainWindowHandle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1006459/
我阅读了一些关于 MainWindowHandle 的线程,但我找不到解决我的问题的方法,我正在启动一个 gui 应用程序并希望通过进程对象获取 MainWindowHandle,但句柄值始终为零,如
我尝试阅读 MainWindowHanlde For Acrobat Reader 10 Process 以便我可以设置 SetParent API我试过了 private Process pDock
我有一个 WPF 应用程序。当它启动时,我需要检查是否已经有一个实例在运行。如果是这样,那么我将使用 PInvoke“显示”正在运行的实例: SendNotifyMessage(proc.MainWi
看看这张图片: 这就是我如何获得被黑框包围的窗口的句柄。 Process[] processes = Process.GetProcessesByName("TopazChat")
我有一个程序只允许其自身运行一个实例。我用这个代码 bool createdNew = true; using(Mutex mutex = new Mutex(true, "MobilePOSServ
为什么 process.MainWindowHandle 在下面的代码中为零? Process me = Process.GetCurrentProcess(); foreach (Process p
我一直在努力理解Process.MainWindowHandle . 根据 MSDN; "主窗口是进程启动时创建的窗口。初始化后,可能会打开其他窗口,包括 Modal 和 TopLevel 窗口,但与
我正在尝试获取我的 C# 应用程序主窗体的窗口句柄 (HWND)(该应用程序只有 1 个窗体)。 互联网上的一些解决方案表明我可以使用: Process.GetCurrentProcess().Mai
当应用程序的主要 Form - 传递给 Application.Run() 的那个 - 有 this.ShowInTaskBar = false; 然后,表示该应用程序的 Process 实例具有 0
我有一个生成 C# 应用程序的 Electron 应用程序。 C# 应用程序想要获取 Electron BrowserWindow 的 MainWindowHandle,但它总是返回 IntPtr.Z
我正在尝试“ Hook ”到窗口的消息中以检测最小化/最大化。我环顾四周,认为唯一/最好的解决方案是挂接到窗口的消息,检查 WM_WINDOWPOSCHANGED 消息,然后检查它的状态。 我遇到了一
这是我的代码: using (Process game = Process.Start(new ProcessStartInfo() { FileName="D
我在 PowerShell 中编写了一个 Windows 服务。它运作良好,但我需要找到一个解决方案来解决一个主要限制。我需要用 列出所有进程窗口 应用程序 - 这是用于被动应用程序计量(即每个登录用
在 .NET Core (3.1) 中访问 MainWindowHandle 时,我遇到了 Process 类的奇怪行为。 考虑以下函数: bool TestProcess() { var p
我是一名优秀的程序员,十分优秀!