Code:
...
void UncheckMenu(HWND hwnd)
{
int menu = 0, submenu = 0;
char holder[3] = {0};
/* check to see if a menu item is already checked. if it is, uncheck it. */
if (menucheck[0] == 49)
{
holder[0] = menucheck[1];
menu = atoi(holder);
holder[0] = menucheck[2];
submenu = atoi(holder);
if (menu == 1)
{
if (submenu == 1)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_FTOC, MF_UNCHECKED); }
else if (submenu == 2)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_FTOK, MF_UNCHECKED); }
else
{ MessageBox(hwnd, "An error occured in the menu.\nPlease restart the application.", "Error", MB_OK | MB_ICONERROR); }
}
else if (menu == 2)
{
if (submenu == 1)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_CTOF, MF_UNCHECKED); }
else if (submenu == 2)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_CTOK, MF_UNCHECKED); }
else
{ MessageBox(hwnd, "An error occured in the menu.\nPlease restart the application.", "Error", MB_OK | MB_ICONERROR); }
}
else if (menu == 3)
{
if (submenu == 1)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_KTOF, MF_UNCHECKED); }
else if (submenu == 2)
{ CheckMenuItem(GetMenu(hwnd), ID_UNITS_KTOC, MF_UNCHECKED); }
else
{ MessageBox(hwnd, "An error occured in the menu.\nPlease restart the application.", "Error", MB_OK | MB_ICONERROR); }
}
else
{ MessageBox(hwnd, "An error occured in the menu.\nPlease restart the application.", "Error", MB_OK | MB_ICONERROR); }
}
}
/* This function sets the labels so the user knows whats going on */
void SetLabel(HWND hwnd, int from, int to)
{
TCHAR fahr_to_cels[22] = "Fahrenheit to Celsius", cels_to_fahr[22] = "Celsius to Fahrenheit", fahr_to_kelv[22] = "Fahrenheit to Kelvin", kelv_to_fahr[22] = "Kelvin to Fahrenheit", cels_to_kelv[24] = "Celsius to Kelvin", kelv_to_cels[24] = "Kelvin to Celsius";
TCHAR tempfahr[19] = "Temp in Fahrenheit", tempcel[20] = "Temp in Celsius", tempkel[20] = "Temp in Kelvin";
UncheckMenu(hwnd);
/*SetWindowText((HWND)ID_LABEL1, "");
SetWindowText((HWND)ID_LABEL2, "");
SetWindowText((HWND)ID_LABEL4, "");*/
SetDlgItemText(hwnd, ID_LABEL1, "");
SetDlgItemText(hwnd, ID_LABEL2, "");
SetDlgItemText(hwnd, ID_LABEL4, "");
/* 1 = fahrenheit, 2 = celsius, 3 = kelvin. */
if (from == 1)
{
SendDlgItemMessage(hwnd, ID_LABEL2, WM_SETTEXT, 0, (LPARAM)tempfahr);
if (to == 1)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_FTOC, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 49;
menucheck[2] = 49;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)fahr_to_cels);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempcel);
}
else if (to == 2)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_FTOK, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 49;
menucheck[2] = 50;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)fahr_to_kelv);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempkel);
}
else { MessageBox(hwnd, "There was an error receiving your request.\nPlease restart the application.", "Error!", MB_OK | MB_ICONERROR); }
}
else if (from == 2)
{
SendDlgItemMessage(hwnd, ID_LABEL2, WM_SETTEXT, 0, (LPARAM)tempcel);
if (to == 1)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_CTOF, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 50;
menucheck[2] = 49;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)cels_to_fahr);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempfahr);
}
else if (to == 2)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_CTOK, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 50;
menucheck[2] = 50;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)cels_to_kelv);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempkel);
}
else { MessageBox(hwnd, "There was an error receiving your request.\nPlease restart the application.", "Error!", MB_OK | MB_ICONERROR); }
}
else if (from == 3)
{
SendDlgItemMessage(hwnd, ID_LABEL2, WM_SETTEXT, 0, (LPARAM)tempkel);
if (to == 1)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_KTOF, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 51;
menucheck[2] = 49;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)kelv_to_fahr);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempfahr);
}
else if (to == 2)
{
CheckMenuItem(GetMenu(hwnd), ID_UNITS_KTOC, MF_CHECKED);
menucheck[0] = 49;
menucheck[1] = 51;
menucheck[2] = 50;
SendDlgItemMessage(hwnd, ID_LABEL1, WM_SETTEXT, 0, (LPARAM)kelv_to_cels);
SendDlgItemMessage(hwnd, ID_LABEL4, WM_SETTEXT, 0, (LPARAM)tempcel);
}
else { MessageBox(hwnd, "There was an error receiving your request.\nPlease restart the application.", "Error!", MB_OK | MB_ICONERROR); }
}
else
{
MessageBox(hwnd, "There was an error receiving your request.\nPlease restart the application.", "Error!", MB_OK | MB_ICONERROR);
}
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
CreateWindowEx(0, TEXT("STATIC"), TEXT("Currently converting: "), WS_CHILD | WS_VISIBLE | SS_SIMPLE,
23, 8, 134, 23, hwnd, (HMENU)ID_TEXT1, g_hInst, NULL);
CreateWindowEx(0, TEXT("STATIC"), TEXT(""), WS_CHILD | WS_VISIBLE | SS_SIMPLE,
160, 8, 150, 23, hwnd, (HMENU)ID_LABEL1, g_hInst, NULL);
CreateWindowEx(0, TEXT("STATIC"), TEXT(""), WS_CHILD | WS_VISIBLE | SS_SIMPLE,
0, 104, 130, 23, hwnd, (HMENU)ID_LABEL2, g_hInst, NULL);
CreateWindowEx (WS_EX_CLIENTEDGE, /* more or 'extended' styles */
TEXT("EDIT"), /* 'class' of control to create */
TEXT(""), /* text displayed in the control */
WS_CHILD | WS_VISIBLE | WS_BORDER, /* how it looks */
131, /* control position: left */
104, /* control position: top */
100, /* control width */
20, /* control height */
hwnd, /* parent window handle */
(HMENU)ID_LABEL3, /* control's ID */
g_hInst, /* application instance */
NULL);
CreateWindowEx (0, TEXT("BUTTON"), TEXT("Convert"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 130, 144, 104, 23, hwnd, (HMENU)ID_TEXT2, g_hInst, NULL);
CreateWindowEx(0, TEXT("STATIC"), TEXT(""), WS_CHILD | WS_VISIBLE | SS_SIMPLE,
0, 208, 130, 23, hwnd, (HMENU)ID_LABEL4, g_hInst, NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER,
131, 208, 100, 20, hwnd, (HMENU)ID_LABEL5, g_hInst, NULL);
CreateWindowEx(0, TEXT("BUTTON"), TEXT("Clear"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
130, 248, 104, 23, hwnd, (HMENU)ID_TEXT3, g_hInst, NULL);
CreateWindowEx(0, TEXT("STATIC"), TEXT(""), WS_CHILD | SS_SIMPLE, 272, 8, 0, 16,
hwnd, (HMENU)ID_LABEL6, g_hInst, NULL);
return 0;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_CLOSE:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_UNITS_FTOC:
SetLabel(hwnd, one, one);
break;
case ID_UNITS_FTOK:
SetLabel(hwnd, one, two);
break;
case ID_UNITS_CTOF:
SetLabel(hwnd, two, one);
break;
case ID_UNITS_CTOK:
SetLabel(hwnd, two, two);
break;
case ID_UNITS_KTOF:
SetLabel(hwnd, three, one);
break;
case ID_UNITS_KTOC:
SetLabel(hwnd, three, two);
break;
case ID_HELP_ABOUT:
MessageBox(hwnd, "Temperature Converter 1.0a; Shibby Inc. © 2005",
"About...", MB_OK | MB_ICONINFORMATION);
break;
case ID_TEXT2:
MessageBox(hwnd, "booyah", "8-)", MB_OK);
break;
case ID_TEXT3:
UncheckMenu(hwnd);
SetDlgItemText(hwnd, ID_LABEL3, "");
SetDlgItemText(hwnd, ID_LABEL5, "");
break;
}
break;
...