计算器2.0版
											自己写了个计算器,也许有不足的地方,希望大家指点呀!呵呵呵!
这是代码:
程序代码:#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
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;
}
void CALLBACK mytimeProc(HWND hwnd ,UINT message,UINT iTimerID,DWORD dwTiemr)
{
    SYSTEMTIME strLocal;
    GetLocalTime(&strLocal);
    TCHAR strlocaltime[256];
    wsprintf(strlocaltime,"%i年%i月%i日 %i:%i:%i",strLocal.wYear,strLocal.wMonth,strLocal.wDay,
             strLocal.wHour,strLocal.wMinute,strLocal.wSecond);
    SetDlgItemText(hwnd,IDC_EDIT4,strlocaltime);
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)//初始化窗口//
{
      SetTimer(hwnd,0,0,mytimeProc);
      HWND hwndCombo = GetDlgItem(hwnd,IDC_COMBO);
      ComboBox_InsertString(hwndCombo,-1,TEXT("+"));
      ComboBox_InsertString(hwndCombo,-1,TEXT("-"));
      ComboBox_InsertString(hwndCombo,-1,TEXT("*"));
      ComboBox_InsertString(hwndCombo,-1,TEXT("/"));
    return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{ 
    switch(id)
    {
    case IDC_OK:
        {
          HWND hwndCombo = GetDlgItem(hwnd,IDC_COMBO);
          TCHAR strname1[256];
          TCHAR strname2[256];
          GetDlgItemText(hwnd,IDC_EDIT1,strname1,sizeof(strname1)/sizeof(TCHAR));
          GetDlgItemText(hwnd,IDC_EDIT2,strname2,sizeof(strname2)/sizeof(TCHAR));
          double i1=atof(strname1);
          double i2=atof(strname2);
          double i3;
          int ret = ComboBox_GetCurSel(hwndCombo);
          switch(ret)
          {
          case 0:
              {
                  i3=i1+i2;
              }
              break;
          case 1:
              {
                  i3=i1-i2;
              }
              break;
          case 2:
              {
                  i3=i1*i2;
              }
                      break;
          case 3:
              {
                  i3=i1/i2;
                  if(i2==0)
                  {
                      MessageBox(hwnd,TEXT("除数不能够为零"),TEXT("提示"),MB_ICONEXCLAMATION);
                      return ;
                  }
              }
              break;
          default:
              break;
          }
             TCHAR strCombo[256];
             gcvt(i3,10,strCombo);//gcvt是浮点数转化为字符数组型的函数,fcvt是单浮点数的转换函数//
             SetDlgItemText(hwnd,IDC_EDIT3,strCombo);
        }
        break;
    default:    break;
    }
}
void Main_OnClose(HWND hwnd)
{
    EndDialog(hwnd, 0);//关闭窗口函数//
}
这是文件打包解压就可以了呀![ 本帖最后由 我菜119 于 2010-5-7 19:34 编辑 ]



											

	    

	


