📄 新二十四点view.cpp
字号:
// 新二十四点View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "新二十四点.h"
#include "stdlib.h"
#include "math.h"
#include "新二十四点Doc.h"
#include "CntrItem.h"
#include "新二十四点View.h"
#include "CalDlg.h"
#include "calculator.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_WM_DESTROY()
ON_WM_SETFOCUS()
ON_WM_SIZE()
ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_GO, OnGo)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_GOCAL, OnGocal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
//
// ipoint 是指+-=()的位置!
// iipoint 是指用户输入的位置!
CMyView::CMyView():ipoint(520,380),iipoint(50,300),PaiPoint(20,30),AnswerPoint(50,300)
{
lrtag=0;
step=0;
FaPai();
m_pSelection = NULL;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/////////show button;
DrawButton(pDC,jia,ipoint);
ipoint.x+=50;
DrawButton(pDC,jian,ipoint);
ipoint.x+=50;
DrawButton(pDC,left,ipoint);
ipoint.x+=50;
DrawButton(pDC,equal,ipoint);
ipoint.y+=50;
ipoint.x-=50;
DrawButton(pDC,right,ipoint);
ipoint.x-=50;
DrawButton(pDC,chu,ipoint);
ipoint.x-=50;
DrawButton(pDC,cheng,ipoint);
ipoint.x+=150;
DrawButton(pDC,goon,ipoint);
//ipoint又回到原来的位置!!
ipoint.x-=150;
ipoint.y-=50;
/////////////show pai
ShowPai();
///////////
CPoint s(490,300);
ShowFonts("按右键求帮助!",40,20,s,255);
///////////
//////////////////////////////////////////
DrawLine(pDC,255,0,0,10,0,250,750,250);
DrawLine(pDC,0,255,0,10,0,260,750,260);
DrawLine(pDC,0,0,255,10,0,270,750,270);
///////////////////////////////////////////////
if (m_pSelection == NULL)
{
POSITION pos = pDoc->GetStartPosition();
m_pSelection = (CMyCntrItem*)pDoc->GetNextClientItem(pos);
}
if (m_pSelection != NULL)
m_pSelection->Draw(pDC, CRect(10, 10, 210, 210));
}
void CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: remove this code when final selection model code is written
m_pSelection = NULL; // initialize selection
}
void CMyView::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
CView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands
BOOL CMyView::IsSelected(const CObject* pDocItem) const
{
// The implementation below is adequate if your selection consists of
// only CMyCntrItem objects. To handle different selection
// mechanisms, the implementation here should be replaced.
// TODO: implement this function that tests for a selected OLE client item
return pDocItem == m_pSelection;
}
void CMyView::OnInsertObject()
{
// Invoke the standard Insert Object dialog box to obtain information
// for new CMyCntrItem object.
COleInsertDialog dlg;
if (dlg.DoModal() != IDOK)
return;
BeginWaitCursor();
CMyCntrItem* pItem = NULL;
TRY
{
// Create new item connected to this document.
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CMyCntrItem(pDoc);
ASSERT_VALID(pItem);
// Initialize the item from the dialog data.
if (!dlg.CreateItem(pItem))
AfxThrowMemoryException(); // any exception will do
ASSERT_VALID(pItem);
if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
pItem->DoVerb(OLEIVERB_SHOW, this);
ASSERT_VALID(pItem);
// As an arbitrary user interface design, this sets the selection
// to the last item inserted.
// TODO: reimplement selection as appropriate for your application
m_pSelection = pItem; // set selection to last inserted item
pDoc->UpdateAllViews(NULL);
}
CATCH(CException, e)
{
if (pItem != NULL)
{
ASSERT_VALID(pItem);
pItem->Delete();
}
AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH
EndWaitCursor();
}
void CMyView::OnCancelEditCntr()
{
// Close any in-place active item on this view.
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
{
pActiveItem->Close();
}
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
// Special handling of OnSetFocus and OnSize are required for a container
// when an object is being edited in-place.
void CMyView::OnSetFocus(CWnd* pOldWnd)
{
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState)
{
// need to set focus to this item if it is in the same view
CWnd* pWnd = pActiveItem->GetInPlaceWindow();
if (pWnd != NULL)
{
pWnd->SetFocus(); // don't call the base class
return;
}
}
CView::OnSetFocus(pOldWnd);
}
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
pActiveItem->SetItemRects();
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{
CPoint ppp(0,300);
CPoint pppp(50,500);
char a[2];
CClientDC dc(this);
//刷屏
int q=1;
if(lrtag==1||step==0)
DrawLine(&dc,255,255,255,200,0,400,410,400);
// TODO: Add your message handler code here and/or call default
ID id=MouseWhere(point);
switch(id)
{
case jia:
expr[step++]='+';
ShowFonts("+",40,14,iipoint);
iipoint.x+=40;
break;
case jian:
expr[step++]='-';
ShowFonts("-",40,14,iipoint);
iipoint.x+=40;
break;
case cheng:
expr[step++]='*';
ShowFonts("*",40,14,iipoint);
iipoint.x+=40;
break;
case chu:
expr[step++]='/';
ShowFonts("/",40,14,iipoint);
iipoint.x+=40;
break;
case left:
expr[step++]='(';
ShowFonts("(",40,14,iipoint);
iipoint.x+=40;
break;
case right:
expr[step++]=')';
ShowFonts(")",40,14,iipoint);
iipoint.x+=40;
break;
case equal:
expr[step++]='=';
ShowFonts("=",40,14,iipoint);
iipoint.x=50;
iipoint.y=300;
expr[step]=NULL;
ShowFonts(expr,40,14,iipoint);
postfix();
DrawLine(&dc,255,255,255,200,0,400,410,400);
if((eval()-24)<0.001&&(eval()-24)>-0.001)
ShowFonts("wonderful",60,20,ppp,255);
else
ShowFonts("error",60,20,ppp,255);
step=0;
break;
case one:
expr[step++]='0';
sprintf(a,"%d",poke[0]);
ShowFonts(a,40,14,iipoint,255);
iipoint.x+=40;
break;
case two:
expr[step++]='1';
sprintf(a,"%d",poke[1]);
ShowFonts(a,40,14,iipoint,0,255);
iipoint.x+=40;
break;
case three:
expr[step++]='2';
sprintf(a,"%d",poke[2]);
ShowFonts(a,40,14,iipoint,0,0,255);
iipoint.x+=40;
break;
case four:
expr[step++]='3';
sprintf(a,"%d",poke[3]);
ShowFonts(a,40,20,iipoint,122,122,122);
iipoint.x+=40;
break;
case goon:
FaPai();
DrawLine(&dc,255,255,255,200,0,400,410,400);
DrawLine(&dc,255,255,255,300,80,70,700,70);
ShowPai();
step=0;
iipoint.x=50;
iipoint.y=300;
break;
}
CView::OnLButtonDown(nFlags, point);
}
ID CMyView::MouseWhere(CPoint point)
{
if(point.x>ipoint.x&&point.x<ipoint.x+40&&point.y>ipoint.y&&point.y<ipoint.y+40)
return jia;
if(point.x>ipoint.x+50&&point.x<ipoint.x+90&&point.y>ipoint.y&&point.y<ipoint.y+40)
return jian;
if(point.x>ipoint.x&&point.x<ipoint.x+40&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
return cheng;
if(point.x>ipoint.x+50&&point.x<ipoint.x+90&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
return chu;
if(point.x>ipoint.x+100&&point.x<ipoint.x+140&&point.y>ipoint.y&&point.y<ipoint.y+40)
return left;
if(point.x>ipoint.x+100&&point.x<ipoint.x+140&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
return right;
if(point.x>ipoint.x+150&&point.x<ipoint.x+190&&point.y>ipoint.y&&point.y<ipoint.y+40)
return equal;
if(point.x>ipoint.x+150&&point.x<ipoint.x+190&&point.y>ipoint.y+50&&point.y<ipoint.y+90)
return goon;
if(point.x>PaiPoint.x&&point.x<PaiPoint.x+100&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
return one;
if(point.x>PaiPoint.x+200&&point.x<PaiPoint.x+300&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
return two;
if(point.x>PaiPoint.x+400&&point.x<PaiPoint.x+500&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
return three;
if(point.x>PaiPoint.x+600&&point.x<PaiPoint.x+700&&point.y>PaiPoint.y&&point.y<PaiPoint.y+200)
return four;
else return none;
}
void CMyView::DrawButton(CDC*pDC,ID id,CPoint ipoint)
{
CBitmap bitmap;
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
switch(id)
{
case jia:
{
bitmap.LoadBitmap(IDB_JIA);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case jian:
{
bitmap.LoadBitmap(IDB_JIAN);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case cheng:
{
bitmap.LoadBitmap(IDB_CHENG);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case chu:
{
bitmap.LoadBitmap(IDB_CHU);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case equal:
{ bitmap.LoadBitmap(IDB_EQUAL);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case left:
{ bitmap.LoadBitmap(IDB_LEFT);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case right:
{ bitmap.LoadBitmap(IDB_RIGHT);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
case goon:
{ bitmap.LoadBitmap(IDB_GOON);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(ipoint.x,ipoint.y,40,40,&dcMemory,0,0,SRCCOPY);
break;
}
}
}
void CMyView::ShowFonts(char * a,int lfHeight,int lfwidth,CPoint point,int red,int green,int blue)
{
CClientDC dc(this);
LOGFONT logfont;
CFont font;
logfont.lfHeight=lfHeight;
logfont.lfWidth=lfwidth;
logfont.lfEscapement=0;
logfont.lfOrientation=0;
logfont.lfWeight=FW_NORMAL;
logfont.lfItalic=0;
logfont.lfUnderline=0;
logfont.lfStrikeOut=0;
logfont.lfCharSet=ANSI_CHARSET;
logfont.lfOutPrecision=OUT_DEFAULT_PRECIS;
logfont.lfClipPrecision=CLIP_DEFAULT_PRECIS;
logfont.lfQuality=PROOF_QUALITY;
logfont.lfPitchAndFamily=VARIABLE_PITCH|FF_ROMAN;
strcpy(logfont.lfFaceName,"Times New Roman");
font.CreateFontIndirect(&logfont);
CFont *oldfont=dc.SelectObject(&font);
dc.SetTextColor(RGB(red,green,blue));
dc.TextOut(point.x,point.y,a);
dc.SelectObject(oldfont);
}
void CMyView::FaPai()
{
for(int i=0;i<4;i++)
{
for(int j=0;j<10;j+=rand()%8)
{
rand();
}
poke[i]=rand()%12+1;
}
}
int CMyView::Algorithum(short poke[4])
{
CClientDC dc(this);
CPoint point=AnswerPoint;
int a[4];//用来表示四个数的标号;
int b[3];//用来表示三个符号;
double ra[4];
char istring[20];
int i=0;
int tag=0;
int count=0;
int p=0;
m_sArray.RemoveAll();
/////////////////////////////////////////////////////////////
for(a[0]=0;a[0]<4;a[0]++)
{
for(a[1]=0;a[1]<4;a[1]++)
{
if(a[0]==a[1])
continue;
for(a[2]=0;a[2]<4;a[2]++)
{
if(a[2]==a[0]||a[2]==a[1])
continue;
for(a[3]=0;a[3]<4;a[3]++)
{
if(a[3]==a[2]||a[3]==a[1]||a[3]==a[0])
continue;
for(i=0;i<4;i++)
{
ra[i]=poke[a[i]]+0.0;
}
for(b[0]=0;b[0]<4;b[0]++)
for(b[1]=0;b[1]<4;b[1]++)
for(b[2]=0;b[2]<4;b[2]++)
{
for(i=0;i<4;i++)
{
ra[i]=poke[a[i]]+0.0;
}
//(((a0b0a1)b1a2)b2a3)
tag=0;
for(i=0;i<3;i++)
{
switch(b[i])
{
case 0: ra[i+1]=ra[i]+ra[i+1];break;
case 1: ra[i+1]=ra[i]-ra[i+1];break;
case 2: ra[i+1]=ra[i]*ra[i+1];break;
case 3:
if(fabs(ra[i+1])>0.0001)
ra[i+1]=ra[i]/ra[i+1];
else
tag=1;
break;
}
if(tag==1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -