#include LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HWND Check; HWND F_Int; HWND F_SkillP; HWND F_SkillM; HWND Reset; HWND Results; #define ID_SKILL_PERCENT 1000 #define ID_SKILL_MINUTES 1001 #define ID_INT 1002 #define ID_CHECK 1003 #define ID_RESET 1004 #define ID_RESULTS 1005 HINSTANCE g_inst; unsigned long int o_min;//online unsigned long int f_min;//offline unsigned long int c_int; unsigned long int d_mod; unsigned long int c_per; unsigned long int c_min; char szClassName[ ] = "Skill Calculator"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); g_inst = hThisInstance; wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, szClassName, "Skill Calculator --Bioteq", WS_SYSMENU|WS_MINIMIZEBOX , CW_USEDEFAULT, CW_USEDEFAULT, 280, 80, HWND_DESKTOP, NULL, hThisInstance, NULL ); ShowWindow (hwnd, nFunsterStil); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } int is_number(char * str) { char *point = str; if (!str) return 0; for (;*point;point++) { if (!isdigit(*point)) return 0; } return 1; } void update_result(void) { char buf[150]; sprintf(buf, "%lu on. min. %lu off. min.", o_min,f_min); SendMessage(Results, WM_SETTEXT, strlen(buf), (LPARAM)(LPCSTR)buf); } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { RECT rect; HWND l1,l2,l3; GetClientRect(hwnd, &rect); F_Int = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT","", WS_CHILD|WS_VISIBLE|ES_CENTER,0,15,30,20,hwnd, NULL,g_inst,0); F_SkillP = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT","", WS_CHILD|WS_VISIBLE|ES_CENTER,35,15,30,20,hwnd, NULL,g_inst,0); F_SkillM = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT","", WS_CHILD|WS_VISIBLE|ES_CENTER,70,15,55,20,hwnd, NULL,g_inst,0); Check = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", "", BS_TEXT|WS_CHILD, 130,15,70,20,hwnd,(HMENU)ID_CHECK,g_inst,0); SendMessage(Check, WM_SETTEXT, strlen("Check"), (LPARAM)(LPCSTR)"Check"); Reset = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", "", BS_TEXT|WS_CHILD, 200,15,70,20,hwnd,(HMENU)ID_RESET,g_inst,0); SendMessage(Reset, WM_SETTEXT, strlen("Reset"), (LPARAM)(LPCSTR)"Reset"); Results = CreateWindowEx(WS_EX_CLIENTEDGE, "STATIC","", WS_CHILD|WS_VISIBLE|ES_CENTER,0,36,270,20,hwnd, NULL,g_inst,0); l1 = CreateWindowEx(0, "STATIC","Int", WS_CHILD|WS_VISIBLE|ES_CENTER,0,0,30,15,hwnd, NULL,g_inst,0); l2 = CreateWindowEx(0, "STATIC","Sk%", WS_CHILD|WS_VISIBLE|ES_CENTER,35,0,30,15,hwnd, NULL,g_inst,0); l3 = CreateWindowEx(0, "STATIC","Minutes", WS_CHILD|WS_VISIBLE|ES_CENTER,70,0,55,15,hwnd, NULL,g_inst,0); SendMessage(Results, WM_SETTEXT, strlen("0 on. min. 0 off. min."), (LPARAM)(LPCSTR)"0 on. min. 0 off. min."); ShowWindow(F_Int,SW_SHOW); ShowWindow(F_SkillP, SW_SHOW); ShowWindow(Check,SW_SHOW); ShowWindow(Reset, SW_SHOW); ShowWindow(Results, SW_SHOW); ShowWindow(l1,SW_SHOW); ShowWindow(l2, SW_SHOW); ShowWindow(l3,SW_SHOW); break; } case WM_COMMAND: switch(LOWORD(wParam)) { case ID_CHECK: { unsigned long int ilen = SendMessage(F_Int,WM_GETTEXTLENGTH,0,0); unsigned long int plen = SendMessage(F_SkillP, WM_GETTEXTLENGTH,0,0); unsigned long int mlen = SendMessage(F_SkillM, WM_GETTEXTLENGTH,0,0); char t_int[ilen+10]; char t_per[plen+10]; char t_min[mlen+10]; unsigned long int d_off_table[20]; unsigned long int d_on_table[20]; int i; int dif; int d; int full,t_omin,t_fmin; SendMessage(F_Int,WM_GETTEXT,ilen+4,(LPARAM)(LPCSTR)t_int); SendMessage(F_SkillP,WM_GETTEXT,plen+4,(LPARAM)(LPCSTR)t_per); SendMessage(F_SkillM,WM_GETTEXT,mlen+4,(LPARAM)(LPCSTR)t_min); if (t_int[0] == '\0' || t_per[0] == '\0' || t_min[0] == '\0') { MessageBox(hwnd, "Please fill out all three boxes with your current Int, current skill percent, and 'minutes' that improve shows.\nNOTE:These minutes MUST be the original minutes!", "Skill calc Error.",0); return; } if (!is_number(t_int)) { MessageBox(hwnd, "Int must be completely numerical.", "Skill calc Error.", 0); return; } if (!is_number(t_per)) { MessageBox(hwnd, "Skill percent must be completely numerical.", "Skill calc Error.", 0); return; } if (!is_number(t_min)) { MessageBox(hwnd, "Skill minutes must be completely numerical.", "Skill calc Error.", 0); return; } c_int = atoi(t_int); c_per = atoi(t_per); c_min = atoi(t_min); if (c_int < 0 || c_per < 0 || c_min < 0) // WE SHOULD NEVER GET HERE! { MessageBox(hwnd, "All values MUST be zero or above!", "Skill calc Error.", 0); return; } if (c_per > 100) { c_per = 100; SendMessage(F_SkillP, WM_SETTEXT, strlen("100"), (LPARAM)(LPCSTR)"100"); } /* build tables based on info given */ for (i=0;i<20;i++) { if (c_per >=75) // 75+ tables { d_on_table[i] = ((100 - c_int) + (5 * (i+1))); } if (c_per < 75) { d_on_table[i] = ((100 - c_int) + (5 * (i + 1))) * 5; } } dif = -1; for (i = 0;i<20;i++) { if (c_min == d_on_table[i]) dif = i+1; } if (dif == -1) { char t[5000]; char tab[5000]; unsigned long int t_table[40]; unsigned long int ii; for (ii=0;ii<20;ii++) { t_table[ii] = ((100 - c_int) + (5 * (ii+1))); t_table[ii+20] = (((100 - c_int) + (5 * (ii + 1))) * 5); } tab[0] = '\0'; for (ii=0;ii<20;ii++) { sprintf(t, "s%d [%lu/%lu] ", ii+1, t_table[ii], t_table[ii+20]); strcat(tab,t); } sprintf(t, "Incorrect minutes input. \nI cannot find a match in the table for you inputed minutes.\n" "Here is the table for you current int. Find the number that most likely matches the minutes you should have began with. First number is 75-100+ second is 1-74\n%s",tab); MessageBox(hwnd, t, "",0); return; } if (dif == 1) { /* Build skill 1 table instead */ for (i = 0; i<20;i++) { if (c_per >=75) { d_off_table[i] = ((((100 - c_int) + (5 * 1)) * 2)); } if (c_per < 75) { d_off_table[i] = ((((100 - c_int) + (5 * 1)) * 2) * 5); } } } else { d_off_table[0] = 0; for (i=1;i<20;i++) { d = i + 1; if (c_per >=75) { d_off_table[i] = ((100 - c_int) + (5 * d)) * (5 * (d - 1)); } if (c_per < 75) { d_off_table[i] = (((100 - c_int) + (5 * d)) * ((5 * (d - 1)))) * 5; } } } // Compute online time if (c_per >= 75) { t_omin = d_on_table[dif-1] * (100 - c_per); o_min += t_omin; if (dif == 1) { t_fmin = d_off_table[0] * (100 - c_per); f_min += t_fmin; } else { t_fmin = d_off_table[dif-1] * (100 - c_per); f_min += t_fmin; } } else if (c_per < 75) { t_omin = d_on_table[dif-1] * (75 - c_per); t_omin += (d_on_table[dif-1] / 5) * 25; o_min += t_omin; if (dif == 1) { t_fmin = d_off_table[0] * (100 - c_per); t_fmin += (d_off_table[0] / 5) * 25; f_min += t_fmin; } else { t_fmin = d_off_table[dif-1] * (75 - c_per); t_fmin += (d_off_table[dif-1] / 5) * 25; f_min += t_fmin; } } update_result(); //o_min += d_on_table[dif-1]; //if (dif == 1) // f_min += d_off_table[0]; //else // f_min += d_off_table[dif]; //update_result(); break; } case ID_RESET: { SendMessage(F_Int, WM_SETTEXT, strlen(""), (LPARAM)(LPCSTR)""); SendMessage(F_SkillP, WM_SETTEXT, strlen(""), (LPARAM)(LPCSTR)""); SendMessage(F_SkillM, WM_SETTEXT, strlen(""), (LPARAM)(LPCSTR)""); o_min = 0; f_min = 0; update_result(); break; } } break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }