我基于MFC建了一个名为EasyCoding的基本对话框工程,在CEasyCodingDlg类中添加两个按钮如下
protected:
int bw,bh;  //按钮长宽
CButton cb1,cb2;
两个按钮分别用来打开一个新的对话框,这两个按钮以及新对话框的操作功能已经完成并可以成功运行。
但是,当我添加第三个按钮cb3时,如下
protected:
int bw,bh;  //按钮长宽
CButton cb1,cb2,cb3;
编译运行,退出后就会提示出错消息……之前做一个工程的时候也出现过类似的问题,我把新按钮的定义放在对应类Cpp文件作为全局变量定义就可以解决(不会再提示出错),但这个我在每个按钮对应的弹出对话框中定义有一个返回主对话框的返回按钮。一旦我将打开子对话框的按钮以全局变量方式在主对话框cpp中定义后,点击子对话框的返回按钮就会报错。这个报错和我重复使用CButton::Create的报错有些类似。所以:1.会否是在子对话框点击返回时出现的重新Create的问题呢?但我打开对话框的方式是先OnOK()关闭自己再定义新对话框DoModel(),所以说是返回,其实是新建一个类的对象,感觉应该不会出现重新定义的问题啊?2.VC中的控件变量在使用完后需要用某些函数删除么?用那些函数呢?就CButton举例,用我们自己去类似DeleteObject或者ReleaseDC那样释放内存空间么?3.回到最初的问题,我多添加了一个cb3就会出错,而在用相同方式添加cb1,cb2的时候就没有问题,我真的表示很费解,如果是内存资源问题难道说一两个按钮的声明就占用完我的内存了么?还是在主对话框添加成员变量本来就不合理呢?望高手指点。4.问题3会否是我这个VC的某个bug呢?你们有遇到过类似的情况么?求高手……各位大侠快来啊!

解决方案 »

  1.   

    “自行添加按钮”就这么一句?
    CButton cb1,cb2,cb3;
    应该没有问题。
    什么错误?
      

  2.   

    主对话框的定义(.h)文件,按钮的定义就在最后两行,目前我在此对应的.cpp文件中有按钮cb3,cb4,cb5的定义,所以我把按钮定义CButton cb1,cb2;改为CButton cb1,cb2,cb6;但此时再编译就会直接弹出出错信息,说是我的应用程序已经停止工作。class CEasyCodingDlg : public CDialog
    {
    // Construction
    public:
    void MyPaint(HDC hdc);
    CEasyCodingDlg(CWnd* pParent = NULL); // standard constructor// Dialog Data
    //{{AFX_DATA(CEasyCodingDlg)
    enum { IDD = IDD_EASYCODING_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CEasyCodingDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    HICON m_hIcon; // Generated message map functions
    //{{AFX_MSG(CEasyCodingDlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnCoding1();
    afx_msg void OnCoding2();
    afx_msg void OnCoding3();
    afx_msg void OnCoding4();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    protected:
    CRgn m_rgnWnd;
    protected:
    int bw,bh;  //按钮长宽
    CButton cb1,cb2;
    };
      

  3.   

    主对话框的.cpp文件,其中包含因类成员不能再定义而定义的全局按钮以及按钮的初始化,响应消息等// EasyCodingDlg.cpp : implementation file
    //#include "stdafx.h"
    #include "EasyCoding.h"
    #include "EasyCodingDlg.h"#include "CodingDlg1.h"
    #include "CodingDlg2.h"
    #include "CodingDlg3.h"
    #include "CodingDlg4.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endifHBITMAP bg,bmp;
    HDC hdc, mdc, bufdc;
    int width,height;
    CButton cb3,cb4,cb5;/////////////////////////////////////////////////////////////////////////////
    // CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CEasyCodingDlg dialogCEasyCodingDlg::CEasyCodingDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CEasyCodingDlg::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CEasyCodingDlg)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }void CEasyCodingDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CEasyCodingDlg)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }BEGIN_MESSAGE_MAP(CEasyCodingDlg, CDialog)
    //{{AFX_MSG_MAP(CEasyCodingDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(100,OnCoding1)
    ON_BN_CLICKED(101,OnCoding2)
    ON_BN_CLICKED(102,OnCoding3)
    ON_BN_CLICKED(103,OnCoding4)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CEasyCodingDlg message handlersBOOL CEasyCodingDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here SetWindowText(_T("Coding")); //取得屏幕的宽,搞
    int cxScreen = ::GetSystemMetrics(SM_CXSCREEN);
    int cyScreen = ::GetSystemMetrics(SM_CYSCREEN); int nEllipseWidth = cxScreen/2;
    int nEllipseHeight = cyScreen/2;
    width = nEllipseWidth;
    height = nEllipseHeight; //将窗口大小设置为宽nEllipseWidth,高nEllipseHeight并移动至屏幕中心
    MoveWindow(nEllipseWidth/2,nEllipseHeight/2,nEllipseWidth,nEllipseHeight); //创建圆角矩形区域
    m_rgnWnd.CreateRoundRectRgn(0,0,nEllipseWidth,nEllipseHeight,50,50); //将m_rgnWnd设置为窗口区域
    SetWindowRgn((HRGN)m_rgnWnd,TRUE); //DC
    hdc = (HDC)*(GetDC());
    mdc = CreateCompatibleDC(hdc);
    bufdc = CreateCompatibleDC(hdc); bmp = CreateCompatibleBitmap(hdc,800,600);
    SelectObject(mdc,bmp); bg = (HBITMAP)LoadImage(NULL,"res/bg.bmp",IMAGE_BITMAP,800,600,LR_LOADFROMFILE); bw = 100;
    bh = 50;
    CRect rect(20,20,20+bw,20+bh);
    //按钮初始化
    cb1.Create("Caesar密码",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,100);
    rect.left+=120;
    rect.right+=120;
    cb2.Create("单表代换",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,101);
    rect.left+=120;
    rect.right+=120;
    cb3.Create("playfair密码",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,102);
    rect.left+=120;
    rect.right+=120;
    cb4.Create("Hill密码",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,103);
    rect.left+=120;
    rect.right+=120;
    cb5.Create("playfair密码",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,104);
    rect.left   = 20;
    rect.right  = 120;
    rect.top    += 65;
    rect.bottom += 65; return TRUE;  // return TRUE  unless you set the focus to a control
    }void CEasyCodingDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.void CEasyCodingDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    MyPaint(hdc);
    // TextOut(hdc,100,100,"张电福吃鸡鸡",strlen("张电福吃鸡鸡"));
    CDialog::OnPaint();
    }
    }// The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CEasyCodingDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }void CEasyCodingDlg::MyPaint(HDC hdc)
    {
    SelectObject(bufdc,bg);
    BitBlt(mdc,0,0,800,600,bufdc,0,0,SRCCOPY);

    StretchBlt(hdc,0,0,width,height,mdc,0,0,800,600,SRCCOPY);}void CEasyCodingDlg::OnCoding1()
    {
    OnOK();
    CCodingDlg1 dlg;
    dlg.DoModal();
    }void CEasyCodingDlg::OnCoding2()
    {
    OnOK();
    CCodingDlg2 dlg;
    dlg.DoModal();
    }void CEasyCodingDlg::OnCoding3()
    {
    OnOK();
    CCodingDlg3 dlg;
    dlg.DoModal();
    }void CEasyCodingDlg::OnCoding4()
    {
    OnOK();
    CCodingDlg4 dlg;
    dlg.DoModal();
    }
      

  4.   

    子对话框CCodingDlg1.h(子对话框模式基本相同,只是其中某些变量和使用算法不同,因此只举例其中一个)class CCodingDlg1 : public CDialog
    {
    // Construction
    public:
    CCodingDlg1(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CCodingDlg1)
    enum { IDD = IDD_CODING_DIALOG };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CCodingDlg1)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CCodingDlg1)
    virtual BOOL OnInitDialog();
    afx_msg void OnReturn();
    afx_msg void OnDecode();
    afx_msg void OnCoding();
    afx_msg void OnSubmission();
    afx_msg void OntCoding();
    afx_msg void OnHelp();
    afx_msg void OnPaint();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    private:
    CButton m_bReturn;   //返回
    CButton m_help;      //帮助
    CButton m_bDecode;   //解密游戏
    bool m_bd;
    CButton m_bCoding;   //加密文件 
    bool m_bc; CEdit m_text;        //解密中的编辑框
    CEdit m_eLoc;       //加密中的文件位置
    CString m_sLoc;     //对应上边edit
    CButton m_bApply;    //提交
    CButton m_tCoding;   //文件加密 CString m_str;    //要加密的明文
    int m_key;        //密钥
    int m_state;      //解密状态(0待解密,1破译,2破译失败)
    };
      

  5.   

    晕……一个用回只能连续回复3次……而一次回复的字数有限制……所以……我等了……
    子对话框CCodingDlg1.cpp// CodingDlg1.cpp : implementation file
    //#include "stdafx.h"
    #include "EasyCoding.h"
    #include "CodingDlg1.h"#include "EasyCodingDlg.h"
    #include "CodeFunctions.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/*********************************************************
    返回     100
    解密游戏 101
      文本框     110
      提交按钮   111
    文本加密 102
      
    *********************************************************//////////////////////////////////////////////////////////////////////////////
    // CCodingDlg1 dialogCCodingDlg1::CCodingDlg1(CWnd* pParent /*=NULL*/)
    : CDialog(CCodingDlg1::IDD, pParent)
    {
    //{{AFX_DATA_INIT(CCodingDlg1)
    // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    }
    void CCodingDlg1::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CCodingDlg1)
    // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CCodingDlg1, CDialog)
    //{{AFX_MSG_MAP(CCodingDlg1)
    ON_BN_CLICKED(100,OnReturn)
    ON_BN_CLICKED(101,OnDecode)
    ON_BN_CLICKED(102,OnCoding)
    ON_BN_CLICKED(103,OnHelp)
    ON_BN_CLICKED(111,OnSubmission)
    ON_BN_CLICKED(121,OntCoding)
    ON_WM_PAINT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CCodingDlg1 message handlersBOOL CCodingDlg1::OnInitDialog() 
    {
    CDialog::OnInitDialog();

    // TODO: Add extra initialization here
    //取得屏幕的宽,搞
    int cxScreen = ::GetSystemMetrics(SM_CXSCREEN);
    int cyScreen = ::GetSystemMetrics(SM_CYSCREEN); //区域宽高
    int w = cxScreen/2;
    int h = cyScreen/2; //窗口设定,居中
    MoveWindow(w/2,h/2,w,h,true);
    SetWindowText("Caesar密码"); //设定返回按钮
    m_bReturn.Create("返回主界面",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(550,280,650,330),this,100);
    m_bDecode.Create("解密游戏",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(220,10,310,60),this,101);
    m_bCoding.Create("文本加密",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(320,10,410,60),this,102);
    m_help.Create("帮助",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(10,10,100,60),this,103);

    m_bd = 0;   //解密游戏未创建
    m_bc = 0;   //加密喂创建
    m_sLoc = "res/1.txt";
    m_state = 0; return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }void CCodingDlg1::OnReturn()
    {
    OnOK();
    CEasyCodingDlg dlg;
    dlg.DoModal();
    }void CCodingDlg1::OnDecode()
    {
    int tx,ty;
    char str[100];
    int  n;
    srand(GetTickCount());
    n = rand()%TEXTNUM+1;     //选取第n条文本加密
    CString bufstr,codestr; //读文件,失败返回
    FILE *fp;
    if(!(fp = fopen("res/text.txt","r")) )
    return; //读具体明文
    while(n>0)
    {
    fscanf(fp,"%s",str);  //读一行
    n--;
    }
    //读完关闭文件
    fclose(fp);
    m_str = str; //生成密钥
    m_key = rand()%26;
    //对m_str进行加密处理,产生密文
    ::CaesarCoding(m_str, codestr,m_key); CDC *pDC = GetDC(); //清除另一模块
    if(m_bc)
    {
    m_eLoc.ShowWindow(SW_HIDE);
    m_tCoding.ShowWindow(SW_HIDE);
    } tx = 150;
    ty = 80;
    //清空文字区域
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    pDC->TextOut(150,280,"                                                                                 ");
    ty+=30; tx = 150;
    ty = 80;
    //贴密文
    bufstr = "密文:"+codestr+"                           ";
    pDC->TextOut(tx,ty,bufstr);
    ty+=30; //贴密钥
    bufstr.Format("密钥:%d",m_key);
    pDC->TextOut(tx,ty,bufstr);
    ty+=30; //输入明文
    pDC->TextOut(tx,ty,"请输入你解出的明文:");
    ty+=30;
    if(!m_bd)
    {
    //创建资源
    //输入文本框
    m_text.Create(WS_CHILD | WS_VISIBLE,CRect(tx,ty,tx+300,ty+15),this,110);
    ty+=60; //提交按钮
    m_bApply.Create("提交",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(tx+100,ty,tx+200,ty+25),this,111); m_bd = true;
    } else {
    m_text.ShowWindow(SW_SHOW);
    m_bApply.ShowWindow(SW_SHOW);
    } ReleaseDC(pDC);
    }void CCodingDlg1::OnCoding()
    {
    int tx,ty;
    char str[30];
    int  n;
    srand(GetTickCount());
    n = rand()%TEXTNUM+1;     //选取第n条文本加密
    CString bufstr,codestr; //隐藏
    if(m_bd)
    {
    m_text.ShowWindow(SW_HIDE);
    m_bApply.ShowWindow(SW_HIDE);
    } CDC *pDC = GetDC(); tx = 150;
    ty = 80;
    //清空文字区域
    pDC->TextOut(tx,ty,"******************************************************");
    ty+=30;
    pDC->TextOut(tx,ty,"******************************************************");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    ty+=30;
    pDC->TextOut(tx,ty,"                                                                                 ");
    pDC->TextOut(150,280,"                                                                                 "); tx = 150;
    ty = 80;
    ty+=60;
    pDC->TextOut(tx,ty,"请在下一行输入需要加密的txt文件目录:");
    ty+=30; if(!m_bc)
    {
    m_eLoc.Create(WS_CHILD | WS_VISIBLE,CRect(tx,ty,tx+300,ty+15),this,120);
    GetDlgItem(120)->SetWindowText(m_sLoc);
    ty+=60; m_tCoding.Create("文件加密",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(tx+100,ty,tx+200,ty+25),this,121);
    m_bc = true;
    ty-=60;
    } else {
    m_eLoc.ShowWindow(SW_SHOW);
    m_tCoding.ShowWindow(SW_SHOW);
    }
    ReleaseDC(pDC);}void CCodingDlg1::OnSubmission()
    {
    CString str;
    GetDlgItem(110)->GetWindowText(str); CDC *pDC = GetDC();
    if(::IsMatching(m_str,str))
    {
    //破译
    m_state = 1;
    pDC->TextOut(150,280,"                         破译成功!!!                          ");
    } else {
    //未破译
    m_state = 2;
    pDC->TextOut(150,280,"                         破译失败……                            ");
    }
    ReleaseDC(pDC);
    }void CCodingDlg1::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here
    // Do not call CDialog::OnPaint() for painting messages
    }void CCodingDlg1::OntCoding()
    {
    FILE *fp1,*fp2;
    CString loc,codestr;
    int tx,ty;
    GetDlgItem(120)->GetWindowText(loc); CDC*pDC = GetDC();
    //读文件1明文
    if(!(fp1 = fopen(loc,"r")) )
    {
    pDC->TextOut(150,280,"                 待加密文件打开失败!!!                  ");
    return;
    }
    fscanf(fp1,"%s",m_str);
    fclose(fp1); //文件加密
    srand(GetTickCount());
    m_key = rand()%26;
    ::CaesarCoding(m_str,codestr,m_key); //获得有密文及密钥的文件2
    if(!(fp2 = fopen("res/2.txt","w")) )
    {
    pDC->TextOut(150,280,"                      加密文件失败!!!                       ");
    return;
    }
    fprintf(fp2,"%s",codestr);
    fprintf(fp2,"\n密钥%d",m_key);
    fclose(fp2); //加密成功
    tx = 150;
    ty = 80;
    ty+=120;
    pDC->TextOut(tx,ty,"加密后的文件:当前目录/res/2.txt");
    pDC->TextOut(150,280,"                      文件加密成功!!!                       ");
    ReleaseDC(pDC);
    }
    void CCodingDlg1::OnHelp()
    {
    ShellExecute(NULL, NULL, "caesarcode.txt", NULL,NULL, SW_SHOWNORMAL); 
    }楼上的朋友们:
    1.有提到为什么不直接添加按钮而用代码,这个一方面我想熟悉下按钮的底层机制,另一方面用代码添加按钮的话对按钮位置的布局和修改感觉会方便一些,而且之前我在直接添加按钮或者其他控件的时候也出现过类似的问题:多添加一个控件就会出错。当然,我添加控件的对话框是系统建立的主对话框,不知道是否因为是系统建立而对控件数量有什么限制……
    2.关于ID冲突,我在不同的子对话框中确实使用了相同的ID,不过在只创建了按钮1和按钮2并把两个按钮对应的子对话框连接已经实现的时候,并没有出现任何的问题。
    4.谢谢大家的热心和出谋划策!
      

  6.   

    应该说不算报错,就是运行时会提示应用程序停止工作的对话框,不是编译器报错
    标题是EasyCoding Mecrosoft基础类应用程序
    内容是:
    EasyCoding Microsoft 基础类应用程序 已停止工作
    Windows 可以联机检查该问题的解决方案
    -》联机检查解决方案并关闭程序
    -》关闭程序
    -》调试程序
    查看问题的详细信息而我添加了全局的按钮变量后,在点击子对话框的返回按钮时又会弹出一个错误对话框
    具体内容为:
    左上角有一个大差号,错误内容是:
    Debug Assertion Failed!Program:..学\个人设计\密码学\EasyCoding1.4Hill密码\Debug\EasyCoding.exe
    File:wincore.cpp
    Line:639For infomation on how your program can cause an assertion
    failure, see the Visual C++ documentation on asserts.(Press Retry to debug the application)
    然后右下角是 终止,重试,忽略 三个按钮