⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 计算器源代码
💻
📖 第 1 页 / 共 4 页
字号:
				ScrText[ScrLen]='.';
				ScrText[ScrLen+1]=0;
			}
			else
			{
				ScrText[1]='6';
			}
			switch(FNum)
			{
			case FNUM16:
				ScrNum=ScrNum*16+6;
				break;
			case FNUM10:
				ScrNum=ScrNum*10+6;
				break;
			case FNUM8:
				ScrNum=ScrNum*8+6;
			}
		}
	}
	Screen.SetWindowText(ScrText);
}

void CMyDlg::On7() 
{
	// TODO: Add your control notification handler code here
	ScrLen=Screen.GetWindowTextLength();
	Screen.GetWindowText(ScrText,ScrLen+1);
	if(Flag)
	{
		Flag=0;
		ScrNum=7;
		ScrText[0]=' ';
		ScrText[1]='7';
		ScrText[2]='.';
		ScrText[3]=0;
	}
	else if(ScrLen<30)
	{
		if(Fpoint)
		{
			ScrNum+=7*pow(10,GetCharPosFromLeft(ScrText,'.')-ScrLen-1);
			ScrText[ScrLen]='7';
			ScrText[ScrLen+1]=0;
		}
		else
		{
			if(ScrNum)
			{
				ScrText[ScrLen-1]='7';
				ScrText[ScrLen]='.';
				ScrText[ScrLen+1]=0;
			}
			else
			{
				ScrText[1]='7';
			}
			switch(FNum)
			{
			case FNUM16:
				ScrNum=ScrNum*16+7;
				break;
			case FNUM10:
				ScrNum=ScrNum*10+7;
				break;
			case FNUM8:
				ScrNum=ScrNum*8+7;
			}
		}
	}
	Screen.SetWindowText(ScrText);
}

void CMyDlg::On8() 
{
	// TODO: Add your control notification handler code here
	ScrLen=Screen.GetWindowTextLength();
	Screen.GetWindowText(ScrText,ScrLen+1);
	if(Flag)
	{
		Flag=0;
		ScrNum=8;
		ScrText[0]=' ';
		ScrText[1]='8';
		ScrText[2]='.';
		ScrText[3]=0;
	}
	else if(ScrLen<30)
	{
		if(Fpoint)
		{
			ScrNum+=8*pow(10,GetCharPosFromLeft(ScrText,'.')-ScrLen-1);
			ScrText[ScrLen]='8';
			ScrText[ScrLen+1]=0;
		}
		else
		{
			if(ScrNum)
			{
				ScrText[ScrLen-1]='8';
				ScrText[ScrLen]='.';
				ScrText[ScrLen+1]=0;
			}
			else
			{
				ScrText[1]='8';
			}
			switch(FNum)
			{
			case FNUM16:
				ScrNum=ScrNum*16+8;
				break;
			case FNUM10:
				ScrNum=ScrNum*10+8;
			}
		}
	}
	Screen.SetWindowText(ScrText);
}

void CMyDlg::On9() 
{
	// TODO: Add your control notification handler code here
	ScrLen=Screen.GetWindowTextLength();
	Screen.GetWindowText(ScrText,ScrLen+1);
	if(Flag)
	{
		Flag=0;
		ScrNum=9;
		ScrText[0]=' ';
		ScrText[1]='9';
		ScrText[2]='.';
		ScrText[3]=0;
	}
	else if(ScrLen<30)
	{
		if(Fpoint)
		{
			ScrNum+=9*pow(10,GetCharPosFromLeft(ScrText,'.')-ScrLen-1);
			ScrText[ScrLen]='9';
			ScrText[ScrLen+1]=0;
		}
		else
		{
			if(ScrNum)
			{
				ScrText[ScrLen-1]='9';
				ScrText[ScrLen]='.';
				ScrText[ScrLen+1]=0;
			}
			else
			{
				ScrText[1]='9';
			}
			switch(FNum)
			{
			case FNUM16:
				ScrNum=ScrNum*16+9;
				break;
			case FNUM10:
				ScrNum=ScrNum*10+9;
			}
		}
	}
	Screen.SetWindowText(ScrText);
}

void CMyDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	OnEqual();
	Sign=FADD;
	Scr_Num=ScrNum;
}

void CMyDlg::OnBackspace() 
{
	// TODO: Add your control notification handler code here
	if(ScrNum)
	{
		ScrLen=Screen.GetWindowTextLength();
		Screen.GetWindowText(ScrText,ScrLen+1);
		if(ScrText[ScrLen-1]=='.')
		{
			Fpoint=0;
			if(ScrLen==3)
			{
				ScrNum=0;
				ScrText[1]='0';
				ScrText[2]='.';
				ScrText[3]=0;
			}
			else
			{
				ScrText[ScrLen-2]='.';
				ScrText[ScrLen-1]=0;
			}
		}
		else
		{
			ScrText[ScrLen-1]=0;
		}

		char p;
		switch(FNum)
		{
		case FNUM16:
			p=16;
			break;
		case FNUM10:
			p=10;
			break;
		case FNUM8:
			p=8;
			break;
		case FNUM2:
			p=2;
		}
		if(Fpoint)
		{
			int offset=GetCharPosFromLeft(ScrText,'.');
			ScrNum*=pow(p,ScrLen-offset-1);
			if((long) (ScrNum))
			{
				ScrNum=(long) ScrNum;
				ScrNum/=pow(p,ScrLen-offset-1);
			}
		}
		else
		{
			if((long) (ScrNum/p))
			{
				ScrNum=(long) (ScrNum/p);
			}
			else
			{
				ScrNum/=p;
			}
		}
		Screen.SetWindowText(ScrText);
	}
}

void CMyDlg::OnClean() 
{
	// TODO: Add your control notification handler code here
	ScrNum=0;
	Fpoint=0;
	Screen.SetWindowText(" 0.");
}

void CMyDlg::OnClear() 
{
	// TODO: Add your control notification handler code here
	Screen.SetWindowText(" 0.");
	ScrNum=0;
	Scr_Num=0;
	Fpoint=0;
	Sign=0;
}

void CMyDlg::OnDiv() 
{
	// TODO: Add your control notification handler code here
	OnEqual();
	Sign=FDIV;
	Scr_Num=ScrNum;
}

void CMyDlg::OnEqual()
{
	// TODO: Add your control notification handler code here
	double i,n,sum=1;
	Fpoint=0;
	Flag=1;
	if(Sign)
	{
		switch(Sign)
		{
		case FADD:
			ScrNum=Scr_Num+ScrNum;
			break;
		case FSUB:
			ScrNum=Scr_Num-ScrNum;
			break;
		case FMUL:
			ScrNum=Scr_Num*ScrNum;
			break;
		case FDIV:
			if(!ScrNum)
			{
				Sign=0;
				Screen.SetWindowText("除数不能为零。");
				return;
			}
			ScrNum=Scr_Num/ScrNum;
			break;
		case FPOW:
			n=333/ScrNum;
			for(i=0;i<n;i++)
				sum*=10;
			if(Scr_Num>sum)
			{
				Sign=0;
				Screen.SetWindowText("数值溢出范围。");
				return;
			}
			ScrNum=pow(Scr_Num,ScrNum);
			break;
		case FAND:
			ScrNum=(long) Scr_Num & (long) ScrNum;
			break;
		case FOR:
			ScrNum=(long) Scr_Num | (long) ScrNum;
			break;
		case FXOR:
			ScrNum=(long) Scr_Num ^ (long) ScrNum;
			break;
		}
		Sign=0;
		if(FNum!=FNUM10)
		{
			switch(FNum)
			{
			case FNUM16:
				Num10ToNum16((long) ScrNum,ScrText);
				break;
			case FNUM8:
				Num10ToNum8((long) ScrNum,ScrText);
				break;
			case FNUM2:
				Num10ToNum2((long) ScrNum,ScrText);
			}
			ScrLen=(char) LengthOfString(ScrText);
			ScrText[ScrLen]='.';
			ScrText[ScrLen+1]=0;
		}
		else
			DoubleToString(ScrNum,ScrText);
		Screen.SetWindowText(ScrText);
	}
}

void CMyDlg::OnMadd()
{
	// TODO: Add your control notification handler code here
	if(ScrNum)
	{
		MNum+=ScrNum;
		Show.SetWindowText("M+");
	}
}

void CMyDlg::OnMclear()
{
	// TODO: Add your control notification handler code here
	MNum=0;
	Show.SetWindowText("MC");
}

void CMyDlg::OnMread() 
{
	// TODO: Add your control notification handler code here
	if(MNum)
	{
		ScrNum=MNum;
		DoubleToString(ScrNum,ScrText);
		Screen.SetWindowText(ScrText);
		Show.SetWindowText("MR");
	}
}

void CMyDlg::OnMsave() 
{
	// TODO: Add your control notification handler code here
	MNum=ScrNum;
	Show.SetWindowText("MS");
}

void CMyDlg::OnMul() 
{
	// TODO: Add your control notification handler code here
	OnEqual();
	Sign=FMUL;
	Scr_Num=ScrNum;
}

void CMyDlg::OnNeg() 
{
	// TODO: Add your control notification handler code here
	if(Flag)
	{
		ScrNum=0;
		Screen.SetWindowText(" 0.");
	}
	else
	{
		ScrNum=-ScrNum;
		ScrLen=Screen.GetWindowTextLength();
		Screen.GetWindowText(ScrText,ScrLen+1);
		if(ScrNum<0)
		{
			ScrText[0]='-';
		}
		else
		{
			ScrText[0]=' ';
		}
		Screen.SetWindowText(ScrText);
	}
}

void CMyDlg::OnPercent()
{
	// TODO: Add your control notification handler code here
	if(Sign)
	{
		OnEqual();
	}
	DoubleToString(ScrNum*100,ScrText);
	long len=LengthOfString(ScrText);
	ScrText[len]='%';
	ScrText[len+1]=0;
	Screen.SetWindowText(ScrText);
}

void CMyDlg::OnPoint() 
{
	// TODO: Add your control notification handler code here
	Fpoint=1;
	if(Flag)
	{
		ScrNum=0;
		Screen.SetWindowText(" 0.");
	}
}

void CMyDlg::OnReciprocal() 
{
	// TODO: Add your control notification handler code here
	Flag=1;
	if(!ScrNum)
	{
		Screen.SetWindowText("除数不能为零。");
		return;
	}
	if(FNum!=FNUM10)
	{
		ScrText[0]=' ';
		ScrText[1]=ScrNum==1?'1':'0';
		ScrText[2]='.';
		ScrText[3]=0;
	}
	else
	{
		ScrNum=1/ScrNum;
		DoubleToString(ScrNum,ScrText);
	}
	Screen.SetWindowText(ScrText);
}

void CMyDlg::OnSqrt() 
{
	// TODO: Add your control notification handler code here
	Flag=1;
	if(ScrNum<0)
	{
		ScrNum=0;
		Screen.SetWindowText("输入不能为负数。");
		return;
	}
	ScrNum=sqrt(ScrNum);
	DoubleToString(ScrNum,ScrText);
	Screen.SetWindowText(ScrText);
}

void CMyDlg::OnSub() 
{
	// TODO: Add your control notification handler code here
	OnEqual();
	Sign=FSUB;
	Scr_Num=ScrNum;
}

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_CHAR)
	{
		switch(pMsg->wParam)
		{
		case '0':
			Key='0';
			btn0.SendMessage(WM_LBUTTONDOWN);
			break;
		case '1':
			Key='1';
			btn1.SendMessage(WM_LBUTTONDOWN);
			break;
		case '2':
			Key='2';
			btn2.SendMessage(WM_LBUTTONDOWN);
			break;
		case '3':
			Key='3';
			btn3.SendMessage(WM_LBUTTONDOWN);
			break;
		case '4':
			Key='4';
			btn4.SendMessage(WM_LBUTTONDOWN);
			break;
		case '5':
			Key='5';
			btn5.SendMessage(WM_LBUTTONDOWN);
			break;
		case '6':
			Key='6';
			btn6.SendMessage(WM_LBUTTONDOWN);
			break;
		case '7':
			Key='7';
			btn7.SendMessage(WM_LBUTTONDOWN);
			break;
		case '8':
			Key='8';
			btn8.SendMessage(WM_LBUTTONDOWN);
			break;
		case '9':
			Key='9';
			btn9.SendMessage(WM_LBUTTONDOWN);
			break;
		case '+':
			Key='+';
			btnAdd.SendMessage(WM_LBUTTONDOWN);
			break;
		case '-':
			Key='-';
			btnSub.SendMessage(WM_LBUTTONDOWN);
			break;
		case '*':
			Key='*';
			btnMul.SendMessage(WM_LBUTTONDOWN);
			break;
		case '/':
			Key='/';
			btnDiv.SendMessage(WM_LBUTTONDOWN);
			break;
		case '.':
			Key='.';
			btnPoint.SendMessage(WM_LBUTTONDOWN);
			break;
		case '%':
			Key='%';
			btnPercent.SendMessage(WM_LBUTTONDOWN);
			break;
		case '=':
		case VK_RETURN:
			Key='=';
			btnEqual.SendMessage(WM_LBUTTONDOWN);
			break;
		case VK_BACK:
			Key='b';
			btnBackspace.SendMessage(WM_LBUTTONDOWN);
			break;
		case VK_ESCAPE:
			Key='e';
			btnClear.SendMessage(WM_LBUTTONDOWN);
		}
		return FALSE;
	}
	if(pMsg->message==WM_KEYDOWN)
	{
		switch(pMsg->wParam)
		{
		case VK_CONTROL:
			Key='l';
			break;
		case 'V':
			if(Key=='l')
				OnPaste();
			break;
		case 'C':
			if(Key=='l')
				OnCopy();
			else
			{
				Key='C';
				btnC.SendMessage(WM_LBUTTONDOWN);
			}
			break;
		case 'A':
			Key='A';
			btnA.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'B':
			Key='B';
			btnB.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'D':
			Key='D';
			btnD.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'E':
			Key='E';
			btnE.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'F':
			Key='F';
			btnF.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'L':
			Key='L';
			btnLg.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'N':
			Key='N';
			btnLn.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'O':
			Key='O';
			btnCos.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'P':
			Key='P';
			btnPi.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'R':
			Key='R';
			btnReciprocal.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'S':
			Key='S';
			btnSin.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'T':
			Key='T';
			btnTan.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'X':
			Key='X';
			btnExp.SendMessage(WM_LBUTTONDOWN);
			break;
		case 'Y':
			Key='Y';
			btnxStepy.SendMessage(WM_LBUTTONDOWN);
		}
		return FALSE;
	}
	if(pMsg->message==WM_KEYUP)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -