|

楼主 |
发表于 2015-9-2 10:02:29
|
显示全部楼层
#include <stdlib.h>
#include "GUI.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
static time_t realtime;
struct tm *timeInfo;
typedef struct _DATE_TIME
{
int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
int nwDay;
int nyDay;
int nisdst;
}SELF_TIME;
SELF_TIME selfTime;
char *weekDay[7]=
{
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe6\\x97\\xa5",//sunday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe4\\xb8\\x80",//monday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe4\\xba\\x8c",//tuesday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe4\\xb8\\x89",//wednesday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe5\\x9b\\x9b",//thursday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe4\\xba\\x94",//friday
"\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe5\\x85\\xad",//saturday
};
static const GUI_WIDGET_CREATE_INFO _aDialogCreateTime[] = {
{ WINDOW_CreateIndirect, "Time", 0, 1, 1, 798, 70, FRAMEWIN_CF_MOVEABLE },
{ TEXT_CreateIndirect, "2015-08-28", GUI_ID_TEXT0, 20, 15, 250, 30 ,TEXT_CF_LEFT },
{ TEXT_CreateIndirect, "\\xe6\\x98\\x9f\\xe6\\x9c\\x9f\\xe4\\xba\\x8c", GUI_ID_TEXT1, 30, 45, 80, 30, TEXT_CF_LEFT },
{ TEXT_CreateIndirect, "10:30:40", GUI_ID_TEXT2, 300, 40, 300, 40, TEXT_CF_LEFT }
};
static void _ChangeFrameClientText(FRAMEWIN_Handle hObj)
{
WM_MESSAGE Message;
Message.MsgId=MSG_CHANGE_MAIN_TEXT;
WM_SendMessage(hObj,&Message);
}
static void _cbDialogTime(WM_MESSAGE * pMsg)
{
WM_HWIN hDlg, hItem;
char strDate[12]={0};
char strTime[12]={0};
char strWeek[10]={0};
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case MSG_CHANGE_MAIN_TEXT:
selfTime.nYear = timeInfo->tm_year+1900;
selfTime.nMonth= timeInfo->tm_mon+1;
selfTime.nDay= timeInfo->tm_mday;
selfTime.nHour= timeInfo->tm_hour;
selfTime.nMinute= timeInfo->tm_min;
selfTime.nSecond= timeInfo->tm_sec;
selfTime.nwDay= timeInfo->tm_wday;
sprintf(strDate,"%04d-%02d-%02d",selfTime.nYear,selfTime.nMonth,selfTime.nDay);
sprintf(strTime,"%02d:%02d:%02d",selfTime.nHour,selfTime.nMinute,selfTime.nSecond);
sprintf(strWeek,"%s",weekDay[selfTime.nwDay]);
//日期
hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
TEXT_SetFont(hItem, &GUI_Fontfangsong24);
TEXT_SetText(hItem,strDate);
//星期
hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT1);
TEXT_SetFont(hItem, &GUI_Fontfangsong24);
TEXT_SetText(hItem,strWeek);
//时间
hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT2);
TEXT_SetFont(hItem, &GUI_Fontyouyuanshuzi36);
TEXT_SetText(hItem,strTime);
break;
case WM_PAINT:
break;
default:
WM_DefaultProc(pMsg);
}
}
void MainTask(void)
{
WM_HWIN hFrameWin;
WM_HWIN hDialogTime;
int msOldtime=0;
int msCurtime=0;
GUI_Init();
GUI_UC_SetEncodeUTF8();
……
hFrameWin = FRAMEWIN_Create("FrameWindow", _cbFrameWin, WM_CF_SHOW, FRAME_X, FRAME_Y, FRAME_XSIZE, FRAME_YSIZE);
……
time(&realtime);
timeInfo = localtime(&realtime);
hDialogTime = GUI_CreateDialogBox(_aDialogCreateTime, GUI_COUNTOF(_aDialogCreateTime), _cbDialogTime, hFrameWin, 1, 30);
……
msOldtime = GUI_GetTime();
while (1)
{
msCurtime = GUI_GetTime();
if(msCurtime - msOldtime>=1000 )//每秒刷新时间
{
msOldtime = msCurtime;
time(&realtime);
timeInfo = localtime(&realtime);
_ChangeFrameClientText(hDialogTime);
}
GUI_Exec();
} |
|