#include <windows.h>
#include "resource.h"
#include <string.h>
BOOL bNewNumber=TRUE,bNewOperation=FALSE;
INT FirstNum = 0,SecondNum = 0;
int iOperation=0;
extern char chStr[5]={'/0'};
extern char szBuffer[20]={'/0'};
HINSTANCE G_hInstance = NULL ;
void ShowNumber(HWND hwnd,UINT iNumber);
INT_PTR CALLBACK AboutDialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
long CALLBACK WndProc(HWND hWnd, int message, int wParam, int lParam);
void ShowNumber(HWND hwnd,UINT iNumber)
{
wsprintf(szBuffer,"%d",iNumber);
SetDlgItemText(hwnd,IDC_EDIT_SHOW,szBuffer);
}
DWORD Compute(UINT FirstNum,int iOperation,UINT iNum)
{
switch(iOperation)
{
case IDC_BUTTON_JIA: return FirstNum+iNum;
case IDC_BUTTON_JIAN:return FirstNum-iNum;
case IDC_BUTTON_CHENG: return FirstNum*iNum;
case IDC_BUTTON_CHU: return iNum ? FirstNum/iNum:-1;
case IDC_BUTTON_YUSHU : return iNum ? FirstNum%iNum:-1;
default : return 0;
}
}
INT_PTR CALLBACK AboutDialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
HICON hIcon = LoadIcon(G_hInstance,MAKEINTRESOURCE(IDI_ICON_ME));
SendMessage(hwndDlg,WM_SETICON,ICON_BIG,(LPARAM)hIcon);
break;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BUTTON_0:
case IDC_BUTTON_1:
case IDC_BUTTON_2:
case IDC_BUTTON_3:
case IDC_BUTTON_4:
case IDC_BUTTON_5:
case IDC_BUTTON_6:
case IDC_BUTTON_7:
case IDC_BUTTON_8:
case IDC_BUTTON_9:
if(bNewNumber)
{
FirstNum=10*FirstNum+LOWORD(wParam)-1000;
ShowNumber(hwndDlg,FirstNum);
}
else
{
bNewOperation=FALSE;
SecondNum=10*SecondNum+LOWORD(wParam)-1000;
ShowNumber(hwndDlg,SecondNum);
}
return TRUE;
case IDC_BUTTON_JIA:
case IDC_BUTTON_JIAN:
case IDC_BUTTON_CHENG:
case IDC_BUTTON_CHU:
case IDC_BUTTON_YUSHU:
bNewOperation=TRUE;
iOperation =LOWORD(wParam);
if(bNewNumber)
{
bNewNumber=FALSE;
return TRUE;
}
FirstNum=Compute(FirstNum,iOperation,SecondNum);
SecondNum=0;
ShowNumber(hwndDlg,FirstNum);
return TRUE;
case IDC_BUTTON_BACK:
if(bNewNumber)
{
FirstNum/=10;
ShowNumber(hwndDlg,FirstNum);
}
else
{
SecondNum/=10;
ShowNumber(hwndDlg,SecondNum);
}
return TRUE;
case IDC_BUTTON_CLEAR:
ShowNumber(hwndDlg,0);
FirstNum=0;SecondNum=0;
bNewNumber=TRUE;bNewOperation=FALSE;
iOperation=0;
return TRUE;
case IDC_BUTTON_EVAL:
{
wsprintf(szBuffer,"%d",Compute(FirstNum,iOperation,SecondNum));
SetDlgItemText(hwndDlg,IDC_EDIT_RESULT,szBuffer);
return TRUE;
}
case IDC_BUTTON_END:
EndDialog(hwndDlg,1);
return true;
}
break;
}
}
return false;
}
long CALLBACK WndProc(HWND hWnd, int message, int wParam, int lParam)
{
switch (message)
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_MENUITEM_COUNT:
DialogBox(G_hInstance,MAKEINTRESOURCE(IDD_DIALOG_COUNT),hWnd,(DLGPROC)AboutDialogProc);
break;
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int __stdcall WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpcmdLine,
int nShowCmd)
{
G_hInstance = hInstance;
DialogBox(G_hInstance,MAKEINTRESOURCE(IDD_DIALOG_COUNT),NULL,(DLGPROC)AboutDialogProc);
return false;
}