Home > Software engineering >  MFC non-modal dialog window click on the button corresponding event control failure suddenly
MFC non-modal dialog window click on the button corresponding event control failure suddenly

Time:09-23

Void CChemStudioView: : OnAddatom ()
{
Dialog_AddAtom: : CreateDlg (this);
}






Void Dialog_AddAtom: : CreateDlg (CWnd * WND)
{
If (dlg_ptr==NULL)
{
Dlg_ptr=new Dialog_AddAtom ();
Dlg_ptr - & gt; Create (IDD_ADDATOMDLG, WND);
Dlg_ptr - & gt; ShowWindow (SW_SHOW);
}
The else return;
}

Void Dialog_AddAtom: : CloseDlg ()
{
Dlg_ptr - & gt; DestroyWindow ();
The delete dlg_ptr;
Dlg_ptr=NULL;
}

Bool Dialog_AddAtom: : IsOpen ()
{
Return dlg_ptr;
}

//Dialog_AddAtom message handler


BOOL Dialog_AddAtom: : OnInitDialog ()
{
CDialogEx: : OnInitDialog ();
CONTROLINIT (atomInput IDC_ATOMIPT);
CONTROLINIT (colorRect IDC_COLORCHOICE);
CONTROLINIT (atomWtDisp IDC_ATOMWTDISP);
CONTROLINIT (atomLbDisp IDC_ATOMLBDISP);
int index=0;
Cstrings STR.
For (cstrings I: CAtom: : ElementSymbol)
{
STR. The Format (" % d % s ", index, I);
AtomInput - & gt; AddString (STR);
Index++;
}
AtomInput - & gt; SetCurSel (0);
Cstrings s;
S. ormat (" atomic weight: % 2 f, "CAtom: : ElementWt [atomInput - & gt; GetCurSel ()");
AtomWtDisp - & gt; SetWindowText (s);
S. ormat (" atom name: % s ", CAtom: : ElementLabel [atomInput - & gt; GetCurSel () ");
AtomLbDisp - & gt; SetWindowText (s);
The CDC * pDC=colorRect - & gt; GetDC ();
CRect RCT.
ColorRect - & gt; GetWindowRect (& amp; RCT);
CBrush BRS.
BRS. CreateSolidBrush (RGB (0, 0, 0));
CRect picrct;
Picrct. Top=0;
Picrct. Left=0;
Picrct. Bottom=RCT. Height ();
Picrct. Right=RCT. Width ();
PDC - & gt; FillRect (& amp; Picrct, & amp; BRS);
Result. AtomNo=CAtom: : Unknown;
Result. The color=RGB (0, 0, 0);
//TODO: add additional initialization here

return true;//return TRUE unless you set the focus to a control
//exception: OCX property page should return FALSE
}

Void Dialog_AddAtom: : OnBnClickedBtnapply ()
{
CAtom: : AtomNum no=CAtom: : Unknown;
Cstrings s;
AtomInput - & gt; GetWindowText (s);
for (int i=0; I & lt;=118; I++)
{
Cstrings independence idx;
Independence idx. The Format (" % d ", I);
Cstrings parse;
The parse. The Format (" % d % s ", I, CAtom: : ElementSymbol [I]);
If ((CAtom: : ElementSymbol [I]==s) | | (independence idx==s) | | (parse==s))
{
No=(CAtom: : AtomNum) I;
break;
}
}
S. ormat (" atom name: % s ", CAtom: : ElementLabel [no]);
AtomLbDisp - & gt; SetWindowText (s);
S. ormat (" atomic weight: % 2 f, "CAtom: : ElementWt [no]);
AtomWtDisp - & gt; SetWindowText (s);
Result. The atomNo=no;
}

Void Dialog_AddAtom: : OnClose ()
{
//TODO: add the message handler code and/or invoke the default

CDialogEx: : OnClose ();
CloseDlg ();
}


After clicking the button:

The DEBUG an ASSERTION FAILED!

All controls all into 0 XDDDD... Initdialog already through macro definition GetDlgItem (before), please explain

CodePudding user response:

The header file:
# include "CAtom. H"

The class Dialog_AddAtom: public CDialogEx
{
DECLARE_DYNAMIC (Dialog_AddAtom)

Public:
Struct AtomInfo
{
COLORREF color;
CAtom: : AtomNum atomNo;
};


Protected:
CComboBox * atomInput;
CStatic * atomWtDisp;
CStatic * atomLbDisp;
CStatic * colorRect;
The static Dialog_AddAtom * dlg_ptr;
AtomInfo result;
Public:
PParent Dialog_AddAtom (CWnd *=nullptr);//standard constructor
Virtual ~ Dialog_AddAtom ();
Public:
The static void CreateDlg (CWnd * WND);
The static void CloseDlg ();
The static bool IsOpen ();

//data dialog
# ifdef AFX_DESIGN_TIME
Enum {IDD=IDD_ADDATOMDLG};
# endif

Protected:
Virtual void DoDataExchange (CDataExchange * symbol;//support DDX/DDV

DECLARE_MESSAGE_MAP ()
Public:
Virtual BOOL OnInitDialog ();
Afx_msg void OnStnClickedColorchoice ();
Afx_msg void OnBnClickedBtnapply ();
Afx_msg void OnClose ();
};

CodePudding user response:

Learn how to use data breakpoints:
 # include & lt; Time. H> 
#include
#include
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]

Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep(100);
B (11) (a=rand () %]=1;
Sleep(100);
B (11) (a=rand () %]=2;
Sleep(100);
B (11) (a=rand () %]=3;
Sleep(100);
B (11) (a=rand () %]=4;
Sleep(100);
}
Return 0;
}
  • Related