如何在 Windows 上抑制控制台 window?
How do you suppress the console window on Windows?
取 basic example Gtk+ app 并将其命名为 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)
使用 toolchain from msys2 这可以通过通常的步骤编译成 Windows 应用程序:
meson build
ninja -C build
生成的可执行文件将具有 Windows 控制台子系统 (-mconsole
)。
从 Windows 资源管理器启动时,它会打开一个控制台 window。
如何避免在此 gui 应用程序中使用控制台 window?
在可执行文件中设置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)
这是文档结束 in the meson manual:
gui_app when set to true flags this target as a GUI application on
platforms where this makes a difference (e.g. Windows)
取 basic example Gtk+ app 并将其命名为 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)
使用 toolchain from msys2 这可以通过通常的步骤编译成 Windows 应用程序:
meson build
ninja -C build
生成的可执行文件将具有 Windows 控制台子系统 (-mconsole
)。
从 Windows 资源管理器启动时,它会打开一个控制台 window。
如何避免在此 gui 应用程序中使用控制台 window?
在可执行文件中设置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)
这是文档结束 in the meson manual:
gui_app when set to true flags this target as a GUI application on platforms where this makes a difference (e.g. Windows)