📄 memoireadd.c
字号:
#include "memoire.h"
#include "../../mybuttonreg.h"
#define IDC_TOOLS_MONTH_ADD_STATIC_TITLE 808
#define IDC_TOOLS_MONTH_ADD_STATIC_TEXT 809
#define IDC_TOOLS_MONTH_ADD_SLEDIT_TITLE 810
#define IDC_TOOLS_MONTH_ADD_SLEDIT_TEXT 811
#define IDC_TOOLS_MONTH_ADD_BUTTON_CREAT 812
#define IDC_TOOLS_MONTH_ADD_BUTTON_QUIT 813
#define IDC_TOOLS_MONTH_ADD_STATIC_YEAR 814
#define IDC_TOOLS_MONTH_ADD_STATIC_MONTH 815
#define IDC_TOOLS_MONTH_ADD_STATIC_DATA 816
#define IDC_TOOLS_MONTH_ADD_STATIC_HOUR 817
#define IDC_TOOLS_MONTH_ADD_STATIC_MINUTE 818
#define IDC_TOOLS_MONTH_ADD_SLEDIT_YEAR 819
#define IDC_TOOLS_MONTH_ADD_SLEDIT_MONTH 820
#define IDC_TOOLS_MONTH_ADD_SLEDIT_DATA 821
#define IDC_TOOLS_MONTH_ADD_SLEDIT_HOUR 822
#define IDC_TOOLS_MONTH_ADD_SLEDIT_MINUTE 823
//#define MEMOIREDAT "data/memoiredat.txt"
#define MSG_MONTH_ADD 1106
static BITMAP creat_pushed;
static BITMAP creat_unpushed;
static BITMAP creat_mousemove;
static BITMAP return_pushed;
static BITMAP return_unpushed;
static BITMAP return_mousemove;
static BITMAP jpg_bkgnd_MA;
HWND hMonthadd;
HWND hCtrl_creat;
HWND hCtrl_return;
static void emMALoadBitmap()
{
LoadBitmap (HDC_SCREEN, &creat_pushed, "image/button/tool_creat_pushed.jpg");
LoadBitmap (HDC_SCREEN, &creat_unpushed, "image/button/tool_creat_unpushed.jpg");
LoadBitmap (HDC_SCREEN, &creat_mousemove, "image/button/tool_creat_mousemove.jpg");
LoadBitmap (HDC_SCREEN, &return_pushed, "image/button/tool_return_pushed.jpg");
LoadBitmap (HDC_SCREEN, &return_unpushed, "image/button/tool_return_unpushed.jpg");
LoadBitmap (HDC_SCREEN, &return_mousemove, "image/button/tool_return_mousemove.jpg");
}
static void emMAUnLoadBitmap()
{
UnloadBitmap (&creat_pushed);
UnloadBitmap (&creat_unpushed);
UnloadBitmap (&creat_mousemove);
UnloadBitmap (&return_pushed);
UnloadBitmap (&return_unpushed);
UnloadBitmap (&return_mousemove);
}
static void MonAdd_notify_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
if ( hwnd == hCtrl_creat&& nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&creat_pushed);
}
if ( hwnd == hCtrl_creat && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&creat_unpushed);
SendNotifyMessage(hMonthadd,IDC_TOOLS_MONTH_ADD_BUTTON_CREAT,0,0);
}
if( hwnd == hCtrl_creat && nc == MYBUTTON_MOUSEMOVE)
{
SetWindowAdditionalData(hwnd, (DWORD)&creat_mousemove);
}
//-----------------------------------------------------------
if ( hwnd == hCtrl_return&& nc == MYBUTTON_PUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_pushed);
}
if ( hwnd == hCtrl_return && nc == MYBUTTON_UNPUSHED)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_unpushed);
SendNotifyMessage(hMonthadd,MSG_CLOSE,0,0);
}
if( hwnd == hCtrl_return && nc == MYBUTTON_MOUSEMOVE)
{
SetWindowAdditionalData(hwnd, (DWORD)&return_mousemove );
}
//-----------------------------------------------------------
InvalidateRect (hwnd, NULL, TRUE);
}
/////////////////////////////////////////////////////////////
struct memoire litem2;
HWND fWnd;
FILE *fp;
static int Month_Add(HWND hWnd)
{
struct tm* ptime;
time_t now;
time(&now);
ptime = localtime(&now);
sprintf(litem2.year,"%d",ptime->tm_year+1900);
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_TITLE),litem2.title,sizeof(litem2.title));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_TEXT),litem2.text,sizeof(litem2.text));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_YEAR),litem2.year,sizeof(litem2.year));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_MONTH),litem2.month,sizeof(litem2.month));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_DATA),litem2.data,sizeof(litem2.data));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_HOUR),litem2.hour,sizeof(litem2.hour));
GetWindowText(GetDlgItem(hWnd,IDC_TOOLS_MONTH_ADD_SLEDIT_MINUTE),litem2.minute,sizeof(litem2.minute));
printf("len:%d\n",strlen(litem2.title));
if((strlen(litem2.title)>20) || (strlen(litem2.title)== 0))
{
MessageBox(hWnd,"请输入正确的标题","",MB_OK | MB_ICONINFORMATION);
return;
}
if(strlen(litem2.title)>200)
{
MessageBox(hWnd,"内容超出范围","",MB_OK | MB_ICONINFORMATION);
return;
}
if((atoi(litem2.year)>10000) || (atoi(litem2.year)<=0))
{
MessageBox(hWnd,"请输入正确的年份","",MB_OK | MB_ICONINFORMATION);
return;
}
if((atoi(litem2.month)>12) || (atoi(litem2.month)<=0))
{
MessageBox(hWnd,"请输入正确的月份","",MB_OK | MB_ICONINFORMATION);
return;
}
if((atoi(litem2.data)>31) || (atoi(litem2.data)<=0))
{
MessageBox(hWnd,"请输入正确的日期","",MB_OK | MB_ICONINFORMATION);
return;
}
if((atoi(litem2.hour)>24) || (atoi(litem2.hour)< 0))
{
MessageBox(hWnd,"请输入正确的小时","",MB_OK | MB_ICONINFORMATION);
return;
}
if((atoi(litem2.minute)>60) || (atoi(litem2.minute)< 0))
{
MessageBox(hWnd,"请输入正确的分钟","",MB_OK | MB_ICONINFORMATION);
return;
}
if((fp=fopen(MEMOIREDAT,"a+"))==NULL)
{
MessageBox(hWnd,"打开文件失败","",MB_OK | MB_ICONINFORMATION);
return;
}
fwrite(&litem2,sizeof(struct memoire),1,fp);
fclose(fp);
SendNotifyMessage(fWnd,MSG_MONTH_ADD,0,0L);
}
static int MonthAddProc(HWND hMonthadd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc = (HDC)wParam;
const RECT* clip = (const RECT*) lParam;
BOOL fGetDC = FALSE;
RECT rcTemp;
switch (message)
{
case MSG_CREATE:
{ emMALoadBitmap();
CreateWindow (CTRL_STATIC,
"标题:",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_TITLE,
10, 10, 40, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"内容:",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_TEXT,
10, 40, 40, 20,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_TITLE,
50, 10, 150, 20,
hMonthadd,
0);
CreateWindow (CTRL_MLEDIT,
"",
WS_VISIBLE | ES_AUTOWRAP| WS_VSCROLL,
IDC_TOOLS_MONTH_ADD_SLEDIT_TEXT,
50, 40, 150, 80,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_YEAR,
50, 130, 40, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"年",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_YEAR,
90, 130, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_MONTH,
140, 130, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"月",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_MONTH,
180, 130, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_DATA,
220, 130, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"日",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_DATA,
260, 130, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_HOUR,
50, 160, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"时",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_HOUR,
90, 160, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_SLEDIT,
"",
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
IDC_TOOLS_MONTH_ADD_SLEDIT_MINUTE,
140, 160, 30, 20,
hMonthadd,
0);
CreateWindow (CTRL_STATIC,
"分",
WS_VISIBLE | SS_CENTER,
IDC_TOOLS_MONTH_ADD_STATIC_MINUTE,
180, 160, 30, 20,
hMonthadd,
0);
hCtrl_creat= CreateWindowEx(CTRL_MYBUTTON,
"创建",
WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,
IDC_TOOLS_MONTH_ADD_BUTTON_CREAT,
240, 20, 60, 25,
hMonthadd,
(DWORD)&creat_unpushed);
hCtrl_return= CreateWindowEx(CTRL_MYBUTTON,
"退出",
WS_VISIBLE | WS_CHILD, WS_EX_TRANSPARENT,
IDC_TOOLS_MONTH_ADD_BUTTON_QUIT,
240, 50, 60, 25,
hMonthadd,
(DWORD)&return_unpushed);
SetNotificationCallback ( hCtrl_creat, MonAdd_notify_proc);
SetNotificationCallback ( hCtrl_return, MonAdd_notify_proc );
}
break;
case MSG_MOUSEMOVE:
SetWindowAdditionalData( hCtrl_creat, (DWORD)&creat_unpushed );
InvalidateRect (hCtrl_creat, NULL, TRUE);
SetWindowAdditionalData( hCtrl_return, (DWORD)&return_unpushed );
InvalidateRect (hCtrl_return, NULL, TRUE);
break;
case MSG_ERASEBKGND:
if (hdc == 0) {
hdc = GetClientDC (hMonthadd);
fGetDC = TRUE;
}
if (clip) {
rcTemp = *clip;
ScreenToClient (hMonthadd, &rcTemp.left, &rcTemp.top);
ScreenToClient (hMonthadd, &rcTemp.right, &rcTemp.bottom);
IncludeClipRect (hdc, &rcTemp);
}
// FillBoxWithBitmap (hdc, rcTemp.left, rcTemp.top, 0, 0, &jpg_bkgnd_EM);
FillBoxWithBitmap (hdc, 0, 0, 320, 192, &jpg_bkgnd_MA);
if (fGetDC)
ReleaseDC (hdc);
return 0;
case IDC_TOOLS_MONTH_ADD_BUTTON_CREAT:
Month_Add(hMonthadd);
emMAUnLoadBitmap();
DestroyMainWindow (hMonthadd);
PostQuitMessage (hMonthadd);
break;
case MSG_CLOSE:
{
emMAUnLoadBitmap();
DestroyMainWindow (hMonthadd);
PostQuitMessage (hMonthadd);
return 0;
}
}
return DefaultMainWinProc(hMonthadd, message, wParam, lParam);
}
int MemoireAdd(HWND hMemoire)
{
MSG Msg;
MAINWINCREATE CreateInfo;
fWnd=hMemoire;
RegisterMyButtonControl ();
CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE;
CreateInfo.dwExStyle = WS_EX_NONE;
CreateInfo.spCaption = "添加备忘录";
CreateInfo.hMenu = 0;
CreateInfo.hCursor = GetSystemCursor(IDC_ARROW);
CreateInfo.hIcon = 0;
CreateInfo.MainWindowProc = MonthAddProc;
CreateInfo.lx = 0;
CreateInfo.ty = 0;
CreateInfo.rx = 320;
CreateInfo.by = 216;
CreateInfo.iBkColor = GetWindowElementColor (BKC_CONTROL_DEF);
CreateInfo.dwAddData = 0;
CreateInfo.hHosting =hMemoire ;
LoadBitmap (HDC_SCREEN, &jpg_bkgnd_MA, "./image/background/bkgnd29.jpg");
hMonthadd=CreateMainWindow(&CreateInfo);
ShowWindow(hMonthadd,SW_SHOWNORMAL);
while(GetMessage(&Msg,hMonthadd))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
MainWindowThreadCleanup(hMonthadd);
UnregisterMyButtonControl ();
UnloadBitmap (&jpg_bkgnd_MA);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -