0

how can I configure GTK+ 2.24 on Visual Studio 2012? I thought that it will be enough to perform the same steps that were needed to take in order to configure GTK+ 2.24 on Visual Studio 2010 ( How to configure gtk on Visual studio 2010 ).

#include <gtk-2.0\gtk\gtk.h>

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;
}

I was wrong, because even if I was able to build that simple project which was provided in the link mentioned before (I slightly edited it to meet visual studio requirement for C to declare all variables before any action), I was still unable to launch it - the window did not show up and I had to kill my program using Task manager since it consumed 100% of processor time. What is more I was able to build and launch simple window project from here: http://zetcode.com/tutorials/gtktutorial/firstprograms/ .

Code:

 #include <gtk/gtk.h>

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

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Center");
  gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_widget_show(window);

  g_signal_connect_swapped(G_OBJECT(window), "destroy",
  G_CALLBACK(gtk_main_quit), NULL);

  gtk_main();

  return 0;
 }

And this one ran fine.

Notice the headers : #include <gtk-2.0\gtk\gtk.h> and #include <gtk/gtk.h> . The former belongs to gtk+2 while the latter belongs to gtk+1.2.

How can I configure my Visual Studio 2012 so that it could launch gtk+2.24?

Community
  • 1
  • 1
Benas
  • 2,106
  • 2
  • 39
  • 66

1 Answers1

1

Use the header #include <gtk/gtk.h>. The preprocessor will find it automatically. If you had the program from Zetcode worked, there is nothing wrong with the compiler. Just the header. Also, if that doesn't work somehow, revert to your original header and delete the

  gtk_widget_set_usize(window, 300, 200); <<(edit) deprecated later on

Instead, use:

  gtk_window_set_default_size ( GTK_WINDOW (window), 400, 200 );

Edited:

I didn't read it carefully. My mistake. Swap the place between gtk_init () with newly created GtkWindow. Without the init first, Gtk won't process anything

luciomrx
  • 1,165
  • 1
  • 7
  • 7
  • I changed header to the gtk/gtk.h, it builds, but then I launch the program, window doesn't show up, instead new process is created, which consumes all CPU time. Same happens when I change gtk_widget_set_usize(window, 300, 200); to gtk_window_set_default_size ( GTK_WINDOW (window), 400, 200 ); . – Benas May 19 '14 at 10:59
  • changing header to #include and then editing code to GtkWidget* window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); actually did the job. Thank you! Oh, and it also works with #include header too. – Benas May 19 '14 at 11:37