//类CPerson的定义
class CPerson
{
private:
char strName[20]; //
char cSex; //性别
short nAge; //年龄
public:
CPerson(char *strName,char cSex,short nAge)
{
strcpy(this->strName,strName);
this->cSex=cSex;
this->nAge=nAge;
}
void Display()
{
cout<<":"<
cout<<"性别:"<<(cSex=='m'||cSex=='M'?"男":"女")< cout<<"年龄:"< }
};
//派生类的定义格式
class CStudent:public CPerson
{
};
//按下鼠标左键,累计左键单击次数
m_nLeft++;
CString strOutput;
strOutput.Format("左键单击次数:%d",m_nLeft); //m_nLeft是在视图类添加的成员,类型int
MessageBox(strOutput);
//按下鼠标左键开始画图
m_bdraw = true; //m_bdraw为添加的类成员,bool型
m_prepoint = point; //m_prepoint为添加的类成员,CPoint型,保存前一个点
//释放鼠标左键停止画图
m_bdraw =false;
//沿鼠标移动轨迹画图
CDC* pDC = GetDC();
if (m_bdraw)
{
pDC->MoveTo(m_prepoint);
pDC->LineTo(point);
m_prepoint = point;
}
//释放鼠标左键画矩形
CDC* pDC = GetDC();
pDC->Rectangle(m_prepoint.x,m_prepoint.y,point.x,point.y);
//释放鼠标右键画椭圆
CDC* pDC = GetDC();
pDC->Ellipse(m_prepoint.x,m_prepoint.y,point.x,point.y);
//m_nCoins初始化,为文档类中添加的int型成员
void CDrawCoinDoc::DeleteContents()
{
m_nCoins=0; // 初始化成员变量
......
}
//硬币数量减1
void CDrawCoinDoc::OnCoinSub()
{
if(m_nCoins>0) m_nCoins--; // 硬币数量减一
UpdateAllViews(NULL); //刷新视图
}
//在视图类的OnDraw函数中实现画硬币
for(int i=0;im_nCoins;i++)
{
int y=200-10*i;
pDC->Ellipse(200,y,300,y-30); // 用两个偏移的椭圆表示一枚硬币
pDC->Ellipse(200,y-10,300,y-35);
}
//在状态栏显示硬币数量
CString strCoins;
CStatusBar* pStatus=(CStatusBar*)AfxGetApp()->m_pMainWnd-> // 获得主窗口指针
GetDescendantWindow(ID_VIEW_STATUS_BAR); // 获得状态栏的指针
if(pStatus)
{
strCoins.Format("硬币:%d", pDoc->m_nCoins); // 设置要显示的信息
pStatus->SetPaneText(1, strCoins); // 显示硬币数量
}
//在状态栏显示鼠标位置
CString str;
CMainFrame* pframe = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar* pstatus = &;pframe->m_wndStatusBar;
if (pstatus)
{
str.Format("X=%d, Y=%d",point.x,point.y);
pstatus->SetPaneText(1,str); //在添加的第2个窗格中显示
}
//单击“输入半径”菜单弹出对话框
CRadirsDialog dlg;
dlg.m_nRadius=100;
if (dlg.DoModal()==IDOK)
{
m_nCViewRadius=dlg.m_nRadius;
Invalidate();
}
//在视图类的OnDraw函数中实现显示一行文本或画圆
if(m_bDraw) //m_bDraw为视图类添加的bool型成员,表示显示文本或画圆,在构造函数中初始化为false
{
pDC->TextOut(10,10,"111 张三");
}
else
{
pDC->Ellipse(0,0,m_nRadius,m_nRadius); //m_nRadius为视图类
添加的int型成员表示半径,在构造函数中初始化为0
}
//刷新视图
Invalidate();
//在InitInstance()函数中显示用户身份确认对话框,并验证用户名和口令是否正确
int nCount=0;
while(nCount<3)
{
CPasswordDlg PassDlg;
if(PassDlg.DoModal()==IDOK)
if((strcmp(PassDlg.m_strUserName,"111")!=0)||(strcmp(PassDlg.m_strPassword,"222")!=0))
{
MessageBox(NULL,"用户名或口令错误,请重试!","错误信息",MB_OK|MB_ICONERROR);
nCount++;
}
else
break;
else
{
return FALSE;
}
}
if(nCount>=3)
{
MessageBox(NULL,"口令输入已经超过3次,请退出!","错误信息",MB_OK|MB_ICONERROR);
return FALSE;
}
//取单选按钮值
UpdateData();
UINT m_id=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2);
GetDlgIte