1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#include <windows.h>
#include <cstdlib>
#include <iostream>
HINSTANCE Currency_GUI_hInst;
HWND MainWindow;
HWND USDBox, USDLabel;
HWND YenBox, YenLabel;
HWND EuroBox, EuroLabel;
double USDBoxDataDouble = 0.00, EuroBoxDataDouble = 0.00, YenBoxDataDouble = 0.00;
bool USDIsWorking = false, EuroIsWorking = false, YenIsWorking = false;
TCHAR USDBoxData[21];
TCHAR EuroBoxData[21];
TCHAR YenBoxData[21];
enum {ID_EDIT_USD = 1, ID_EDIT_YEN, ID_EDIT_EURO};
LRESULT APIENTRY MainWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
int APIENTRY WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR line, int CmdShow)
{
Currency_GUI_hInst = hInst;
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.lpfnWndProc = (WNDPROC) MainWindowProc;
wc.lpszClassName = "Currency GUI Calc";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
MainWindow = CreateWindow(
"Currency GUI Calc",
"Currency Calculator",
WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
192,
128,
NULL,
NULL,
hInst,
NULL);
ShowWindow(MainWindow, SW_SHOW);
UpdateWindow(MainWindow);
while(GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT APIENTRY MainWindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
USDBox = CreateWindow("Edit","0.00",ES_CENTER | WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_RIGHT, 5,20,100,20,hwnd,(HMENU)ID_EDIT_USD,Currency_GUI_hInst,0);
EuroBox = CreateWindow("Edit","0.00",ES_CENTER | WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_RIGHT, 5,40,100,20,hwnd,(HMENU)ID_EDIT_EURO,Currency_GUI_hInst,0);
YenBox = CreateWindow("Edit","0.00",ES_CENTER | WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_RIGHT, 5,60,100,20,hwnd,(HMENU)ID_EDIT_YEN,Currency_GUI_hInst,0);
USDLabel = CreateWindow("Static",":USD",WS_CHILD | WS_VISIBLE,105,21,50,15,hwnd,0,Currency_GUI_hInst,0);
EuroLabel = CreateWindow("Static",":Euro",WS_CHILD | WS_VISIBLE,105,41,50,15,hwnd,0,Currency_GUI_hInst,0);
YenLabel = CreateWindow("Static",":Yen",WS_CHILD | WS_VISIBLE,105,61,50,15,hwnd,0,Currency_GUI_hInst,0);
break;
case WM_COMMAND:
switch (HIWORD(wParam))
{
case EN_CHANGE:
switch (LOWORD(wParam))
{
case ID_EDIT_USD:
if (YenIsWorking == false && EuroIsWorking == false)
{
USDIsWorking = true;
SendMessage(USDBox,WM_GETTEXT,(WPARAM)20, (LPARAM)USDBoxData);
USDBoxDataDouble = strtod(USDBoxData, NULL);
EuroBoxDataDouble = USDBoxDataDouble * .7582;
YenBoxDataDouble = USDBoxDataDouble * 116.79;
sprintf ( EuroBoxData, "%.2f", EuroBoxDataDouble );
SendMessage(EuroBox, WM_SETTEXT, (WPARAM)0, (LPARAM)EuroBoxData);
sprintf ( YenBoxData, "%.2f", YenBoxDataDouble );
SendMessage(YenBox, WM_SETTEXT, (WPARAM)0, (LPARAM)YenBoxData);
USDIsWorking = false;
}
break;
case ID_EDIT_EURO:
if (USDIsWorking == false && YenIsWorking == false)
{
EuroIsWorking = true;
SendMessage(EuroBox,WM_GETTEXT,(WPARAM)20, (LPARAM)EuroBoxData);
EuroBoxDataDouble = strtod(EuroBoxData, NULL);
USDBoxDataDouble = EuroBoxDataDouble / .7582;
YenBoxDataDouble = USDBoxDataDouble * 116.79;
sprintf ( USDBoxData, "%.2f", USDBoxDataDouble );
SendMessage(USDBox, WM_SETTEXT, (WPARAM)0, (LPARAM)USDBoxData);
sprintf ( YenBoxData, "%.2f", YenBoxDataDouble );
SendMessage(YenBox, WM_SETTEXT, (WPARAM)0, (LPARAM)YenBoxData);
EuroIsWorking = false;
}
break;
case ID_EDIT_YEN:
if (USDIsWorking == false && EuroIsWorking == false)
{
YenIsWorking = true;
SendMessage(YenBox,WM_GETTEXT,(WPARAM)20, (LPARAM)YenBoxData);
YenBoxDataDouble = strtod(YenBoxData, NULL);
USDBoxDataDouble = YenBoxDataDouble / 116.79;
EuroBoxDataDouble = USDBoxDataDouble * .7582;
sprintf ( EuroBoxData, "%.2f", EuroBoxDataDouble );
SendMessage(EuroBox, WM_SETTEXT, (WPARAM)0, (LPARAM)EuroBoxData);
sprintf ( USDBoxData, "%.2f", USDBoxDataDouble );
SendMessage(USDBox, WM_SETTEXT,(WPARAM)0, (LPARAM)USDBoxData);
YenIsWorking = false;
}
break;
}
break;
}
default: return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
|