수정이 필요함
#include#include LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); HINSTANCE g_hInst; LPSTR lpszClass="Calculator"; int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance ,LPSTR lpszCmdParam,int nCmdShow) { HWND hWnd; MSG Message; WNDCLASS WndClass; g_hInst=hInstance; WndClass.cbClsExtra=0; WndClass.cbWndExtra=0; WndClass.hbrBackground=CreateSolidBrush(RGB(235,235,235)); WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); WndClass.hInstance=hInstance; WndClass.lpfnWndProc=(WNDPROC)WndProc; WndClass.lpszClassName=lpszClass; WndClass.lpszMenuName=NULL; WndClass.style=CS_HREDRAW | CS_VREDRAW; RegisterClass(&WndClass); hWnd=CreateWindow(lpszClass,lpszClass,WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT,CW_USEDEFAULT,302,226, NULL,(HMENU)NULL,hInstance,NULL); ShowWindow(hWnd,nCmdShow); while(GetMessage(&Message,0,0,0)) { TranslateMessage(&Message); DispatchMessage(&Message); } return Message.wParam; } //컨트롤값 정의 #define ID_SCREEN (HMENU)100 #define ID_C (HMENU)1 #define ID_CE (HMENU)2 #define ID_BS (HMENU)3 #define ID_MA (HMENU)4 #define ID_MC (HMENU)5 #define ID_MR (HMENU)6 #define ID_MS (HMENU)7 #define ID_B0 (HMENU)8 #define ID_B1 (HMENU)9 #define ID_B2 (HMENU)10 #define ID_B3 (HMENU)11 #define ID_B4 (HMENU)12 #define ID_B5 (HMENU)13 #define ID_B6 (HMENU)14 #define ID_B7 (HMENU)15 #define ID_B8 (HMENU)16 #define ID_B9 (HMENU)17 #define ID_DIV (HMENU)18 #define ID_MUL (HMENU)19 #define ID_SUB (HMENU)20 #define ID_ADD (HMENU)21 #define ID_SQRT (HMENU)22 #define ID_MOD (HMENU)23 #define ID_RVS (HMENU)24 #define ID_EQL (HMENU)25 #define ID_SIGN (HMENU)26 #define ID_DOT (HMENU)27 //현재 연산 종류 #define ADD 101 #define SUB 102 #define MUL 103 #define DIV 104 #define INI 105 //버튼 눌림 함수 선언 void ClickedC(); HWND hScreen; long double lVal=0,lTemp=0; //계산값, 메모리값 int iStatus=INI; //현재 연산의 종류 bool bDot=FALSE; //소수점 on,off char strVal[34]; LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam) { switch(iMessage) { case WM_CREATE: //스크린 hScreen=CreateWindow("edit","0",WS_CHILD | WS_VISIBLE | WS_BORDER | SS_WHITERECT | ES_RIGHT, 5,5,282,20,hWnd,ID_SCREEN,g_hInst,NULL); //버튼생성 //C CreateWindow("button","C",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 212,38,75,25,hWnd,ID_C,g_hInst,NULL); //CE CreateWindow("button","CE",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 135,38,75,25,hWnd,ID_CE,g_hInst,NULL); //Backspace CreateWindow("button","Backspace",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 58,38,75,25,hWnd,ID_BS,g_hInst,NULL); //MemoryClear CreateWindow("button","MC",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5,75,35,25,hWnd,ID_MC,g_hInst,NULL); //MemoryRead CreateWindow("button","MR",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5,104,35,25,hWnd,ID_MR,g_hInst,NULL); //MemorySave CreateWindow("button","MS",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5,133,35,25,hWnd,ID_MS,g_hInst,NULL); //MemoryAdd CreateWindow("button","M+",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5,162,35,25,hWnd,ID_MA,g_hInst,NULL); //Sqrt CreateWindow("button","sqrt",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 252,75,35,25,hWnd,ID_SQRT,g_hInst,NULL); //% CreateWindow("button","%",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 252,104,35,25,hWnd,ID_MOD,g_hInst,NULL); //1/x CreateWindow("button","1/x",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 252,133,35,25,hWnd,ID_RVS,g_hInst,NULL); //= CreateWindow("button","=",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 252,162,35,25,hWnd,ID_EQL,g_hInst,NULL); //'/' CreateWindow("button","/",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 212,75,35,25,hWnd,ID_DIV,g_hInst,NULL); //* CreateWindow("button","*",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 212,104,35,25,hWnd,ID_MUL,g_hInst,NULL); //- CreateWindow("button","-",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 212,133,35,25,hWnd,ID_SUB,g_hInst,NULL); //+ CreateWindow("button","+",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 212,162,35,25,hWnd,ID_ADD,g_hInst,NULL); //9 CreateWindow("button","9",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 172,75,35,25,hWnd,ID_B9,g_hInst,NULL); //8 CreateWindow("button","8",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 132,75,35,25,hWnd,ID_B8,g_hInst,NULL); //7 CreateWindow("button","7",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 92,75,35,25,hWnd,ID_B7,g_hInst,NULL); //6 CreateWindow("button","6",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 172,104,35,25,hWnd,ID_B6,g_hInst,NULL); //5 CreateWindow("button","5",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 132,104,35,25,hWnd,ID_B5,g_hInst,NULL); //4 CreateWindow("button","4",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 92,104,35,25,hWnd,ID_B4,g_hInst,NULL); //3 CreateWindow("button","3",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 172,133,35,25,hWnd,ID_B3,g_hInst,NULL); //2 CreateWindow("button","2",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 132,133,35,25,hWnd,ID_B2,g_hInst,NULL); //1 CreateWindow("button","1",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 92,133,35,25,hWnd,ID_B1,g_hInst,NULL); //0 CreateWindow("button","0",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 92,162,35,25,hWnd,ID_B0,g_hInst,NULL); //'+/-' CreateWindow("button","+/-",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 132,162,35,25,hWnd,ID_SIGN,g_hInst,NULL); //. CreateWindow("button",".",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 172,162,35,25,hWnd,ID_DOT,g_hInst,NULL); return 0; case WM_KEYDOWN: switch(wParam){ case 46: //Delete, CE처리 case 27: //ESC, C처리 ClickedC(); return 0; } if(lVal==(int)lVal){ //정수일 때 switch(wParam){ case 49: case 97: case 35: lVal=lVal*10+1; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 50: case 98: case 40: lVal=lVal*10+2; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 51: case 99: case 34: lVal=lVal*10+3; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 52: case 100: case 37: lVal=lVal*10+4; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 53: case 101: case 12: lVal=lVal*10+5; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 54: case 102: case 39: lVal=lVal*10+6; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 55: case 103: case 36: lVal=lVal*10+7; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 56: case 104: case 38: lVal=lVal*10+8; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 57: case 105: case 33: lVal=lVal*10+9; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; case 48: case 96: case 45: lVal=lVal*10+0; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); return 0; } }//정수 일 때 return 0; case WM_COMMAND: switch(wParam){ case ID_SIGN: lVal=-lVal; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_CE: //방금 입력한 수만 지움 case ID_C: //메모리 다 지움 ClickedC(); SetFocus(hWnd); return 0; } //버튼눌림, lVal이 정수 일 때 if(lVal==(int)lVal){ switch(wParam){ case ID_B1: lVal=lVal*10+1; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B2: lVal=lVal*10+2; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B3: lVal=lVal*10+3; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B4: lVal=lVal*10+4; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B5: lVal=lVal*10+5; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B6: lVal=lVal*10+6; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B7: lVal=lVal*10+7; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B8: lVal=lVal*10+8; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B9: lVal=lVal*10+9; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; case ID_B0: lVal=lVal*10+0; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); SetFocus(hWnd); return 0; } } case WM_DESTROY: PostQuitMessage(0); return 0; } return(DefWindowProc(hWnd,iMessage,wParam,lParam)); } //버튼눌림 함수 정의 void ClickedC(){ //계산기 메모리 초기화 lVal=0; sprintf(strVal,"%G",lVal); SetWindowText(hScreen,strVal); }