四则运算器

#include "stdafx.h"
#include "iostream"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"

using namespace std;

BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
        HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
		HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
    }

    return FALSE;
}

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
	HWND hwndCombo1 = GetDlgItem(hwnd,IDC_COMBO1);
	ComboBox_AddString(hwndCombo1,"+");
	ComboBox_AddString(hwndCombo1,"-");
	ComboBox_AddString(hwndCombo1,"*");
	ComboBox_AddString(hwndCombo1,"/");
    return TRUE;
}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
	HWND hwndCombo1 = GetDlgItem(hwnd,IDC_COMBO1);
	int x,y,z,sum;
	TCHAR str1[101];
	TCHAR str2[101];
	TCHAR str[101];
	GetDlgItemText(hwnd,IDC_EDIT1,str1,sizeof(str1));
	GetDlgItemText(hwnd,IDC_EDIT2,str2,sizeof(str2));
	x=atoi(str1);
	y=atoi(str2);
	z=ComboBox_GetCurSel(hwndCombo1);
    switch(id)
    {
        case IDC_OK:
			{
				if(0==z)
					sum=x-y;
				else if(1==z)
					sum=x*y;
				else if(2==z)
					sum=x/y;
				else if(3==z)
					sum=x+y;
			}
		wsprintf(str,"%i",sum);
		SetDlgItemText(hwnd,IDC_EDIT3,str);
        break;
    }
}

void Main_OnClose(HWND hwnd)
{
    EndDialog(hwnd, 0);
}

你可能感兴趣的:(四则运算器)