joplin-notes/joplin notion extension/Web Development/C_C++/GTK/Functions.md
2026-11-04 00:33:23 +05:30

2.3 KiB

Functions https://docs.gtk.org/gtk3/class.Window.html

#include <gtk/gtk.h>
#include <stdio.h>

void gtk_main_quit1()
{
    gtk_main_quit();
    // printf("Inside quit");
}



int main(int argc,char **argv)
{
    // printf("hello world 12");

    gtk_init(&argc,&argv);
    int a=12;
    int b=13;

    const char *title;
    int width,height;

    GtkWidget *window;
    // gtk_window_new(type) here type can be pop window or top level
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);


    //to give title
    gtk_window_set_title(GTK_WINDOW(window),"firstapp");
  
    // para: gtkwindow,width,height
    gtk_window_set_default_size(GTK_WINDOW(window), 500,500);

    // type casting to GTK window as it is GTKWidget, and passing GtkWindowPosition as GTK_WIN_POS_CENTER_ALWAYS
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER_ALWAYS);

    // if set to false user cant resize window
    gtk_window_set_resizable(GTK_WINDOW(window),TRUE);

    // to remove title bar means no minimize,maximize or close btton and no title by setting to false
    gtk_window_set_decorated(GTK_WINDOW(window),TRUE);

    // to maximize the window by default
    // gtk_window_maximize(GTK_WINDOW(window));

    // getting title of window
    title=gtk_window_get_title(GTK_WINDOW(window));
    printf("Your title is: %s\n", title);



    //getting size of window
    gtk_window_get_size(GTK_WINDOW(window),&width,&height);
    printf(" Width:%d\tHeight %d\n", width,height);

    // checking if window is decorated or maximized or active
    printf("GTK WINDOW Decorated? %d\n", gtk_window_get_decorated(GTK_WINDOW(window) ));
    printf("GTK WINDOW Maximized? %d\n", gtk_window_is_maximized(GTK_WINDOW(window) ));
    printf("GTK WINDOW Active? %d\n", gtk_window_is_active(GTK_WINDOW(window) ));


    // callback function
    // 1st para is instance,2nd is detail,3rd is callback function handler, 4th is data to be passed to call back function
    // gtk_main_quit will quit the gtk_main program 
    g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit1),NULL);

    



    // show all gtk widgets that are created. window is parent widget
    gtk_widget_show_all(window);



    
    

    gtk_main();

    
    return 0;
}