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)

  • 相关阅读:
    spring 事务
    Servlet详解之两个init方法的作用
    被request.getLocalAddr()苦闷了很久
    Java获取IP地址:request.getRemoteAddr()警惕
    MongoDB笔记
    hexo+github搭建博客
    Python处理Excel(使用openpyxl库)
    Wireshark使用学习
    查看开启操作系统端口
    记录Centos7服务器搭建过程
  • 原文地址:https://www.cnblogs.com/goodluck14/p/13229794.html
Copyright © 2011-2022 走看看