从NW.JS的程序切换器隐藏窗口

我正在用NW.JS(node-webkit)编写桌面应用程序。 在我的应用程序用户可能会打开很多窗口,我想隐藏他们从程序切换器(ALT +标签)和任务栏。 我已经find了从taksbar隐藏窗口的选项,但无法find任何方法来隐藏程序切换器。 这甚至有可能吗? 或者至less是可以将所有窗口分组为一个(就像在Windows上的便利贴)?

这个特性可能会在某些时候出现,但是从版本0.12.3开始,node-webkit没有提供任何实现工具types窗口的接口,所以没有办法用javascript或者使用项目的package.json文件来实现这个function。 我可以在这里想到两个select。

1.自己构buildnode-webkit。 该指南非常简单而全面。 您需要在native_aurora_aura.cc中修改NativeWindowAura的构造函数 ,具体是:

 #if defined(OS_WIN) HWND hwnd = views::HWNDForWidget(window_->GetTopLevelWidget()); int current_style = ::GetWindowLong(hwnd, GWL_STYLE); ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION); //This is the importante line #endif 

至:

  ::SetWindowLong(hwnd, GWL_STYLE, current_style | WS_CAPTION | WS_EX_TOOLWINDOW); 

请注意,这是一个简单的解决scheme,将导致所有新窗口默认为工具样式,切换窗口时不可见。 使清单文件或窗口API可用此function将需要更改几个文件。

2.编写并部署一个加载打包项目(或项目文件夹)的启动应用程序,连续search具有特定标题的窗口并设置窗口样式。 下面是一个使用ac#console应用程序的例子,但是您也可以使用c ++或任何.NET语言来实现:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Timers; using System.Diagnostics; namespace nw { class Program { const int GWL_EXSTYLE = -0x14; const int WS_EX_APPWINDOW = 0x40000; const int WS_EX_TOOLWINDOW = 0x80; const int WS_EX_COMPOSITED = 0x02000000; [DllImport("user32", CharSet = CharSet.Auto)] static extern int GetWindowLong(IntPtr hwnd, int index); [DllImport("User32.Dll")] static extern int SetWindowLong(IntPtr hwnd, int index, int newLong); [DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount); [DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowTextLength(IntPtr hWnd); [DllImport("user32.dll")] static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam); [DllImport("user32.dll")] static extern IntPtr SetWindowText(IntPtr HWND, string Text); delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); //------------------------------------------------------------------ static void Main(string[] args) { // Test an unpackaged app like: // Process.Start(<path\to\nw.exe>, <path\to\project-folder>); Process.Start("packaged-nw-app.js"); Timer timer = new Timer() { Interval = 100, Enabled = true }; timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); Console.ReadLine(); } //------------------------------------------------------------------ static void OnTimedEvent(object source, ElapsedEventArgs e) { // Find our target windows (change "nw-tool-window" to your window title) IEnumerable<IntPtr> windows = FindWindowsWithText("nw-tool-window"); foreach (var window in windows) { // Apply WS_EX_TOOLWINDOW to the current style SetWindowLong(window, GWL_EXSTYLE, (GetWindowLong(window, GWL_EXSTYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW); // Change title to flag as changed SetWindowText(window, "nw-tool-window-hidden"); } } //------------------------------------------------------------------ static string GetWindowText(IntPtr hwnd) { int size = GetWindowTextLength(hwnd); if (size > 0) { var builder = new StringBuilder(size + 1); GetWindowText(hwnd, builder, builder.Capacity); return builder.ToString(); } return String.Empty; } //------------------------------------------------------------------ static IEnumerable<IntPtr> FindWindows(EnumWindowsProc filter) { IntPtr found = IntPtr.Zero; List<IntPtr> windows = new List<IntPtr>(); EnumWindows(delegate(IntPtr wnd, IntPtr param) { if (filter(wnd, param)) { windows.Add(wnd); } return true; }, IntPtr.Zero); return windows; } //------------------------------------------------------------ static IEnumerable<IntPtr> FindWindowsWithText(string titleText) { return FindWindows(delegate(IntPtr wnd, IntPtr param) { return GetWindowText(wnd).Contains(titleText); }); } } } 

find标题的代码是从这里拿走的。 如果你只对你的主窗口感兴趣,你可以摆脱上面的大部分代码,并使用FindWindowSetWindowLong 。 你也应该隐藏控制台或者窗口(如果你使用Forms或者WPF来做这个),那么关于如何在SO上完成的信息就够了。

第二种方法是有一点哈克,但是,我宁愿去第一个。 也许实现它,而不是硬编码,并打开拉请求:)

我从来没有使用NW.JS,所以这可能是完全错误的,但它看起来像NM.JS的本地用户界面模块。 我会想象使用这个模块,你应该能够创build本地窗口,并给他们一个WS_EX_TOOLWINDOW风格。 看到这个答案: 从Alt-Tab程序切换器隐藏窗口的最佳方法 。 如果您只针对Windows,这似乎是通知的最佳path。

另一个想法是使用IFRAMES构build应用程序,以便只有一个本地窗口。 然后,您可以使用JavaScript和您自己的接口来决定哪些IFRAMES正在显示。