1. IDC_STATIC1:
void CCStatic2Dlg::OnStatic1()
{
// TODO: Add your control notification handler code here
CString str;
GetDlgItem(IDC_STATIC1)->GetWindowText(str);
if("Hello,World!"==str)
{
GetDlgItem(IDC_STATIC1)->SetWindowText("Visual C++!");
}
if("Visual C++!"==str)
{
GetDlgItem(IDC_STATIC1)->SetWindowText("I like C++");
}
if("I like C++"==str)
{
GetDlgItem(IDC_STATIC1)->SetWindowText("Hello,World!");
}
}
2.
BOOL CRadio_Button1Dlg::OnInitDialog()中的代码:CheckRadioButton(IDC_RADIO1,IDC_RADIO3,IDC_RADIO1);
3.
BOOL CButton3Dlg::OnInitDialog()中的代码:
CheckRadioButton(IDC_RADIO1,IDC_RADIO3,IDC_RADIO3);
CButton *ptn=(CButton *)GetDlgItem(IDC_CHECK1);
ptn->SetCheck(1);
在void CButton3Dlg::OnOK()
{
// TODO: Add extra validation here
CString str,strCtrl;
int i;
str="您的年级:";
UINT nID1=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3);
GetDlgItemText(nID1,strCtrl);
str=str+strCtrl;
str=str+"/n你最喜欢的课程:";
UINT nID2[4]={IDC_CHECK1,IDC_CHECK2,IDC_CHECK3,IDC_CHECK4};
CButton *ptn;
for(i=0;i<4;i++)
{
ptn=(CButton *)GetDlgItem(nID2[i]);
if(1==ptn->GetCheck())
{
ptn->GetWindowText(strCtrl);
str=str+strCtrl;
str=str+" ";
}
}
MessageBox(str);
// CDialog::OnOK();
}
4.
void CCstatic1Dlg::OnOK()
{
if (static1.m_hWnd)
{
static1.DestroyWindow();
}
else
{
static1.Create("生成的新的静态文本框",WS_CHILD|WS_VISIBLE,CRect(0,0,200,30),this,11);
}
// CDialog::OnOK();
}
5.
void CCShrinkView::OnShrink()
{
// TODO: Add your command handler code here
CShrink_Dlg* pt1=new CShrink_Dlg;
pt1->DoModal();
}
void CShrink_Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str;
GetDlgItemText(IDC_BUTTON1,str);
if("收缩<<"==str)
SetDlgItemText(IDC_BUTTON1,"扩展>>");
else
SetDlgItemText(IDC_BUTTON1,"收缩<<");
static CRect rectLarge;
static CRect rectSmall;
if(rectLarge.IsRectNull())
{
CRect temp;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SHRINK)->GetWindowRect(&temp);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.right=rectLarge.right;
rectSmall.bottom=temp.top;
}
if(str=="收缩<<")
{
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),SWP_NOMOVE|SWP_NOZORDER);
}
else
{
SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),SWP_NOMOVE|SWP_NOZORDER);
}
}
6.
BOOL CCEdit_6Dlg::OnInitDialog()中的:
CTime time;
time=CTime::GetCurrentTime();
m_time=time.Format("%x--%X");
UpdateData(FALSE);
void CCEdit_6Dlg::OnTimer(UINT nIDEvent)
{
CTime time;
time=CTime::GetCurrentTime();
m_time=time.Format("%Y-%m-%d %H:%M:%S");
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
7.
只有一个例子,其它的仿照
void CCEdit4Dlg::OnGreenRadio3()
{
colour = RGB(0,255,0);
m_edit.SetFocus();
}
8.
class CColorEdit : public CEdit自己新创了一个类
HBRUSH CColorEdit::CtlColor(CDC* pDC, UINT nCtlColor)
{
// TODO: Change any attributes of the DC here
CDC* dc = GetDC(); //获取画布对象
CRect rect;
GetClientRect(rect); //获取客户区域
rect.InflateRect(3,3,3,3);//将客户区域增大3个像素
CBrush brush (m_color);//创建画刷
dc->FrameRect(rect,&brush);//绘制边框
// TODO: Return a non-NULL brush if the parent's handler should not be called
return NULL;
}
void CColorEdit::SetColorEdit(COLORREF color)
{
m_color=color;
}//m_color是CColorEdit的一个成员函数
BOOL CCEdit_5Dlg::OnInitDialog()中的
m_edit1.SetColorEdit(RGB(255,0,0));
m_edit2.SetColorEdit(RGB(0,0,255));
9.
void CCEdit_1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str;
UpdateData(TRUE);
if((strcmp(m_name,"张三")==0)&&(strcmp(m_password,"1113")==0))
str="密码正确,登陆成功!";
else if((strcmp(m_name,"")==0)||(strcmp(m_password,"")==0))
str="请输入用户名或密码:";
else
str="用户名或密码错误:";
MessageBox(str);
}
10.
void CCEdit_2Dlg::OnChangeEdit1()
{
UpdateData(TRUE);
// m_write="d/nyyy";
m_read=m_write;
UpdateData(FALSE);
}
11.
CSpinButtonCtrl m_spinage;
BOOL CSpinButtonDlg::OnInitDialog()中的:
m_spinage.SetRange(1,100);
m_spinage.SetBase( 0 );
void CSpinButtonDlg::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_age=m_age+(float)pNMUpDown->iDelta;
if(m_age<0) m_age=0;
if(m_age>10) m_age=10;
UpdateData(FALSE);
*pResult = 0;
}
void CSpinButtonDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
CString str;
char *temp=new char;
itoa(m_age,temp,10);
str="结果显示:/n姓名:";
str+=m_name;
str+="/n年龄:";
str+=temp;
str+="/n年级:";
str+=m_class;
str+="/n电话:";
str+=m_phone;
MessageBox(str);
//CDialog::OnOK();
}