{"id":1294,"date":"2013-10-07T18:09:43","date_gmt":"2013-10-07T18:09:43","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=1294"},"modified":"2014-09-26T15:05:13","modified_gmt":"2014-09-26T15:05:13","slug":"creating-a-gtk-applicaiton","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/gui-programming-in-c\/gtk\/creating-a-gtk-applicaiton","title":{"rendered":".Creating A GTK Applicaiton"},"content":{"rendered":"<p>\n&nbsp;\n<\/p>\n<h4>\nHeader FIles<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n#include &lt;gtk\/gtk.h&gt;\r\n<\/code><\/pre>\n<h4>\nIn The Main Function<br \/>\n<\/h4>\n<p>\nGTK replaces the normal main loop to make your application become event driven. This is an example of a basic main function, but you add to this all of the widgets etc your application needs before finally calling gtk_main(), which takes over running the application from its own main loop.\n<\/p>\n<pre>\r\n<code>\r\n\t\/\/---------------------------------\r\n\t\/\/----- CREATE THE GTK WINDOW -----\r\n\t\/\/---------------------------------\r\n\tGtkWidget *MainWindow;\r\n\t\r\n\tgtk_init(&amp;argc, &amp;argv);\r\n\t\r\n\tMainWindow= gtk_window_new(GTK_WINDOW_TOPLEVEL); \t\t\/\/GTK_WINDOW_TOPLEVEL = Has a titlebar and border, managed by the window manager. \r\n\tgtk_window_set_title(GTK_WINDOW(MainWindow), &quot;My Application&quot;);\r\n\tgtk_window_set_default_size(GTK_WINDOW(MainWindow), 400, 300);\t\t\/\/Size of the the client area (excluding the additional areas provided by the window manager)\r\n\tgtk_window_set_position(GTK_WINDOW(MainWindow), GTK_WIN_POS_CENTER);\r\n\tgtk_widget_show_all(MainWindow);\r\n\r\n\t\/\/Close the application if the x button is pressed if ALT+F4 is used\r\n\tg_signal_connect(G_OBJECT(MainWindow), &quot;destroy&quot;, G_CALLBACK(gtk_main_quit), NULL);\r\n\r\n\r\n\t\/\/----- ENTER THE GTK MAIN LOOP -----\r\n\tgtk_main();\t\t\/\/Enter the GTK+ main loop until the application closes.\r\n\r\n\treturn 0;\r\n<\/code><\/pre>\n<p>\nIf you still need your own main loop to carry out background tasks you can simple create a timer to fire say every 1mS &#8211; see <a href=\"https:\/\/raspberry-projects.com\/pi\/programming-in-c\/gui-programming-in-c\/gtk\/timers\">here<\/a>.\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Header FIles #include &lt;gtk\/gtk.h&gt; In The Main Function GTK replaces the normal main loop to make your application become event driven. This is an example of a basic main function, but you add to this all of the widgets etc your application needs before finally calling gtk_main(), which takes over running the application from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[],"class_list":["post-1294","post","type-post","status-publish","format-standard","hentry","category-gtk"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=1294"}],"version-history":[{"count":15,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1294\/revisions"}],"predecessor-version":[{"id":1547,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/1294\/revisions\/1547"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=1294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=1294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=1294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}