📄 timeset.c
字号:
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include <minigui/mywindows.h>
#include <minigui/mgext.h>
#include "../mybuttonreg.h"
//窗口控件ID
#define IDC_MC 100
#define IDC_OK 200
#define IDC_SPR1 201
#define IDC_SPR2 202
#define IDC_HOURE 204
#define IDC_MINUTEE 205
#define IDC_SECONDE 206
#define IDC_CL 207
#define IDC_BS 208
#define IDC_CS 209
static BITMAP bmp_bkgnd;
/*static BITMAP ok_pushed;
static BITMAP ok_unpushed;
static BITMAP ok_mousemove;
static BITMAP return_pushed;
static BITMAP return_unpushed;
static BITMAP return_mousemove;
static BITMAP green_pushed;
static BITMAP green_unpushed;
static BITMAP green_mousemove;
static BITMAP blue_pushed;
static BITMAP blue_unpushed;
static BITMAP blue_mousemove;
*/
static HWND hCtrl1;
static HWND hCtrl2;
static HWND hCtrl3;
static HWND hCtrl4;
static HWND hChildWnd1,hWnd1,hWnd2,hWnd3;
//static HWND hDlg;
int j=0,k=0,l=0;
/*
* 窗口打开时,根据当前的系统时间设定正确的日历显示.
*/
static void ShowRightTime(HWND hDlg)
{
struct tm* ptime;
time_t now;
int day,month,year,hour,minute,second;
char buff[4];
time(&now);
ptime = localtime(&now);
day = ptime->tm_mday;
month = ptime->tm_mon+1;
year = ptime->tm_year+1900;
hour = ptime->tm_hour;
minute = ptime->tm_min;
second = ptime->tm_sec;
j=hour;
k=minute;
l=second;
SendMessage(GetDlgItem(hDlg,IDC_MC),MCM_SETCURDAY,day,0);
SendMessage(GetDlgItem(hDlg,IDC_MC),MCM_SETCURMONTH,month,0);
SendMessage(GetDlgItem(hDlg,IDC_MC),MCM_SETCURYEAR,year,0);
sprintf(buff,"%d",hour);
SendMessage(GetDlgItem(hDlg,IDC_HOURE),MSG_SETTEXT,4,(LPARAM)buff);
sprintf(buff,"%d",minute);
SendMessage(GetDlgItem(hDlg,IDC_MINUTEE),MSG_SETTEXT,4,(LPARAM)buff);
sprintf(buff,"%d",second);
SendMessage(GetDlgItem(hDlg,IDC_SECONDE),MSG_SETTEXT,4,(LPARAM)buff);
}
/*
* 根据用户的选择重新设定系统日期,日历功能不用修改到天以内的精确时间,所以用原时间不变.
*/
SetRightTime(HWND hDlg)
{
struct tm* ptime;
time_t now;
int day,month,year,hour,minute,second;
char buff[4];
time_t t;
struct tm nowtime;
time(&now);
ptime = localtime(&now);
day = ptime->tm_mday;
month = ptime->tm_mon+1;
year = ptime->tm_year+1900;
hour = ptime->tm_hour;
minute = ptime->tm_min;
second = ptime->tm_sec;
day = SendMessage (GetDlgItem(hDlg,IDC_MC), MCM_GETCURDAY, 0, 0);
month = SendMessage (GetDlgItem(hDlg,IDC_MC), MCM_GETCURMONTH, 0, 0);
year = SendMessage (GetDlgItem(hDlg,IDC_MC), MCM_GETCURYEAR, 0, 0);
j=hour;
k=minute;
l=second;
SendMessage(GetDlgItem(hDlg,IDC_HOURE),MSG_GETTEXT,4,(LPARAM)buff);
//-------------小时
hour = atoi(buff);
if((hour>23)||(hour<0))
{
MessageBox (hDlg, "小时应设置在0-23内", "提示", MB_OK | MB_ICONINFORMATION);
return ptime->tm_hour;
}
SendMessage(GetDlgItem(hDlg,IDC_MINUTEE),MSG_GETTEXT,4,(LPARAM)buff);
//------------分钟
minute = atoi(buff);
if((minute>59)||(minute<0))
{
MessageBox (hDlg, "分钟应设置在0-59内", "提示", MB_OK | MB_ICONINFORMATION);
return ptime->tm_min;
}
SendMessage(GetDlgItem(hDlg,IDC_SECONDE),MSG_GETTEXT,4,(LPARAM)buff);
//--------------秒钟
second = atoi(buff);
if((second>59)||(minute<0))
{
MessageBox (hDlg, "秒钟应设置在0-59内", "提示", MB_OK | MB_ICONINFORMATION);
return ptime->tm_sec;
}
nowtime.tm_sec = second; /* Seconds.[0-60] (1 leap second)*/
nowtime.tm_min = minute; /* Minutes.[0-59] */
nowtime.tm_hour = hour; /* Hours. [0-23] */
nowtime.tm_mday = day; /* Day.[1-31] */
nowtime.tm_mon = month-1 ; /* Month. [0-11] */
nowtime.tm_year = year-1900; /* Year- 1900.*/
nowtime.tm_isdst = -1; /* DST.[-1/0/1]*/
t = mktime(&nowtime);
stime(&t);
SendNotifyMessage (hDlg, MSG_CLOSE, 0, 0);
}
//窗口控件数组
CTRLDATA CtrlTime1[]=
{
/* {
"button",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
260, 20, 47, 25,
IDC_OK,"确定",0
},
{
"button",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
260, 105, 47, 25,
IDC_CL,"返回",0
},
{
"button",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
260, 62, 23, 25,
IDC_BS,"绿",0
},
{
"button",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
284, 62, 23, 25,
IDC_CS,"蓝",0
},
*/
{
CTRL_STATIC,
WS_VISIBLE | SS_CENTER,
90, 158, 20, 19,
IDC_SPR1, ":",0
},
{
CTRL_STATIC,
WS_VISIBLE | SS_CENTER,
150, 158, 20, 19,
IDC_SPR2, ":",0
}
};
//窗口属性结构体
DLGTEMPLATE DlgTime1 =
{
WS_VISIBLE | WS_CAPTION | WS_BORDER,
WS_EX_NONE,
0, 0, 320, 216,
"★ ☆ ★ 系 统 时 间 设 定 ★ ☆ ★ ",
0, 0,
2, CtrlTime1,
0
};
/*static void notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
MCCOLORINFO mcci;
//printf("hwnd=%d\n", hwnd);
if ( hwnd == hCtrl1 && nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&ok_pushed);
}
if(hwnd == hCtrl2 && nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_pushed);
}
if ( hwnd == hCtrl3 && nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&green_pushed);
}
if(hwnd == hCtrl4 && nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&blue_pushed);
}
if ( hwnd == hCtrl1 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&ok_unpushed);
SetRightTime(GetParent(hwnd));
// add your business code
}
if(hwnd == hCtrl2 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
SendNotifyMessage(GetParent(hwnd),MSG_CLOSE,0,0);
}
if ( hwnd == hCtrl3 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&green_unpushed);
//MCCOLORINFO mcci;
memset (&mcci, -1, 11*sizeof(int));
mcci.clr_titlebk = COLOR_lightgray;
mcci.clr_titletext = PIXEL_lightwhite;
mcci.clr_arrow = PIXEL_blue;
mcci.clr_arrowHibk = COLOR_yellow;
mcci.clr_daybk = COLOR_green;
mcci.clr_dayHibk = COLOR_magenta;
mcci.clr_daytext = PIXEL_lightwhite;
mcci.clr_trailingtext = COLOR_darkgreen;
mcci.clr_dayHitext = COLOR_lightwhite;
mcci.clr_weekcaptbk = COLOR_yellow;
mcci.clr_weekcapttext = COLOR_magenta;
SendMessage (hChildWnd1, MCM_SETCOLOR, 0, (LPARAM) &mcci);
// add your business code
}
if(hwnd == hCtrl4 && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&blue_unpushed);
//MCCOLORINFO mcci;
memset (&mcci, -1, 11*sizeof(int));
mcci.clr_titlebk = COLOR_lightgray;
mcci.clr_titletext = PIXEL_lightwhite;
mcci.clr_arrow = PIXEL_blue;
mcci.clr_arrowHibk = COLOR_yellow;
mcci.clr_daybk = COLOR_blue;
mcci.clr_dayHibk = COLOR_magenta;
mcci.clr_daytext = PIXEL_lightwhite;
mcci.clr_trailingtext = COLOR_darkgreen;
mcci.clr_dayHitext = COLOR_lightwhite;
mcci.clr_weekcaptbk = COLOR_yellow;
mcci.clr_weekcapttext = COLOR_magenta;
SendMessage (hChildWnd1, MCM_SETCOLOR, 0, (LPARAM) &mcci);
}
if( hwnd == hCtrl1 && nc == MYBUTTON_MOUSEMOVE)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -