zoukankan      html  css  js  c++  java
  • X Window研究笔记(22)

    X Window研究笔记(22)

    转载时请注明出处和作者联系方式
    作者联系方式:李先静 <xianjimli at hotmail dot com>

    22.X Window 简单示例

    对大多数linux程序员来说,很少有机会直接用Xlib去开发应用程序,那样开发效率太低,一般都是使用基于像GTK+和QT这样的toolkit。不过了解一下
    XWindow编程没有什么坏处,这里举一个简单的例子,供新手参考:

    xdemo.c

    #include <string.h>
    #include 
    <X11/Xlib.h>
    #include 
    <X11/keysym.h>

    int main(int argc, char* argv[])
    {
        Display
    * display = XOpenDisplay(NULL);
        
    int screen = DefaultScreen(display);
        
    int width = DisplayWidth(display, screen)/2;
        
    int height = DisplayHeight(display, screen)/2;

        Window win 
    = XCreateSimpleWindow(display, RootWindow(display, screen),
            
    00, width, height, 3, BlackPixel(display, screen), WhitePixel(display, screen));

        XSelectInput(display, win, ExposureMask
    |KeyPressMask | ButtonPressMask | StructureNotifyMask);

        GC gc 
    = XCreateGC(display, win, 0, NULL);

        XMapWindow(display, win);

        
    while(1)
        
    {
            XEvent 
    event = {0};
            XNextEvent(display, 
    &event);
            
    switch(event.type)
            
    {
                
    case ConfigureNotify:
                
    {
                    width 
    = event.xconfigure.width;
                    height 
    = event.xconfigure.height;
                    
    break;
                }

                
    case Expose:
                
    {
                    XSetForeground(display, gc, WhitePixel(display, screen));
                    XFillRectangle(display, win, gc, 
    00, width, height);
                   XSetForeground(display, gc, BlackPixel(display, screen));
                    XDrawString(display, win, gc, width
    /2, height/2"XWindow"7);
                    
    break;
                }

                
    case KeyPress:
                
    {
                    
    if(event.xkey.keycode == XKeysymToKeycode(display, XK_Escape))
                    
    {
                        XFreeGC(display, gc);
                        XCloseDisplay(display);
                        
    return 0;
                    }

                }

                
    default:break;
            }

        }


        
    return 0;
    }

       

     Makefile
    all:
        gcc 
    --lX11 xdemo.-o xdemo
    clean
    :
        rm 
    -f xdemo

    (我并不擅长X Window编程,请不要问我关于X Window编程的问题。)

    ~~end~~
  • 相关阅读:
    WHERE col1=val1 AND col2=val2;index exists on col1 and col2, the appropriate rows can be fetched directly
    MySQL 交集 实现方法
    MBProgressHUD的使用
    Xcode4 使用 Organizer 分析 Crash logs(转)
    SimpleXML 使用详细例子
    PHP的XML Parser(转)
    iPhone,iPhone4,iPad程序启动画面的总结 (转)
    Pop3得到的Email 信件格式介绍
    yii总结
    隐藏Tabbar的一些方法
  • 原文地址:https://www.cnblogs.com/zhangyunlin/p/6167665.html
Copyright © 2011-2022 走看看