某储备粮的“学习笔记” - 2011年5月 http://blog.gregwym.info/2011/05/ by 咳嗽di小鱼 Virtualbox - 主机与虚拟机之间共享文件夹 http://blog.gregwym.info/virtualbox---zhu-ji-yu-xu-ni-ji-zhi-jian-gong-xiang-wen-jian-jia.html 2011-05-16T04:13:28+08:00 此文章特指Windows主机, Linux虚拟机环境.前提是需要在Linux中安装Virtualbox的虚拟机工具.Step1:在设备属性中设置"分配数据空间", "数据空间位置" - 主机上需要分享的文件夹位置 "数据空间名称" - 共享资源显示的名字, 不需要和原文件夹同名, 但不能包含空格. 最好为英文 "只读分配" - 顾名思义 "Auto-mount" - 测试没成功, 不推荐选择, 可以手动在虚拟机中设置 "固定分配" - 是否给该虚拟机永久分配此数据空间 Step2:启动虚拟机, 打开Terminalsudo mkdir /mnt/share sudo mount -t vboxsf <数据空间名称> /mnt/share 之后就可以在/mnt/share里访问主机的文件了注: /mnt/是Ubuntu的默认mount目录, 并不是所有Linux都是如此, 请自行注意Step3:卸载这个数据空间, 你可以选择重启, 或者使用以下命令sudo umount -f /mnt/shared Step4:如果需要每次打开虚拟机的时候都自动加载这个, 可以编辑/etc/fstabsudo vim /etc/fstab # 添加如下一行内容 <数据空间名称> /mnt/share vboxsf rw,gid=100,uid=1000,auto 0 0 XLib初接触 http://blog.gregwym.info/xlib-chu-jie-chu.html 2011-05-15T04:24:52+08:00 XLib是X Window编程的基础Library, 使用时首先需要在文件头中#include <X11/Xlib.h> 在绘制图形界面之前, 第一步要连接到一个Display. 就好比画画之前先要找到一张桌子或者画板, 你不能举着一张纸直接就往上泼墨...// Open display Display* display; display = XOpenDisplay(""); if(!display){ printf("Cannot open display\n"); exit(-1); } 之后可以通过一些函数, 获取当前Display的各种信息. 如需要, 可以保存到variable里供后边绘图时候使用.int printScreenInfo(Display* display){ int screen_num; // 当前屏幕的编号 int screen_width; // 当前屏幕的宽度 int screen_height; // 当前屏幕的高度 Window root_window; // root窗口的编号 unsigned long white_pixel; // 白色像素的编号 unsigned long black_pixel; // 黑色像素的编号 screen_num = DefaultScreen(display); screen_width = DisplayWidth(display, screen_num); screen_height = DisplayHeight(display, screen_num); root_window = RootWindow(display, screen_num); white_pixel = WhitePixel(display, screen_num); black_pixel = BlackPixel(display, screen_num); printf("Screen Number: \t%d\n Width: \t%d\n Height: \t%d\n Root: \t%d\n White: \t%d\n Black: \t%d\n", screen_num, screen_width, screen_height, root_window, white_pixel, black_pixel); return 0; } 画板摆好以后, 就要在上边铺上一张用来画画的纸, 也就是一个窗口...// Define window properties Window window; int x, y; unsigned int width, height, border_width; width = 850; height = 470; x = y = 50; border_width = 0; // Define display constants int screen_num = DefaultScreen(display); unsigned long white_pixel = WhitePixel(display, screen_num); unsigned long black_pixel = BlackPixel(display, screen_num); // Create window window = XCreateSimpleWindow(display, RootWindow(display, screen_num), x, y, width, height, border_width, black_pixel, white_pixel); // Map win to display & Flush display XMapWindow(display, win); XFlush(display); 万事俱备只欠画画儿了`XLib的function都挺容易看懂的...int drawInterface(Display* display, Window window, unsigned long black_pixel, unsigned long white_pixel ){ // Define GCs for drawing GC foregc; foregc = XCreateGC (display, window, 0, 0); XSetBackground( display, foregc, black_pixel ); XSetForeground( display, foregc, white_pixel ); // Start Drawing XClearWindow(display, window); // Door XDrawRectangle(display, window, foregc, 1, 1, 630, 460); XFillRectangle(display, window, foregc, 66, 66, 480, 330); // Dashboard XDrawRectangle(display, window, foregc, 633, 1, 215, 460); XDrawRectangle(display, window, foregc, 650, 45, 185, 330); // Timer XDrawRectangle(display, window, foregc, 660, 60, 160, 65); // And More... // Flush display to show everything changed XFlush(display); } Event Handling的部分晚点再整理