📄 liuyf24pointdlg.cpp
字号:
Middle.Format("%d",(int)(strtod(Mul1.GetBuffer(Mul1.GetLength()),&stopstring)/
strtod(Mul2.GetBuffer(Mul2.GetLength()),&stopstring)));
else
Middle.Format("%d",(int)(strtod(Mul1.GetBuffer(Mul1.GetLength()),&stopstring)*
strtod(Mul2.GetBuffer(Mul2.GetLength()),&stopstring)));
Str=Left+Middle+Right;
MulPos=Str.Find('*')+1;
DivPos=Str.Find('/')+1;
First=MulPos;
if(MulPos>DivPos)
First=DivPos;
if(DivPos==0&&MulPos!=0)
{
First=MulPos;
DivPos=2000;
}
if(MulPos==0&&DivPos!=0)
{
First=DivPos;
MulPos=2000;
}
}
First=FirstPos(Str);
if(First==200)
return (int)strtod(Str.GetBuffer(Str.GetLength()),&stopstring);
char Fuhao=FirstF(Str);
while(First)
{
CString tempStr=Str.Mid(0,First-1);
int temp=LastPos(tempStr);
CString Left=Str.Mid(0,temp);
CString Mul1=Str.Mid(temp,First-temp-1);
tempStr=Str.Mid(First,Str.GetLength()-First);
temp=FirstPos(tempStr);
if(temp==200)
{
Mul2=tempStr;
Right=" ";
}
else
{
Mul2=tempStr.Mid(0,temp-1);
Right=tempStr.Mid(temp-1,tempStr.GetLength()-temp+1);
}
if(Fuhao=='+')
Middle.Format("%d",(int)(strtod(Mul1.GetBuffer(Mul1.GetLength()),&stopstring)+
strtod(Mul2.GetBuffer(Mul2.GetLength()),&stopstring)));
else
Middle.Format("%d",(int)(strtod(Mul1.GetBuffer(Mul1.GetLength()),&stopstring)-
strtod(Mul2.GetBuffer(Mul2.GetLength()),&stopstring)));
Str=Left+Middle+Right;
First=FirstPos(Str);
if(First==200)
break;
Fuhao=FirstF(Str);
}
return (int)strtod(Middle.GetBuffer(Middle.GetLength()),&stopstring);
}
//用于计算表达式的结果
int CLiuyf24POINTDlg::TotalCompute(CString Str)
{
int First=Str.ReverseFind('(')+1;
while(First)
{
CString SubStr=Str.Mid(First,(Str.GetLength()-First));
int Last=SubStr.Find(')')+1;
Last+=First;//定位最后一个(号以后的最开始的)号位置
CString Left=Str.Mid(0,First-1);//(号左边的字符串
CString Middle=Str.Mid(First,Last-First-1);//()号中间的字符串
CString Right=Str.Mid(Last,Str.GetLength()-Last);//()号右边的字符串
int Result=SubCompute(Middle);//进入下面的计算
Middle.Format("%d",Result);
Str=Left+Middle+Right;
First=Str.ReverseFind('(')+1;
}
int Result=SubCompute(Str);
return Result;
}//以上为验算部分 下面为总验算
void CLiuyf24POINTDlg::OnCalc()
{
// TODO: Add your control notification handler code here
KillTimer(1);
UpdateData();
int flag=1;
CString Str=M_EDIT;
int First=Str.ReverseFind('(')+1;//里层括号“(”
while(First)
{
CString SubStr=Str.Mid(First,(Str.GetLength()-First));
int Last=SubStr.Find(')')+1;
Last+=First;
CString Left=Str.Mid(0,First-1);
CString Middle=Str.Mid(First,Last-First-1);
CString Right=Str.Mid(Last,Str.GetLength()-Last);
Str=Left+Middle+Right;
First=Str.ReverseFind('(')+1;
}
if(Str=="")
{MessageBox("对不起,你的输入不正确!","错误",MB_OK);flag=0;}//无输入时报警
First=FirstPos(Str);
while(First!=200&&flag)
{
CString tempStr=Str.Mid(0,First-1);
int temp=LastPos(tempStr);
CString Left=Str.Mid(0,temp);
CString Mul1=Str.Mid(temp,First-temp-1);
Str=Str.Mid(First,Str.GetLength()-First);
First=FirstPos(Str);
}
int Result=TotalCompute(M_EDIT);
while(flag)
{
if(Result==24)
{
MessageBox("你真棒!","对了",MB_OK);
UpdateData();
}
else
{
CString temp;
temp.Format("%d",Result);
CString Answer="您输入的结果为"+temp+"!";
MessageBox(Answer,"错了",MB_OK);
}
flag=0;
}
UpdateData(FALSE);
GetDlgItem(IDC_CALC)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO1)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO2)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO3)->EnableWindow(TRUE);
}
void CLiuyf24POINTDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnEnd()
{
// TODO: Add your control notification handler code here
CLiuyf24POINTDlg::OnEnd() ;
}
void CLiuyf24POINTDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnStart()
{
// TODO: Add your control notification handler code here
srand( (unsigned)time( NULL ) );
for(int i=0;i<4;i++)
m_number[i]=rand()%13;//形成四个随机数
((CStatic*)GetDlgItem(IDC_PICTURE0))->SetBitmap(HBITMAP(Bitmap[m_number[0]]));
((CStatic*)GetDlgItem(IDC_PICTURE1))->SetBitmap(HBITMAP(Bitmap[m_number[1]]));
((CStatic*)GetDlgItem(IDC_PICTURE2))->SetBitmap(HBITMAP(Bitmap[m_number[2]]));
((CStatic*)GetDlgItem(IDC_PICTURE3))->SetBitmap(HBITMAP(Bitmap[m_number[3]]));//发牌
SetTimer(1,1000,NULL);
SpendTime=0;
SetDlgItemText(IDC_EDIT1,"");
SetDlgItemText(IDC_EDIT,"小朋友祝你顺利!o(≧v≦)o");
CProgressCtrl*M_PROGRESS=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
M_PROGRESS->SetRange(0,30);
M_PROGRESS->SetPos(0);//设置进度条初始值
int iRADIO=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3);
if(iRADIO==IDC_RADIO1)
{
m_Hardlevel=60;
}
else if(iRADIO==IDC_RADIO3)
{
m_Hardlevel=30;
}
else
{
m_Hardlevel=45;
}//困难级别判断(三个按钮)
m_Score=m_Hardlevel;
GetDlgItem(IDC_RADIO1)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO2)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO3)->EnableWindow(FALSE);//游戏开始后困难级别不可选
GetDlgItem(IDC_CALC)->EnableWindow(TRUE);//游戏重新开始后,验算可用
UpdateData();
}
void CLiuyf24POINTDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);//初始存在
if(nIDEvent==1)
{
CProgressCtrl* M_PROGRESS=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
M_PROGRESS->SetPos(M_PROGRESS->GetPos()+1);
M_PROGRESS->SetRange(0,m_Hardlevel);
if(M_PROGRESS->GetPos()>=m_Hardlevel)
{
KillTimer(nIDEvent);
AfxMessageBox("Time over:-/",MB_OK);
GetDlgItem(IDC_CALC)->EnableWindow(FALSE);
GetDlgItem(IDC_RADIO1)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO2)->EnableWindow(TRUE);
GetDlgItem(IDC_RADIO3)->EnableWindow(TRUE);
}
}
SpendTime++;
CString SSpendTime;
m_Score--;
SSpendTime.Format("%d",SpendTime);
GetDlgItem(IDC_STATIC10)->SetWindowText(""+SSpendTime+"秒");
}
void CLiuyf24POINTDlg::OnStatic10()
{
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnOutofmemoryProgress1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CLiuyf24POINTDlg::OnStatic11()
{
// TODO: Add your control notification handler code here
}
void CLiuyf24POINTDlg::OnAboutbox()
{
// TODO: Add your control notification handler code here
MessageBox("L.F--2009-1-11","LIUYF24PIONT",MB_OK);
}
HBRUSH CLiuyf24POINTDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID()==IDC_EDIT)
{
pDC->SetTextColor(RGB(0,0,255));
pDC->SetBkColor(RGB(0,255,0));
//return m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CLiuyf24POINTDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(::TranslateAccelerator(GetSafeHwnd(),hAccel,pMsg))
return true;
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CLiuyf24POINTDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::OnCommand(wParam, lParam);
}
void CLiuyf24POINTDlg::OnChangeEdit()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -