problem with setwindowtext()
-
hi, i am writing a program that stores data into a text file i specify in the form of a class object. when i initialize the window where i can edit this data, i have a combo box that reads the file and inserts part of the object(the name of each class object) into the combo box. than i select the name and when i hit the button to edit the data for that particular object i am trying to have my program insert each part of the class into its own text box but when i try to do this my program completely crashes without any information as to why. i tried to push the values of the variables into a buffer and than use setwindowtext but it would still crash which i have done else where in my program without any bit of trouble.
-
hi, i am writing a program that stores data into a text file i specify in the form of a class object. when i initialize the window where i can edit this data, i have a combo box that reads the file and inserts part of the object(the name of each class object) into the combo box. than i select the name and when i hit the button to edit the data for that particular object i am trying to have my program insert each part of the class into its own text box but when i try to do this my program completely crashes without any information as to why. i tried to push the values of the variables into a buffer and than use setwindowtext but it would still crash which i have done else where in my program without any bit of trouble.
Can you show your code that has error_**
**_
whitesky
-
Can you show your code that has error_**
**_
whitesky
sure not a problem, i will post the whole function, hope that will be enough to help solve the issue.
afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); }
all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code). -
sure not a problem, i will post the whole function, hope that will be enough to help solve the issue.
afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); }
all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).You might try putting a breakpoint on this line and see if pNameText is NULL (which it probably is):
CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME);
GetDlgItem will return NULL if it can't find the control with the specified ID. The symbol might exist in your resource file, so no compile time error, but check the specific control in the resource editor and make sure it is assigned an ID of IDC_ENAME.
- S 50 cups of coffee and you know it's on!
-
sure not a problem, i will post the whole function, hope that will be enough to help solve the issue.
afx_msg void CEditDialog::OnEdit() { elements s; int size = sizeof(elements); bool found = false; //MessageBox(" This Area is Still under Construction", "Debug", MB_ICONINFORMATION); CComboBox *pSelection; pSelection = (CComboBox *)GetDlgItem(IDC_SELECTION); CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); CEdit *pSymbolText; pSymbolText = (CEdit *) GetDlgItem(IDC_ESYMBOL); CEdit *pAtomicText; pAtomicText = (CEdit *) GetDlgItem(IDC_EATOMIC); CEdit *pPeriodText; pPeriodText = (CEdit *) GetDlgItem(IDC_EPERIOD); CEdit *pGroupText; pGroupText = (CEdit *) GetDlgItem(IDC_EGROUP); CEdit *pElectronText; pElectronText = (CEdit *) GetDlgItem(IDC_EELECTRON); int iCurSel = pSelection->GetCurSel(); if(iCurSel == CB_ERR) { MessageBox(" Please Select an Item.", "Error", MB_ICONWARNING); return; } char lpszText[32]; pSelection->GetLBText(iCurSel, lpszText); access.Open(file, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite); do{ access.Read(reinterpret_cast< char * > (&s), sizeof(elements)); MessageBox(lpszText, "debug", MB_ICONINFORMATION); if(strcmp(s.element, lpszText) == 0) { access.Seek(-(long)size, CFile::current); MessageBox("Found", "debug", MB_ICONINFORMATION); found = true; pNameText->SetWindowText("test"); } }while(found != true); access.Close(); }
all the code works as expected except the setwindowtext, anythign i put for it to output causes a crash(please excuse my sloppy code).you said this code has problem
CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); pNameText->SetWindowText("test");
Do you have IDC_ENAME in your program and is this CEdit_**
**_
whitesky
-
You might try putting a breakpoint on this line and see if pNameText is NULL (which it probably is):
CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME);
GetDlgItem will return NULL if it can't find the control with the specified ID. The symbol might exist in your resource file, so no compile time error, but check the specific control in the resource editor and make sure it is assigned an ID of IDC_ENAME.
- S 50 cups of coffee and you know it's on!
or maybe i guess IDC_ENAME isnt CEdit_**
**_
whitesky
-
you said this code has problem
CEdit *pNameText; pNameText = (CEdit *) GetDlgItem(IDC_ENAME); pNameText->SetWindowText("test");
Do you have IDC_ENAME in your program and is this CEdit_**
**_
whitesky
you know...i went back to check the ids and names of controls as you said to do...noticed that some how the names of controls in another window were being used in that window so i changed them to what they needed to be and well it works fine, now to see if i can get it to do what i need(which should be no problem at all.) thank you so much :).
-
or maybe i guess IDC_ENAME isnt CEdit_**
**_
whitesky
That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.
- S 50 cups of coffee and you know it's on!
-
That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.
- S 50 cups of coffee and you know it's on!
you right(of course in this thread it seems that my guess is ture)and i think he find problem.:)and i agree with GetDlgItem is returning null_**
**_
whitesky