Code:
#define _WIN32_IE 0x0300
#define ID_BUTTON 1
#define ID_BUTTONSA 2
#define ID_BUTTONSB 3
#define ID_EDIT 4
#define ID_EDITA 5
#define ID_LABLE1 6
#define ID_LABLE2 7
#define ID_STATIC 8
#define ID_OPEN 1000
#define ID_CLOSE 1001
#define ID_EXIT 1002
#define ID_CUT 1003
#define ID_COPY 1004
#define ID_PASTE 1005
#define ID_1 1006
#define ID_2 1007
#define ID_3 1008
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <tchar.h>
HINSTANCE g_hinst;
int cals = 3;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void GetSelectedDate(HWND, HWND, HWND);
int OnButton1click(HWND hwnd,HWND, HWND, HWND,HWND);
int FileCreate(HWND hwnd);
int CalenderSwitch(HWND hwnd,HWND,HWND,HWND,HWND);
int TextSwitch(HWND hwnd,HWND,HWND,HWND,HWND);
int FileWrite(HWND hwnd, HWND, HWND,HWND);
HINSTANCE hInst = NULL;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = TEXT("Month Calendar");
wc.hInstance = hInstance ;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor(0,IDC_ARROW);
hInst = hInstance;
g_hinst = hInstance;
RegisterClass(&wc);
hwnd = CreateWindow(wc.lpszClassName, TEXT("Reminder+"),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
100, 100, 500, 350, 0, 0, hInstance, 0);
while( GetMessage(&msg, NULL, 0, 0)) {
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND hwnddateStatic;
static HWND hwnddateEdit;
static HWND hwndbutton2;
static HWND hwndbutton3;
static HWND hwndEdit;
static HWND hwndMonthCal;
static HWND hwndLabel;
INITCOMMONCONTROLSEX icex;
LPNMHDR lpNmHdr;
static HWND hwndbutton;
int calenders;
CREATESTRUCT *cs;
HMENU hMenu, hSubMenu, hSubMenu2;
char szText[64];
static char szMenuItem[6][10] = {"Open", "Close", "Exit", "Cut", "Copy", "Paste"};
switch(msg)
{
case WM_CREATE:
cs = (LPCREATESTRUCT)lParam;
hMenu = CreateMenu();
SetMenu(hwnd, hMenu);
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_OPEN, "&Open");
AppendMenu(hSubMenu, MF_STRING, ID_CLOSE, "&Close");
AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit");
AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
InsertMenu(hMenu, 0, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu, "File");
hSubMenu2 = CreatePopupMenu();
AppendMenu(hSubMenu2, MF_STRING, ID_1, "File 1");
AppendMenu(hSubMenu2, MF_STRING, ID_2, "File 2");
AppendMenu(hSubMenu2, MF_STRING, ID_3, "File 3");
InsertMenu(hSubMenu, 5, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu2, "Recent &Files");
DestroyMenu(hSubMenu2);
DestroyMenu(hSubMenu);
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_CUT, "Cut");
AppendMenu(hSubMenu, MF_STRING, ID_COPY, "Copy");
AppendMenu(hSubMenu, MF_STRING, ID_PASTE, "Paste");
InsertMenu(hMenu, 1, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu, "Edit");
DestroyMenu(hSubMenu);
DestroyMenu(hMenu);
DrawMenuBar(hwnd);
hwnddateStatic= CreateWindow(TEXT("Static"),"Date:",
WS_CHILD | WS_VISIBLE,
105, 0, 200, 200,
hwnd, (HMENU)ID_STATIC, hInst, NULL);
hwnddateEdit = CreateWindow(TEXT("Edit"),"Date here",
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
145, 0, 100, 18,
hwnd, (HMENU)ID_EDIT, hInst, NULL);
ShowWindow(hwnddateEdit,SW_SHOW);
hwndEdit = CreateWindow(TEXT("Edit"),"I am ze terminator",
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
250, 20, 200, 200,
hwnd, (HMENU)ID_EDIT, hInst, NULL);
ShowWindow(hwndEdit,SW_SHOWNORMAL);
hwndbutton = CreateWindow("Button","hide",
WS_CHILD | WS_VISIBLE,
20, 0, 80, 20,
hwnd, (HMENU)ID_BUTTONSA, NULL, NULL);
ShowWindow(hwndbutton,SW_HIDE);
hwndbutton2 = CreateWindow("Button","Calendar",
WS_CHILD | WS_VISIBLE,
20, 0, 80, 20,
hwnd, (HMENU)ID_BUTTONSB, NULL, NULL);
ShowWindow(hwndbutton2,SW_SHOW);
hwndLabel = CreateWindow("Static","loading...",
WS_CHILD | WS_VISIBLE ,
100, 230, 500, 500,
hwnd, (HMENU)ID_LABLE1, NULL, NULL);
hwndbutton3 = CreateWindow("Button","save",
WS_CHILD | WS_VISIBLE,
10, 230, 80, 30,
hwnd, (HMENU)ID_BUTTON, NULL, NULL);
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
hwndMonthCal = CreateWindowEx(0, MONTHCAL_CLASS, TEXT(""),
WS_BORDER | WS_CHILD | WS_VISIBLE | MCS_DAYSTATE,
20, 20, 200, 200, hwnd, (HMENU)2, NULL, NULL);
GetSelectedDate(hwndMonthCal, hwndLabel, hwnddateEdit);
ShowWindow(hwndMonthCal,SW_HIDE);
break;
case WM_NOTIFY:
lpNmHdr = (LPNMHDR) lParam;
if (lpNmHdr->code==MCN_SELECT) {
GetSelectedDate(hwndMonthCal, hwndLabel, hwnddateEdit);
return CalenderSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_BUTTON:
//what type of event happened to the button?
if(HIWORD(wParam) == BN_CLICKED)//it was clicked
{
// return OnButton1click(hwnd);
//MessageBox(hwnd,"...hello","hello...",MB_OK);
return OnButton1click(hwnd,hwndMonthCal, hwndLabel, hwndEdit, hwnddateEdit);//call our click handler code
}
//else let this fall thru to the DefWindowProc handler
break;
case ID_BUTTONSA:
if(HIWORD(wParam) == BN_CLICKED)
{
if(cals == 1){
return CalenderSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
else if(cals == 3)
{
return TextSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
else
{
return TextSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
SetFocus(hwndMonthCal);
}
}
break;
case ID_BUTTONSB:
if(HIWORD(wParam) == BN_CLICKED)
{
if(cals == 1){
return CalenderSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
else if(cals == 3)
{
return TextSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
else
{
SetFocus(hwndMonthCal);
return TextSwitch(hwnd,hwndMonthCal,hwnddateEdit,hwndbutton,hwndbutton2);
}
}
break;
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
void GetSelectedDate(HWND hwndMonthCal, HWND hwndLabel, HWND hwnddateEdit)
{
int month;
SYSTEMTIME time;
TCHAR date[50];
ZeroMemory(&time, sizeof(SYSTEMTIME));
SendMessage(hwndMonthCal, MCM_GETCURSEL, 0, (LPARAM) &time);
_stprintf(date, _T("%d/%d/%d"), time.wMonth, time.wDay, time.wYear);
SetWindowText(hwnddateEdit,date);
SetWindowText(hwndLabel, date);
}
int OnButton1click(HWND hwnd,HWND hwndMonthCal, HWND hwndLabel, HWND hwndEdit,HWND hwnddateEdit)
{
FILE *pfile;
pfile = fopen("Date.txt","r");
if(pfile == NULL)
{
if(MessageBox(hwnd,"The file for storing dates needs to be made or has been deleted, would you like to make one?","Database",MB_YESNO) == IDYES)
{
return FileCreate(hwnd);
}
else
{
if(MessageBox(hwnd,"if you dont have this file the program will not be able to store dates\nare you sure you don't want to make a file to store dates?\n(press no to make the file)","DataBase",MB_YESNO) == IDNO)
{
return FileCreate(hwnd);
}
else
{
MessageBox(hwnd,"this program will NOT store dates now.\nIf you ever change your mind just goto \"file\" then \"create file\".","file",MB_OK);
return 0;
}
}
}
if(pfile != NULL)
{
fclose(pfile);
}
return FileWrite(hwndMonthCal, hwndLabel, hwndEdit,hwnddateEdit);
}
int FileCreate(HWND hwnd)
{
FILE *pfile;
pfile = fopen("date.txt","a");
MessageBox(hwnd,"File created","file",MB_OK);
}
int FileWrite(HWND hwndMonthCal, HWND hwndLabel, HWND hwndEdit, HWND hwnddateEdit)
{
FILE *pfile;
int month;
SYSTEMTIME time;
TCHAR date[50];
TCHAR dateedit[1000];
TCHAR Edit[1000];
ZeroMemory(&time, sizeof(SYSTEMTIME));
SendMessage(hwndMonthCal, MCM_GETCURSEL, 0, (LPARAM) &time);
GetWindowText(hwnddateEdit,dateedit,1000);
GetWindowText(hwndEdit,Edit,1000);
//_stprintf(date, _T("last date saved: %d/%d/%d\nFor:%s"), time.wMonth, time.wDay, time.wYear,Edit);
_stprintf(date, _T("last date saved: %s\nFor:%s"), dateedit,Edit);
pfile = fopen("date.txt","a");
fprintf(pfile,"%d/%d/%d...%s\n",time.wMonth, time.wDay, time.wYear,Edit);
fclose(pfile);
SetWindowText(hwndLabel, date);
}
int CalenderSwitch(HWND hwnd,HWND hwndMonthCal,HWND hwnddateEdit,HWND hwndbutton,HWND hwndbutton2)
{
cals = 2;
ShowWindow(hwndbutton,SW_HIDE);
ShowWindow(hwndbutton2,SW_SHOW);
ShowWindow(hwndMonthCal,SW_HIDE);
ShowWindow(hwnddateEdit,SW_SHOW);
}
int TextSwitch(HWND hwnd,HWND hwndMonthCal,HWND hwnddateEdit,HWND hwndbutton,HWND hwndbutton2)
{
cals = 1;
ShowWindow(hwndbutton,SW_SHOW);
ShowWindow(hwndbutton2,SW_HIDE);
ShowWindow(hwndMonthCal,SW_SHOW);
}