問題描述
場景
我有一個窗口,它有一個打開一個窗口的添加任務(wù)按鈕
.每次用戶點擊它,它都會打開一個窗口.我在 add task window
上有一個按鈕,可以將其最小化.這個最小化按鈕如何實現(xiàn)?
I have a window and it has an add task button
that is opening a window. Everytime user clicks on it, it opens a window. I have a button on add task window
that minimize it. How to implement this minimize button?
代碼
我可以使用以下代碼關(guān)閉
最大化
窗口:
I am able to close
maximize
window by using the code below:
var winclose = function () {
window.close();
}
var winmaximize = function () {
window.moveTo(0, 0);
window.resizeTo(screen.width, screen.height);
}
但是,我找不到任何可以從渲染進(jìn)程中最小化窗口的函數(shù).
However, I am not able to find any function that can minimize a window from rendered process.
請幫忙,非常感謝;
注意:
瀏覽器不向開發(fā)者提供最小化它們的功能.但在這兒是一個不同的場景.這里我使用的是 Electronjs 提供的鉻.因此,在我們開發(fā)桌面應(yīng)用程序時,一定有辦法做到這一點
虛擬下載鏈接:從 OneDrive 下載
推薦答案
可以調(diào)用minimize()
在相應(yīng)的 BrowserWindow
實例上.問題是如何最好地訪問此實例,而這又取決于您打開窗口的方式以及最小化按鈕的位置.從您的示例中,我認(rèn)為最小化按鈕實際上位于您要關(guān)閉的窗口中,在這種情況下,您可以最小化焦點窗口,因為當(dāng)用戶單擊其中的按鈕時,窗口當(dāng)前應(yīng)該具有焦點:
You can call minimize()
on the respective BrowserWindow
instance. The question is how to best get access to this instance and this, in turn, depends on how you open the windows and where your minimize button is. From your example, I take it that the minimize button is actually in the window you want to close, in that case you can just minimize the focused window, because to when a user clicks the button inside it, the window should currently have the focus:
const { remote } = require('electron')
remote.BrowserWindow.getFocusedWindow().minimize();
您也可以使用 BrowserWindow.fromId()
來訪問相關(guān)窗口,例如,如果您想從另一個窗口最小化任務(wù)窗口.
Alternatively you can use BrowserWindow.fromId()
to get access to the window in question if, for example, you want to minimize the task window from the other window.
這篇關(guān)于Electron:如何最小化渲染進(jìn)程中的窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!