zoukankan      html  css  js  c++  java
  • An Introduction to C & GUI Programming -----Simon Long 学习笔记 1

    这本书主要是讲C语言和GTK的

    1. 环境准备

    Ubuntu 20.04安装gtk3.0

    sudo apt-get install gtk+-3.0   (书中用的gtk2.0 有点老了)

    2. 编写程序

    第一个gtk程序

    #include <gtk/gtk.h>
    int main (int argc, char *argv[])
    {
        gtk_init (&argc, &argv);
        GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_show (win);
        gtk_main ();
        return 0;
    }

    3. 编译

    gcc `pkg-config --cflags gtk+-3.0` test.c -o hello `pkg-config --libs gtk+-3.0`        test.c 文件生成hello二进制文件

    4.运行结果

     5. 引申

    gtk_window_new感觉是新生成一个窗口,再加一个会如何呢
    #include <gtk/gtk.h>
    int main (int argc, char *argv[])
    {
        gtk_init (&argc, &argv);
        GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        GtkWidget *winwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_widget_show (win);
        gtk_widget_show (winwin);
        gtk_main ();
        return 0;
    }

    编译后运行结果

     生成了2个窗口

    点击窗口上的X并不会终止程序,只是窗口没了(

    If you press the X in the
    top-right corner, the window closes, but if you look in the terminal window from which you
    ran gtktest, you’ll see the program is still running. This is because closing a window doesn’t
    terminate the gtk_main function, which will carry on running until you hit CTRL+C in the
    terminal window)

  • 相关阅读:
    第9天 图片整合
    第六天 元素类型
    第五天 文本溢出
    第四天 盒子模型
    第三天 css核心属性
    第二天 css基础 ,部分选择符
    第一天 HTML基础
    *Move Zeroes
    Word Pattern
    ReentrantLock
  • 原文地址:https://www.cnblogs.com/goodluck14/p/13229794.html
Copyright © 2011-2022 走看看