初学MFC按钮控件

 学了才知道,都是一些类的调用,关系就是继承居多。以下是学习的一些心得体会:

1.我的程序编译后出现错误提示:fatal error C1083: Cannot open precompiled header file: 'Debug/li2201.pch': No such file or directory
执行 cl.exe 时出错.
还是codeguru网站上的人牛逼,我也遇到同样的问题,经过指点解决了。
你点击工具栏Project->Settings->C/C++,在Category下拉菜单中选Precompiled Headers之后,点击下面的单选按钮Not using precompiled headers,确定即可。
2.265也有详细的毕业设计的流程,我现在的差距在编不出函数,还是C++没有精通的问题,我需要多练练数组,指针,类继承等等。
7
   第三章,vC+100,1212

3.F2换文件名,先指向再按。
4.设计程序时用面向对象还是过程,可以考虑下。
   congst+=5.的理解,即是增加5,*=5即是增加5倍。
5.this指针千万莫乱用,不好控制。
发信人: thatboy (thatboy), 信区: Program
标  题: Re: C++疑惑
发信站: 幽幽黄桷兰BBS (Fri Apr 16 11:28:00 2010), 站内
 
#include <iostream.h> 
 
class complex 

private: 
    double real; 
    double imag; 
public: 
    complex(double r=0.0,double i=0.0){real=r;imag=i;} 
 
    //complex operator-(complex c2); 
 
    complex complex::operator-(const complex& c2);
 
    friend complex operator+(const complex& c1, const complex& c2);
    void display(); 
 
 
    complex(const complex& org)
    {
        this->real = org.real;
        this->imag = org.imag;
        cout<<"复制构造函数"<<endl;
    }
 
    ~complex()
    {
        cout<<"析构函数"<<endl;
    }
 
    complex& operator-=(const complex& org)//这个版本的话本身就要变 比如c1 -= c2,那么c1就变了的
    {
        this->real=this->real-org.real; 
        this->imag=this->imag-org.imag; 
        return *this; 
    }
 
    complex& operator=(const complex& org)
    {
        this->real = org.real;
        this->imag = org.imag;
        return *this;
    }
}; 
 
//complex complex::operator-(complex c2) //这个不对 重载后的版本  如果调用-的话 本身的值也变了 不符合逻辑 看你下面c1 和 c3的值是不是一样了 逻辑上c1是不能变的
//{ 
//    this->real=this->real-c2.real; 
//    this->imag=this->imag-c2.imag; 
//    return *this; 
//}
 
 
//complex operator +(complex c1,complex c2) //栈里面的局部对象能返回么? 退出函数 自动就回收了。
//{complex c; 
//c.real=c1.real+c2.real; 
//c.imag=c1.imag+c2.imag; 
//return c; 
//} 
 
//complex& operator+(const complex& c1, const complex& c2) //也许这个版本是对的,至少从结果上看,这个是对的,但是有new 没有delete内存泄漏!!!严重的问题 或许你说delete下就OK嘛,但是在什么地方delete呢?
//{complex* c = new complex(c1); 
//(*c).real=c1.real+c2.real; 
//(*c).imag=c1.imag+c2.imag; 
//return *c; 
//} 
 
//complex& complex::operator-(const complex& c2)//与+号相同的解释
//{
//    complex* tmp = new complex(*this);
//    *tmp -= c2;
//    return *tmp;
//}
 
complex operator+(const complex& c1, const complex& c2) //或许只有这样做了,至于为什么??。。。。我们需要新的值,但又不改变原来的值,但还得返回新的值,但还得释放内存,这么多但是! 但是你的明白这是为什么。。
{
    return complex(c1.real+c2.real, c1.imag+c2.imag);

 
complex complex::operator-(const complex& c2)//与+号相同的解释
{
    return complex(this->real-c2.real, this->imag-c2.imag);
}
 
 
void complex::display() 

    cout<<"("<<real<<","<<imag<<")"<<endl; 

int main( ) 
 

    complex c1(5,4),c2(2,10),c3,c4; 
    cout<<"c1="; 
    c1.display(); 
    cout<<"c2="; 
    c2.display(); 
 
//    c1 -= c2;
//    c1.display();
 
    c3=c1-c2; 
    cout<<"c3=c1-c2="; 
    c3.display(); 
    c4=c1+c2; 
    cout<<"c4=c1+c2="; 
    c4.display(); 
    return 0; 

6.怎样给文件夹添加头文件呢
7.对话框:
  模态的(在关闭之前不能执行其他任务),非模态的。cdialoy-cwnd-ccndtamget-cobject.
  对资源的操作通过一个类,新建一个类classwizard;资源上双击;在newclass的栏里输入类的名字。ctest中c是作为类的标识。模态对话框的创建:domodal创建,enddialog关闭模态对话框。非模态对话框:creat,并要调用showwindow把窗口显示出来。getdlgitem()获取控件指针,getwindowtext获得文本,setwindowtest设置文本。style-nodify-使静态文本响应点击信息。getdilitem()获取控件指针,atoi转换。
关联m(以后,控件就有初值,且被构造)-ddx(dodatachange)-void
CMy34Dlg::OnAdd()
{
 // TODO: Add your control notification handler code here
 int num1,num2,num3;
 char ch1[10],ch2[10],ch3[10];
 GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
 GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
    
 num1=atoi(ch1);
 num2=atoi(ch2);
  num3=num1+num2;
 itoa(num3,ch3,10);

 GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);

 


}

void CMy34Dlg::OnNumber1()
{
 // TODO: Add your control notification handler code here
 CString str;
 if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str),str=="Number1")
 {
  GetDlgItem(IDC_NUMBER1)->SetWindowText("数值1");
 }
 else
 {
  GetDlgItem(IDC_NUMBER1)->SetWindowText("Number1");
 }

}
第二种:void CMy34Dlg::OnAdd()
{
 // TODO: Add your control notification handler code here
 int num1,num2,num3;
 char ch1[10],ch2[10],ch3[10];
 GetDlgItemText(IDC_EDIT1,ch1,10);
 GetDlgItemText(IDC_EDIT2,ch2,10);
    
 num1=atoi(ch1);
 num2=atoi(ch2);
  num3=num1+num2;
 itoa(num3,ch3,10);

 SetDlgItemText(IDC_EDIT3,ch3);

 


}
第三种:void CMy34Dlg::OnAdd()
{
 // TODO: Add your control notification handler code here
 int num1,num2,num3;
 char ch1[10],ch2[10],ch3[10];
 num1=GetDlgItemInt(IDC_EDIT1);
 num2=GetDlgItemInt(IDC_EDIT2);

 
  num3=num1+num2;


 SetDlgItemInt(IDC_EDIT3,num3);

 


}支持有符号的数值计算
第四种:成员变量法
dodatachangge,不直接调用,需先嗲用updatedata函数,当一个模态框创建时自动调用flase,完成初始化,获取数据就需要设置为true,即();
当输入的数不是关联的数时候,就会弹出一个框,提示出错。
第五种:控件变量void CMy34Dlg::OnAdd()
{
 // TODO: Add your control notification handler code here
 int num1,num2,num3;
 char ch1[10],ch2[10],ch3[10];
   m_edit1.GetWindowText(ch1,10);
   m_edit2.GetWindowText(ch2,10);
  
   num1=atoi(ch1);
   num2=atoi(ch2);
   num3=num1+num2;
   itoa(num3,ch3,10);

   m_edit3.SetWindowText(ch3);

 


}第六种:消息wm_settext.wm_gettext.::SendMessage.
第七种:发送消息SendDlgItemMessage.
 SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);

8.设置焦点:SetFocus.EM_SETSEL复选,0,-1全部复选。
9.对话框的伸缩与扩展:首先是控件文本的变换
void CMy34Dlg::OnButton2()
{
 // TODO: Add your control notification handler code here
 CString str;
 if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
 {
  SetDlgItemText(IDC_BUTTON2,"扩展");
 }
 else
 {
        SetDlgItemText(IDC_BUTTON2,"收缩<<");
 }
}
CRect类成员函数,isrectEmpty(是否为空),isrectnull(检查坐标)均可用来判断是否为空。
GetWindowRect获得窗口矩形局域。
分割线用图画框代替。rect矩形,getwindowrect获取矩形区域,SetWindowPos函数
void CMy34Dlg::OnButton2()
{
 // TODO: Add your control notification handler code here
 CString str;
 if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
 {
  SetDlgItemText(IDC_BUTTON2,"扩展");
 }
 else
 {
        SetDlgItemText(IDC_BUTTON2,"收缩<<");
 }
  static CRect rectLarge;
 static CRect rectSmall;
 
if(rectLarge.IsRectNull())
{
 CRect rectSeparator;
 GetWindowRect(&rectLarge);
 GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);

 rectSmall.left=rectLarge.left;
 rectSmall.top=rectLarge.top;
 rectSmall.right=rectLarge.right;
 rectSmall.bottom=rectSeparator.bottom;
}
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);
}
10.把输入焦点转变,按回车就跳转到下一个编辑框。从写一个窗口过程。
11.cDlg从cDialog派生,app从CWinApp派生。
   到处乱跑的小按键:先新建两个相同的按键,可以在框架右键font改变字体.首先捕获鼠标移动的消息,有对话框来捕获可不可以呢?我们想要的功能是在按钮上移动,并不是对话框,所以应该用按键来捕获,新建一个按键类,CWeiXinBin,然后将控件分别关联一个变量m_button1,m_button2.即创建CWeiXinBin的对象。由于是新建的类,需要在头文件中说明#include"WeiXinBin.h".增加消息处理,Mousemove,编辑处理。在其内部完成消息处理函数,完成功能。移动时候调用showwindow。获取控件指针,就是在CWeiXinBin类定义一个变量,即一个指针,用于放对方的地址。地址互相交换一下,这样每个对象内部指针,保存了对方的地址。在onInitDialog内部添加地址交换的函数。然后在消息处理函数中去调用showwindow,

        CWeiXinBin *m_pBin;

        CWeiXinBin m_button3;
 CWeiXinBin m_button1;


 m_button1.m_pBin=&m_button3;
 m_button3.m_pBin=&m_button1;

void CWeiXinBin::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 ShowWindow(SW_HIDE);
 m_pBin->ShowWindow(SW_SHOW);
 CButton::OnMouseMove(nFlags, point);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值