c++ - Visual Studio 2015 中没有显示 GTK

标签 c++ visual-studio gtk

经过几轮故障排除后,我能够在 Visual Studio 中正确编译 GTK 源代码。我遵循了与 'How to configure gtk on Visual studio 2010' 不太相似的程序.代码如下,

#include <gtk-2.0\gtk\gtk.h>
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")

int main(int argc, char* argv[])
{


GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_init(&argc, &argv);
gtk_widget_set_usize(window, 300, 200);

g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit),     NULL);
gtk_window_set_title(GTK_WINDOW(window), "GTK+ with VS2010");

gtk_widget_show(window);

gtk_main();
return 0;
}

但是在启动代码时没有窗口出现。 Visual Studio 只是指示解决方案正在运行但没有窗口出现。有什么想法吗?

最佳答案

这里有问题:

GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_init(&argc, &argv);

你应该调用gtk_init 创建任何窗口之前:

Call this function before using any other GTK+ functions in your GUI applications. It will initialize everything needed to operate the toolkit and parses some standard command line options.

尝试:

gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

关于c++ - Visual Studio 2015 中没有显示 GTK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36833769/

相关文章:

c - GStreamer:没有这样的文件或目录

c++ - 谁能告诉我为什么 float 不能容纳 3153600000?

visual-studio - 指定VS扩展安装目录名

visual-studio - 事件选项卡固定在 Visual Studio 的左侧

python - 如何真正将窗口置于所有窗口之上——Linux PyGTK

python - 如何更改 GTK 小部件(如堆栈)的属性?

c++ - 使用新运算符时的数组生命周期

c++ - 仅需要 k 位时的快速求幂 - 续

c++ - 如何在 C++ 初始化时重载分配运算符以分配对象

visual-studio - CMake:将文件作为内容添加到 Visual Studio 解决方案