microwindows Win32 API demo

初次使用microwindows,资料有限,我也是费了很多功夫才明白.所以记录下来,好帮助那些爱学习的童鞋,另外请大虾们多多指教.

什么是microwindows,什么作用,等背景介绍我就不多说了,因为你准备写代码之前,一定研究过了.

下面直接进入主题,如何把源文件编译成lib,写自己的代码,make自己代码,运行等.

环境及版本说明:

Ubuntu 11.04

microwindows-0.92

如何编译源文件:

1- 从网站下载源文件

ftp://microwindows.org/pub/microwindows/microwindows-full-0.92.tar.gz

tar zxvf microwindows-full-0.92.tar.gz
cd microwindows-0.92/src

有3个文件

README  //打开文件第一句就说明 "To build Nano-X/Microwindows, see src/INSTALL and src/CONTENTS." 说明很重要,想要编译通过,一定要详细读.

doc     // 相关文档

src     //源文件

cd src
./xconfigure

环境,编译变量配置.

开始编译源文件:

make

如果编译报错,其主要原因一定是缺少lib库,请查看 src/INSTALL文件,其中包含

2. Edit the default configuration file "config", if desired.
There are pre-built configuration files for X11, framebuffer,
and a variety of target systems, see Configs/README.

The default configuration is for framebuffer (Configs/config.fb2)
Type "cp Configs/config.x11 config" for the X11 configuration.

See CONTENTS and Configs/README for more information.

根据提示读src/CONTENTS文件,其中包含

EXTERNAL REQUIRED LIBRARIES (when configured to use them, latest tested version)
freetype-2.3.9.tar.gz libfreetype.so - freetype 2 font engine
freetype-1.3.1.tar.gz libttf.so - freetype 1 font engine
jpegsrc.v6b.tar.gz libjpeg.a - JPEG image library
png-1.2.37.tar.gz libpng.a - PNG image library
zlib-1.2.3.3.tar.gz libz.a - compression lib for loadable pcf.gz fonts/png files
t1lib-5.1.2.tar.gz libt1.a - T1 font engine (requires T1LIB_CONFIG=microwin/src/fonts/t1lib/config.t1lib)

以上lib库最好都安装,或者选择自己需要的安装,配合上面./xconfigure的配置

编译通过之后,试运行源文件自带的demo 

cd bin
./mtest2

 

如何写自己代码

我一直在看源文件自带的.src/demos/mwin的代码,由于win32函数参数很多,而且事件驱动开发,导致看完也很渺茫,如何写呢.所以建议初学者先翻阅下此书forgers-win32-tutorial_zh_CN.pdf,找了很多这本入门还不错,很清晰.

Demo功能说明:

用户登录窗口,输入用户名,密码.与文件中存储内容校验,如果相等,则提示"登录成功",否则提示"是否需要新建用户",点击"否"退出messageBox,点击"是"新建用户.内容追加写入文件.

开始写代码:

cd demos/mwin/
vi login_main.c

代码就不在这里体现了,可直接访问:

https://github.com/galoishelley/microwindows 

userinfo.pwd 文件格式为: userName|userPwd  eg: testlogin|abc123

其实microwindows win32API 就是windows 下得API.

如何编译自己代码

开始修改原代码中自带的Makefile

由于程序在/microwindows-0.92/src/demos/mwin目录,所以修改此目录的Makefile文件

修改Makefile文件很简单,不用都看懂,找程序自带的例子mtest2如何写的,你照搬就好.

ifeq ($(ARCH), PSP)

DEMOS = $(MW_DIR_BIN)/mdemo $(MW_DIR_BIN)/malpha $(MW_DIR_BIN)/mtest $(MW_DIR_BIN)/mtest2 $(MW_DIR_BIN)/mine else DEMOS = $(MW_DIR_BIN)/mdemo $(MW_DIR_BIN)/malpha $(MW_DIR_BIN)/mtest $(MW_DIR_BIN)/mtest2 $(MW_DIR_BIN)/mine $(MW_DIR_BIN)/login_main

修改完Makefile可以编译了

cd /microwindows-0.92/src
make

 如果不成功,也是自己写的程序问题,可以调试.

如何运行自己写的代码

cd /microwindows-0.92/src/bin
./login_main

 由于microwindows win32API支持的控件特别少,所以MessageBox都是自己实现的.代码中为MessageBoxC

MessageBox

参考资料:

http://microwindows.org/

read-only access to git repository: 

git clone https://github.com/galoishelley/microwindows 
原文地址:https://www.cnblogs.com/galoishelley/p/3413964.html