189 lines
5.0 KiB
C
189 lines
5.0 KiB
C
//这段程序是一个时钟
|
|
//
|
|
//
|
|
#include "stdint.h"
|
|
#include "stddef.h"
|
|
#include "stdio.h"
|
|
#include "gdd.h"
|
|
#include "gdd_button.h"
|
|
#include "wjh_window.h"
|
|
#include "wjh_ClockControl.h"
|
|
#include "wjh_Clock.h"
|
|
|
|
// 用于存放按钮hwnd
|
|
HWND timeclock[8];
|
|
HWND clock_window = NULL;
|
|
//定义按钮名字
|
|
u8 buttontime[8][20] = {"hour1", "hour2", "colon1", "minute1", "minute2", "colon2", "second1", "second2"};
|
|
//图片名称,不可更改
|
|
u8 timename[10][20] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
|
|
//初始化时间
|
|
u32 hour_t = 0;
|
|
u32 minute_t = 59;
|
|
u32 second_t = 50;
|
|
|
|
u32 C_flag = 0;
|
|
struct WinTimer* c_timer;
|
|
enum {
|
|
C_Clock,
|
|
C_Timer,
|
|
};
|
|
static bool_t main_window_paint(struct WindowMsg *pMsg) {
|
|
HWND hwnd = pMsg->hwnd;
|
|
if (hwnd == NULL) return false;
|
|
|
|
HDC hdc = GDD_BeginPaint(hwnd);
|
|
|
|
GDD_SetBackGroundColor(hdc, RGB(8,24,58));
|
|
GDD_CleanClient(hdc);
|
|
|
|
GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新
|
|
|
|
return true;
|
|
}
|
|
static bool_t button_paint(struct WindowMsg *pMsg) {
|
|
u8* data;
|
|
HWND hwnd;
|
|
HDC hdc;
|
|
if(pMsg==NULL)
|
|
return false;
|
|
hwnd = pMsg -> hwnd;
|
|
if(hwnd ==NULL) return false;
|
|
hdc = GDD_BeginPaint(hwnd);
|
|
// struct RopGroup ropgroup = GDD_GetRopCode(hdc);
|
|
// ropgroup.HyalineEn = 1;
|
|
// GDD_SetRopCode(hwnd, ropgroup);
|
|
// GDD_SetWindowHyalineColor(hwnd, RGB(8,24,58));
|
|
// Set the background image for the window
|
|
wjh_setBackBmp(hwnd, wjh_Search_ClockBMP("colon"));
|
|
|
|
GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新
|
|
|
|
return true;
|
|
}
|
|
|
|
static bool_t timer_paint(struct WindowMsg *pMsg) {
|
|
u8* data;
|
|
HWND hwnd;
|
|
HDC hdc;
|
|
if(pMsg==NULL)
|
|
return false;
|
|
hwnd = pMsg -> hwnd;
|
|
if(hwnd ==NULL) return false;
|
|
hdc = GDD_BeginPaint(hwnd);
|
|
//根据时间调整图片
|
|
wjh_setBackBmp(timeclock[0], wjh_Search_ClockBMP(timename[hour_t/10]));
|
|
wjh_setBackBmp(timeclock[1], wjh_Search_ClockBMP(timename[hour_t%10]));
|
|
wjh_setBackBmp(timeclock[3], wjh_Search_ClockBMP(timename[minute_t/10]));
|
|
wjh_setBackBmp(timeclock[4], wjh_Search_ClockBMP(timename[minute_t%10]));
|
|
wjh_setBackBmp(timeclock[6], wjh_Search_ClockBMP(timename[second_t/10]));
|
|
wjh_setBackBmp(timeclock[7], wjh_Search_ClockBMP(timename[second_t%10]));
|
|
if(C_flag == C_Clock){
|
|
second_t = second_t + 1;
|
|
if(second_t==60){
|
|
second_t = 0;
|
|
minute_t = minute_t + 1;
|
|
}
|
|
if(minute_t==60){
|
|
minute_t = 0;
|
|
hour_t = hour_t + 1;
|
|
}
|
|
if(hour_t==24){
|
|
hour_t = 0;
|
|
}
|
|
}else if(C_flag == C_Timer){
|
|
if(second_t==0&&minute_t == 0&&hour_t==0){
|
|
GDD_StopTimer(c_timer);
|
|
}
|
|
if(second_t==0&&!(minute_t == 0&&hour_t == 0)){
|
|
second_t = 60;
|
|
if(minute_t == 0 && hour_t != 0){
|
|
minute_t = 60;
|
|
hour_t -= 1;
|
|
}
|
|
minute_t -= 1;
|
|
|
|
}
|
|
second_t -= 1;
|
|
|
|
}
|
|
|
|
|
|
GDD_EndPaint(hwnd, hdc); // 结束绘制并刷新
|
|
|
|
return true;
|
|
}
|
|
void create_TimerControl(){
|
|
if(clock_window!=NULL){
|
|
hour_t = 1;
|
|
minute_t = 1;
|
|
second_t = 0;
|
|
C_flag = C_Timer;
|
|
GDD_PostMessage(clock_window, MSG_TIMER, 0, NULL);
|
|
}
|
|
}
|
|
|
|
void start_timer(){
|
|
if(clock_window!=NULL)
|
|
GDD_StartTimer(c_timer);
|
|
|
|
}
|
|
void pause_timer(){
|
|
if(clock_window!=NULL)
|
|
GDD_StopTimer(c_timer);
|
|
|
|
}
|
|
void Del_ClockControl(){
|
|
if(clock_window!=NULL){
|
|
GDD_DestroyWindow(clock_window);
|
|
clock_window = NULL;
|
|
u32 hour_t = 0;
|
|
u32 minute_t = 59;
|
|
u32 second_t = 50;
|
|
}
|
|
}
|
|
void correct_ClockControl(){
|
|
hour_t = 0;
|
|
minute_t = 59;
|
|
second_t = 50;
|
|
GDD_StartTimer(c_timer);
|
|
|
|
}
|
|
|
|
// Main function
|
|
HWND wjh_GetClockControl(HWND hwnd, u32 x, u32 y)
|
|
{
|
|
// Enable the screen backlight
|
|
// Lcd_BackLight_OnOff(1);
|
|
// Create the navigation bar window
|
|
// if(clock_window == NULL){
|
|
C_flag = C_Clock;
|
|
clock_window = wjh_createWindow(
|
|
"clock_window", x, y, 340, 70, CN_WINBUF_PARENT, 0, CN_SYS_PF_DISPLAY,
|
|
RGB(1, 1, 1), hwnd, main_window_paint, NULL
|
|
);
|
|
|
|
//创建按钮
|
|
for(int i = 0; i < 8; i++){
|
|
timeclock[i] = wjh_createButton(buttontime[i], BS_NORMAL | WS_UNFILL, 12+i*40, 5, 40, 60, clock_window, button_paint, NULL);
|
|
// HDC hdc = GDD_BeginPaint(timeclock[i]);
|
|
// struct RopGroup ropgroup = GDD_GetRopCode(hdc);
|
|
// ropgroup.HyalineEn = 1;
|
|
// GDD_SetRopCode(timeclock[i], ropgroup);
|
|
// GDD_SetWindowHyalineColor(hwnd, RGB(8,24,58));
|
|
// GDD_EndPaint(timeclock[i], hdc);
|
|
}
|
|
//给main窗口创建一个计时器的timer事件
|
|
wjh_setTimer(clock_window,timer_paint);
|
|
//创建计时器
|
|
c_timer = GDD_CreateTimer(clock_window,0,1000);
|
|
//计时器开始执行
|
|
GDD_StartTimer(c_timer);
|
|
return clock_window;
|
|
// }else{
|
|
// correct_ClockControl();
|
|
// }
|
|
// return NULL;
|
|
}
|
|
|