如何在Windows上隐藏控制台窗口? [英] How do you suppress the console window on Windows?
问题描述
采用基本示例Gtk +应用并将其命名为main.vala
:>
Take the basic example Gtk+ app and calll it main.vala
:
using Gtk;
int main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
window.title = "First GTK+ Program";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);
var button = new Button.with_label ("Click me!");
button.clicked.connect (() => {
button.label = "Thank you";
});
window.add (button);
window.show_all ();
Gtk.main ();
return 0;
}
添加一个简单的meson.build
文件:
project('gui-test', 'vala', 'c')
dependencies = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('gtk+-3.0')
]
sources = files('main.vala')
executable('gui-test', sources, dependencies: dependencies)
使用msys2中的工具链,可以使用通常的步骤:
With the toolchain from msys2 this can be compiled to a Windows application with the usual steps:
meson build
ninja -C build
生成的可执行文件将具有Windows控制台子系统(-mconsole
).
The resulting executable will have the Windows console subsystem (-mconsole
).
从Windows资源管理器启动后,它将打开一个控制台窗口.
It opens a console window when launched from Windows explorer.
如何避免在此gui应用程序中包含控制台窗口?
How do I avoid having a console window in this gui app?
推荐答案
在可执行文件中设置gui_app: true
:
project('gui-test', 'vala', 'c')
dependencies = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('gtk+-3.0')
]
sources = files('main.vala')
executable('gui-test', sources, dependencies: dependencies, gui_app: true)
This is documentend in the meson manual:
gui_app设置为true时,将此目标标志为GUI应用程序 可以发挥作用的平台(例如Windows)
gui_app when set to true flags this target as a GUI application on platforms where this makes a difference (e.g. Windows)
这篇关于如何在Windows上隐藏控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!