#include #include #include "heat.h" BOOL CALLBACK digHeatEventListener (HWND hwnd, UINT event, WPARAM object, LPARAM lParam); BOOL CALLBACK digHeatEventListener (HWND hwnd, UINT event, WPARAM object, LPARAM lParam) { if (event == WM_INITDIALOG) { HWND handleCbox = GetDlgItem(hwnd, cboxFrom); SendMessage(handleCbox, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Celius"); SendMessage(handleCbox, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Fahrenheight"); SendMessage(handleCbox, CB_SETCURSEL, 0, 0); SetDlgItemText(hwnd, txtAmount, "32"); } else if (event == WM_COMMAND) { int objectID = LOWORD(object); if (objectID == cmdConvert) { BOOL success; int amount = GetDlgItemInt(hwnd, txtAmount, &success, 0); if (!success) { MessageBox(hwnd, "Please only enter numeric amounts", "Invalid Data", MB_OK | MB_ICONEXCLAMATION); } else if (amount > 3000) { MessageBox(hwnd, "Too hot, too hot!", "Burning up", MB_OK | MB_ICONEXCLAMATION); } else { HWND handleCbox = GetDlgItem(hwnd, cboxFrom); char answer[10]; if (SendMessage(handleCbox, CB_GETCURSEL, 0, 0) == 0) { sprintf(answer, "%4.2f*F", (amount * 1.8 + 32)); } else { sprintf(answer, "%4.2f*C", ((amount - 32) / 1.8)); } SetDlgItemText(hwnd, lblAnswer, answer); } } else if (objectID == cmdClose) { EndDialog(hwnd, objectID); } } else if (event == WM_CLOSE) { EndDialog(hwnd, object); } else { return false; } return true; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int nCmdShow) { return DialogBox(hInstance, MAKEINTRESOURCE(digHeat), NULL, digHeatEventListener); }