Write "Hello World" in Microwindows (nano-x"

Source: Internet
Author: User

Write "Hello World" in Microwindows (nano-x"

By: Wu Yin
Date: 2008-05-09
Homepage: Http://blog.csdn.net/wooin
Email: Lazy. Fox. Wu # gmail.com
Copyright: This article is copyrighted by Wu Yin and his lovely wife. It can be freely transmitted and replicated for non-commercial purposes. For commercial purposes, any behavior in this article shall be approved by the author.
Link: Http://blog.csdn.net/wooin/archive/2008/05/14/2446721.aspx
1. Microwindows, also known as nano-X, is a lightweight GUI system. Because it is open-source and free, and supports Chinese, it is often used in embedded devices that need to display graphical interfaces. I will not talk about the Introduction to Microsoft Windows, and many can be found on Google. This article mainly introduces how to download a Microwindows program from the Internet, compile it, and then write your own "Hello World" program using microwindos. Note: This section only describes Microwindows running on a PC, rather than cross-compiling embedded environments.

Here (www.microwindows.org) is the official website of Microwindows, which has not been updated for many years, but the application of Microwindows has not weakened.

2. Next we will start today's work (My Linux release version is fedora 5), first download a Microwindows source code package from the website, we use version 0.90, the downloaded file is Microwindows-0.90.tar.gz.
Decompress the package with the following command and enter the source code directory:
$ Tar-xzvf microwindows-0.90.tar.gz
$ CD microwindows-0.90/src
3. Modify several files:
File arch. Rules
21 rows:
Compiler = gcc
Change
Compiler = gcc32

Because the default GCC version of Fedora 5 is 4.1.0, the syntax check is too strict, and Microwindows compilation will fail. If the default GCC version on your release is also 4. for Version X, replace it with 3. in Version X, replace the above "gcc32" with your GCC on Linux 3. the name of Version X. If not, you may have to install it on your own.
Use GCC 4. X cannot be compiled, but because the Microwindows code is too old to be compatible with the new compiler, compilation may produce some errors. You can modify the source code according to the error prompt or compile the code, it is a little troublesome. I will not detail it here.

Row 3:
Link_app_into_server = N
Change
Link_app_into_server = y

Modify the config file
Row 3:
Have_cmd_support = y
Change
Have_cmd_support = N
Because my computer does not have the/usr/lib/libjpeg. A file, compilation will fail. If you have this file,
You can try not to modify the above line to see if it can be compiled.
This allows Microwindows to support JPEG files.
Row 3:
X11 = N
Change
X11 = y
Modify this configuration so that Microsoft Windows uses the X11 mouse and keyboard driver
4. Compile Microwindows:
Run the make command in the microwindows-0.90/src directory for compilation:
$ Make

If there is no accident, the compilation will be successful. If there is still an error, it may be that the file is missing in your Linux environment. You can modify the config file according to the error message.

Run the demo program in the bin directory to check whether the compilation is successful. The mine program is a mine clearance game that comes with Microsoft Windows, which is the same as that in windows. Run the following command:

$ CD Bin
$./Mine

If you can see the game interface in, it indicates that you have compiled it. Congratulations !!

5. Write your own "Hello World" program and create a "Projects" folder under the src directory
$ Mkdir Projects
$ CD Projects
Then write our program in it. The "Hello. c" source program and "makefile" are listed below"
6.
1 /************************************** *************************************
2 * filename: Hello. c
3 * begin: 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
14IntMain ()
15 {
16Gr_window_idRoot_wid, WID;
17Gr_gc_idGC;
18Gr_coordX, Y;
19Gr_sizeWidth, height;
20Gr_eventEvent;
21
22 x = 0;
23 y = 0;
24 width = 640;
25 Height = 480;
26
27If(Gropen () <0)
28 {
29 printf ("can't open graphics/N ");
30Return0;
31}
32
33 GC = grnewgc ();
34 // create a parent window (root window)
35 root_wid = grnewwindow (gr_root_window_id, X, Y, width, height,
36 1, gr_color_royalblue, gr_color_black );
37 // create a subwindow
38 WID = grnewwindow (root_wid, 60, 60,200, 60, 1, gr_color_black, gr_color_white );
39 grmapwindow (root_wid); // draw the parent window
40 grmapwindow (WID); // draw a subwindow
41
42 // text displayed in the parent window
43 grsetgcforeground (GC, gr_color_red); // foreground color (font color)
44 grsetgcbackground (GC, gr_color_green); // background color (font background color)
45 grtext (root_wid, GC, 10, 20, "hello in root_wid",-1, gr_tfbottom );
46
47 // text displayed in the subwindow
48 grsetgcforeground (GC, gr_color_red); // foreground color (font color)
49 grsetgcbackground (GC, gr_color_green); // background color (font background color)
50 grtext (WID, GC, 10, 20, "hello in wid",-1, gr_tfbottom );
51
52For(;;)
53 {
54 grgetnextevent (& event );
55}
56 grclose ();
57
58Return1;
59}
60
7.
 1 ##############################################################################
2 # Makefile
3 ##############################################################################
4 ifndef TOP
5 TOP = ..
6 CONFIG = $(TOP)/config
7 endif
8
9 include $(CONFIG)
10
11 ############################# targets section ################################
12 # If you want to create a library with the objects files, define the name here
13 OBJS = hello.o
14 TARGETS = hello
15
16 all: default $(TARGETS)
17
18 ######################### Makefile.rules section #############################
19 include $(TOP)/Makefile.rules
20
21 ifeq ($(SHAREDLIBS), Y)
22 LD_NANOXCLIENTLIBS = $(CCNANOXCLIENTLIBS)
23 else
24 LD_NANOXCLIENTLIBS = $(NANOXCLIENTLIBS)
25 endif
26
27 ######################## Tools targets section ###############################
28 $(TARGETS): $(OBJS) $(NANOXCLIENTLIBS) $(TOP)/config
29 $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LD_NANOXCLIENTLIBS)
30 clr:
31 rm -f *.o *~ .depend $(TARGETS)
8. Create the above two source files in your projects folder, and then run the make command to compile it. If there is no accident, a "hello" executable file should be generated in the projects folder, run it to view the following interface:
9. The rest is to write your own program. ^_^
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.