#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "pthread.h"
#if UNIX | DOS_DJGPP
#endif
#define MWINCLUDECOLORS
#include "nano-X.h"
#define WIDTH 320
#define HEIGHT 215
#define bkpic "./image/top18.bmp" //这是PDA 桌面背景图片。
/*主要全局变量*****************************************************/
static GR_WINDOW_ID window; //
static GR_WINDOW_ID bt1,bt2,bt3;
static GR_WINDOW_ID smb[10]; //menu 开始菜单最大为十个选择项。
static GR_WINDOW_ID scb[10]; //shortCut 快捷键最大也为十项。
static GR_GC_ID gc;
static GR_GC_ID gcfn;
static GR_FONT_ID fontid;
static GR_IMAGE_ID picID; //put background's image
static GR_IMAGE_ID icon[10]; //put icon's image
static GR_IMAGE_INFO picIF; //image information of background
static GR_IMAGE_INFO iconIF[10]; //image information of icon
struct DATE_TIME //该结构用于记录系统时间,并分解为日期,时,分,秒。
{
char year[10];
char mon[10];
char day[10];
char hour[10];
char min[10];
char sec[10];
char week[10];
char date[50];
char dateTime[50];
};
char *fileName[10]={"退 出","记事本","名片","通讯录","画板","游戏","闹钟","音乐
","file8","file9"}; //开始菜单各项。
char
*picfile[10]={"./image/book10s.gif","./image/earth6s.gif","./image/note39s.gif
","./image/hbs.gif","","
","","","",""};//桌面快捷键使用图片。
struct DATE_TIME datetime;
static int ret;
/*调用的子函数***************************************************/
void drawMainWin(GR_GC_ID gc);
void drawBar(GR_GC_ID gc);
void loadImage(GR_IMAGE_ID picID,GR_IMAGE_INFO picIF,char *picfile);
void setBackGround();
void* doTime(void* data);
void doStartMenu(int fileNnum,GR_GC_ID gc);
void doShortCut(char *fileName,int fileNum,GR_GC_ID gc,int x,int y,GR_IMAGE_ID
icon,GR_IMAGE_INFO iconIF);
void doEventButtonDown(GR_EVENT_BUTTON *bevent,GR_GC_ID gc);
void doEventButtonUp(GR_EVENT_BUTTON *bevent);
void doEventMouseExit(GR_EVENT_MOUSE *mevent,GR_GC_ID gc);
void doEventMouseEnter(GR_EVENT_MOUSE *mevent,GR_GC_ID gc);
void highLightStartMenu(int i);
/**********************************************************/
int main(int ac, char **av)
{
//void * retval;
int i;
pthread_t th_com; //为时钟显示开启一个独立线程。
if (GrOpen() < 0)
exit(1);
gc = GrNewGC();
gcfn=GrNewGC();
GrSetGCBackground(gc, WHITE);
GrSetGCForeground(gc, 255);
GrSetGCUseBackground(gcfn, GR_FALSE);
GrSetGCBackground(gcfn, BLACK);
GrSetGCForeground(gcfn, 255);
fontid = GrCreateFont("HZKFONT", 0, NULL);
GrSetFontSize(fontid, 16);
GrSetFontRotation(fontid, 330); // 33 degrees
GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0);
GrSetGCFont(gcfn, fontid);
//loadImage(picID,picIF,bkpic)用于加载图形文件。
if(!(picID = GrLoadImageFromFile(bkpic, 0)))
{
fprintf(stderr, "Failed to load image file "%s"\n", bkpic);
}
GrGetImageInfo(picID, &picIF);
for(i=0;i<4;i++)
{
if(!(icon[i] = GrLoadImageFromFile(picfile[i], 0)))
//从已经定义的桌面快捷键图片集中为桌面快捷键图标选择图片。
{
fprintf(stderr, "Failed to load image file "%s"\n", picfile[i]);
}
GrGetImageInfo(icon[i], &iconIF[i]);
}
drawMainWin(gc); //绘制主窗口。
drawBar(gcfn); //绘制任务栏。
setBackGround(); //绘制桌面背景。
pthread_create(&th_com, NULL, doTime, 0); //创建线程。
//pthread_join(th_com, &retval);
while (1)
{
//doTime(gc);
GR_EVENT event;
GrCheckNextEvent(&event);
switch(event.type)
{
case GR_EVENT_TYPE_CLOSE_REQ:
GrClose();
exit(0);
case GR_EVENT_TYPE_BUTTON_DOWN:
doEventButtonDown(&event.button,gcfn);
break;
case GR_EVENT_TYPE_BUTTON_UP:
doEventButtonUp(&event.button);
break;
case GR_EVENT_TYPE_MOUSE_ENTER:
doEventMouseEnter(&event.mouse,gcfn);
break;
case GR_EVENT_TYPE_MOUSE_EXIT:
doEventMouseExit(&event.mouse,gcfn);
break;
//case GR_EVENT_TYPE_TIMEOUT:
}
//GrDestroyFont(fontid);
}
GrFlush();
GrDestroyFont(fontid);
GrDestroyGC(gcfn);
GrDestroyGC(gc);
GrClose();
return 0;
}
/***********************************************************************/
void drawMainWin(GR_GC_ID gc) //该函数绘制主窗口。
{
window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, WIDTH,
HEIGHT-2,1,BLACK,BLUE);
GrSelectEvents(window,
GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ |
GR_EVENT_MASK_BUTTON_DOWN |
GR_EVENT_MASK_BUTTON_UP |
GR_EVENT_MASK_MOUSE_ENTER |
GR_EVENT_MASK_MOUSE_EXIT);
GrMapWindow(window);
//GrFreeImage(picID);
//GrDestroyWindow(window);
}
/***********************************************************************/
void drawBar(GR_GC_ID gc) //绘制类似Windows 下任务栏的菜单。
{
bt1=GrNewWindow(GR_ROOT_WINDOW_ID,0,215,70,23,2,GREEN,BLUE);
bt2=GrNewWindow(GR_ROOT_WINDOW_ID,70,215,180,23,2,GREEN,BLUE);
bt3=GrNewWindow(GR_ROOT_WINDOW_ID,250,215,70,23,2,GREEN,BLUE);
GrSelectEvents(bt1,GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_BUTTON_DOWN);
GrSelectEvents(bt2,GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_BUTTON_DOWN);
GrSelectEvents(bt3,GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_BUTTON_DOWN);
GrMapWindow(bt1);
GrMapWindow(bt2);
GrMapWindow(bt3);
GrSetGCForeground(gc, WHITE);
GrSetGCUseBackground(gc, GR_FALSE);
GrSetGCFont(gc, fontid);
GrText(bt1, gc, 13, 15,
"开始", -1, GR_TFASCII);
GrText(bt2, gc,1, 15,
"博创科技PDAwww.up-tech.com", -1, GR_TFASCII);
}
/*********************************************************************/
void setBackGround() //绘制桌面背景,新的桌面快捷键也在该子函数中添加。
{
GrDrawImageToFit(window, gc, 0, 0, picIF.width, picIF.height, picID);
doShortCut(fileName[1],0,gcfn,20,20,icon[0],iconIF[0]);
doShortCut(fileName[2],1,gcfn,20,80,icon[1],iconIF[1]);
doShortCut(fileName[3],2,gcfn,20,140,icon[2],iconIF[2]);
doShortCut(fileName[4],3,gcfn,80,20,icon[3],iconIF[3]);
}
/*******************************************************************/
void loadImage(GR_IMAGE_ID picID, GR_IMAGE_INFO picIF, char *picfile)
//加载图片
{
GR_IMAGE_ID pic_ID;
GR_IMAGE_INFO pic_IF;
if(!(picID = GrLoadImageFromFile(picfile, 0)))
{
fprintf(stderr, "Failed to load image file "%s"\n", picfile);
}
GrGetImageInfo(picID, &picIF);
picID=pic_ID;
picIF=pic_IF;
}
/******************************************************************/
void doStartMenu(int fileNum,GR_GC_ID gc) //绘制开始菜单
{
int i;
char* startMenuFileName[fileNum+1];
int smbW,smbH;
smbW=100; smbH=20;
GrSetGCForeground(gc, MWRGB(255,0,0));
GrSetGCUseBackground(gc, GR_FALSE);
GrSetGCFont(gc, fontid);
for(i=0;i<fileNum;i++)
{
smb[i]=GrNewWindow(GR_ROOT_WINDOW_ID,1,192-i*smbH,smbW,smbH,2,GREEN,
BLUE);
GrSelectEvents(smb[i],GR_EVENT_MASK_EXPOSURE |
GR_EVENT_MASK_BUTTON_DOWN |
GR_EVENT_MASK_MOUSE_ENTER |
GR_EVENT_MASK_MOUSE_EXIT);
GrMapWindow(smb[i]);
startMenuFileName[i]=fileName[i];
GrText(smb[i],gc,13,15,startMenuFileName[i],-1,GR_FALSE);
}
}
/*************************************************************************
/
void doEventMouseEnter(GR_EVENT_MOUSE *mevent,GR_GC_ID gc)
//响应鼠标光标进入事件。
{
GrSetGCFont(gc, fontid);
GrSetGCForeground(gc, YELLOW);
if(mevent->wid==smb[0])
{
GrText(smb[0],gc,13,15,fileName[0],-1,GR_FALSE);
}
if(mevent->wid==smb[1])
{
GrText(smb[1],gc,13,15,fileName[1],-1,GR_FALSE);
}
if(mevent->wid==smb[2])
{
GrText(smb[2],gc,13,15,fileName[2],-1,GR_FALSE);
}
if(mevent->wid==smb[3])
{
GrText(smb[3],gc,13,15,fileName[3],-1,GR_FALSE);
}
if(mevent->wid==smb[4])
{
GrText(smb[4],gc,13,15,fileName[4],-1,GR_FALSE);
}
if(mevent->wid==smb[5])
{
GrText(smb[5],gc,13,15,fileName[5],-1,GR_FALSE);
}
if(mevent->wid==smb[6])
{
GrText(smb[6],gc,13,15,fileName[6],-1,GR_FALSE);
}
if(mevent->wid==smb[7])
{
GrText(smb[7],gc,13,15,fileName[7],-1,GR_FALSE);
}
}
/************************************************************************/
void doEventMouseExit(GR_EVENT_MOUSE *mevent,GR_GC_ID gc)
//响应鼠标光标离开事件。
{
GrSetGCFont