| 6. |
1 /* 2 * Filename : hello.c 3 * Begin : 2008-05-09 16:24:44 4 * Project : Hello Nano-X World 5 * Version : 1.0 6 * Copyright : GPL v2.0 7 * Author : Wu Yin 8 * Description : 9 ************************************************************************** 10 #include <stdio.h> 11 #include "nano-X.h" 12 #include "nxcolors.h" 13 14 int main() 15 { 16 GR_WINDOW_ID root_wid, wid; 17 GR_GC_ID gc; 18 GR_COORD x, y; 19 GR_SIZE width, height; 20 GR_EVENT event; 21 22 x = 0; 23 y = 0; 24 width = 640; 25 height = 480; 26 27 if (GrOpen() < 0) 28 { 29 printf("Can't open graphics\n"); 30 return 0; 31 } 32 33 gc = GrNewGC(); 34 // 创建父窗口(根窗口) 35 root_wid = GrNewWindow(GR_ROOT_WINDOW_ID, x, y, width, height, 36 1, GR_COLOR_ROYALBLUE, GR_COLOR_BLACK); 37 // 创建一个子窗口 38 wid = GrNewWindow(root_wid, 60, 60, 200, 60, 1, GR_COLOR_BLACK, GR_COLOR_WHITE); 39 GrMapWindow(root_wid); // 绘制父窗口 40 GrMapWindow(wid); // 绘制子窗口 41 42 // 显示在父窗口中的文字 43 GrSetGCForeground(gc, GR_COLOR_RED); // 前景色(字体颜色) 44 GrSetGCBackground(gc, GR_COLOR_GREEN); // 背景色(字体背景颜色) 45 GrText(root_wid, gc, 10, 20, "Hello in root_wid", -1, GR_TFBOTTOM); 46 47 // 显示在子窗口中的文字 48 GrSetGCForeground(gc, GR_COLOR_RED); // 前景色(字体颜色) 49 GrSetGCBackground(gc, GR_COLOR_GREEN); // 背景色(字体背景颜色) 50 GrText(wid, gc, 10, 20, "Hello in wid", -1, GR_TFBOTTOM); 51 52 for (;;) 53 { 54 GrGetNextEvent(&event); 55 } 56 GrClose(); 57 58 return 1; 59 } 60
|