在同一程序中组合SDL窗口和GTK +窗口

我正在创建和SDL程序,其中一些function打开GTK +窗口。 主窗口是SDL窗口,GTK +窗口主要是对话框。 main()函数正常打开SDL窗口,并且具有SDL事件的while循环,通常在SDL中。 一些SDL事件调用打开GTK +窗口的函数,如GTK +窗口通常是打开的,并且具有与main()在GTK +程序中相同的结构。

所有窗口都应该打开,问题在于关闭GTK +窗口。 当我关闭GTK +窗口时,它会一直打开,直到我关闭主SDL窗口。 当我关闭GTK +窗口时,唯一发生的事情是它在关闭后不再做任何事情,所以例如如果我最小化它然后再次最大化它,它就会变空。 当我关闭它时,SDL窗口也会响应事件,就像GTK +窗口不存在一样。 所以一切都像GTK +窗口关闭一样,只是它仍然可见。 我有一个g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(gtk_main_quit),NULL); 打开GTK +窗口的每个函数中的行,这不是问题所在。

当我点击GTK +窗口中的关闭按钮时,如何关闭GTK +窗口但不关闭SDL窗口?

这是代码的结构(GTK窗口是这里的About对话框):

 #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #ifdef WINDOWS #include  #endif void openGtkWindow(){ GtkWidget *aboutWindow = gtk_about_dialog_new(); //Write things in the About window g_signal_connect(G_OBJECT(aboutWindow),"delete-event",G_CALLBACK(gtk_main_quit),NULL); gtk_widget_show(aboutWindow); gtk_main(); } int main(int argc,char *argv[]){ gtk_init(&argc,&argv); SDL_Surface *screen; SDL_Event event; SDL_Init(SDL_INIT_VIDEO); putenv("SDL_VIDEO_CENTERED=center"); SDL_WM_SetCaption("SDL window",NULL); SDL_WM_SetIcon(IMG_Load("icon.png"),NULL); screen = SDL_SetVideoMode(600,400,32,SDL_HWSURFACE | SDL_DOUBLEBUF); //Draw things in the SDL window SDL_Flip(screen); int continuer = 1; while(continuer){ SDL_WaitEvent(&event); switch(event.type){ case SDL_QUIT: continuer = 0; break; case SDL_MOUSEBUTTONUP: if(event.button.button == SDL_BUTTON_LEFT){ if(/*Test if the mouse is inside the About button*/){ openGtkWindow(); } } break; } } SDL_Quit(); return 0; } 

我认为你需要在你的while循环中处理GTK事件(我认为你没有调用gtk_main并且你保持自定义while循环)。

你可以通过使用类似的东西来做到这一点:

 while (running) { while (gtk_events_pending()) // are there GTK events to handle gtk_main_iteration(); // - If so, handle them // Your SDL Code }