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 学习——Spring IOC概念
    Oracle使用——Oracle表空间处理
    Spring 学习——Spring框架结构、概念
    Java错误——The hierarchy of the type is inconsistent错误
    Git教程
    git 常用操作
    "use strict"; 的正确使用
    react学习笔记(二)React表单详解
    chrome 添加有用扩展程序
    react学习笔记(一)
  • 原文地址:https://www.cnblogs.com/goodluck14/p/13229794.html
Copyright © 2011-2022 走看看