Solved

Contents of an EditBox

Posted on 2002-03-23
3
1,193 Views
Last Modified: 2013-11-20
I have an MFC project where the main form is based on CDAORecordView.

The EditBox's ID is: IDC_EDIT_CurrentRecord
its value member variable is long m_CurrentRecord.
its control member variable is CEdit m_CurrentRecordCTRL.

As I use the record selectors in the toolbar I have use the GetAbsolutePosition function to update the m_CurrentRecord member variable.

During runtime, when I change the value of the EditBox I want the form to Move to the record number in the EditBox.

The following code compiles with no errors.

void CTheoFrontEndView::OnKillfocusEDITCurrentRecord()
{
     // TODO: Add your control notification handler code here
     CString strTemp;
     m_CurrentRecordCTRL.GetDlgItemText(IDC_EDIT_CurrentRecord, strTemp);

     m_pSet->SetAbsolutePosition(atol(strTemp));
}

The problem is the GetDlgItemText returns NULL.
Why?

also

How can I get the contents of the EditBox independant of its member variable?
or
Am I approching this problem all wrong?

Dave
0
Comment
Question by:Smave
3 Comments
 
LVL 2

Expert Comment

by:gandalf79
Comment Utility
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
 int nRetCode = 0;
 
 // initialize MFC and print and error on failure
 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
 {
  // TODO: change error code to suit your needs
  cerr << _T("Fatal Error: MFC initialization failed") << endl;
  nRetCode = 1;
 }
 else
 {
  // TODO: code your application's behavior here.
  CString strHello;
  strHello.LoadString(IDS_HELLO);
  cout << (LPCTSTR)strHello << endl;
 
  //here is where I want to 'cout' the contents of the fields in
  //the table
  BTable* pBTbl1 = new BTable(NULL);
  if(!pBTbl1->IsOpen())
   pBTbl1->Open();
 
  cout << "PrimeKey: " << pBTbl1->m_PrimeKey << endl;
  cout << "Book Title: " << (LPCTSTR)pBTbl1->m_BookTitle << endl;
  cout << "Book Number: " << pBTbl1->m_BookNumber << endl;
  cout << "Chapter: " << pBTbl1->m_Chapter << endl;
  cout << "Verse: " << pBTbl1->m_Verse << endl;
  cout << "English: " << (LPCTSTR)pBTbl1->m_1769_Authorized << endl;
  cout << "Non-English: " << (LPCTSTR)pBTbl1->m_NotEnglish << endl;
 
  pBTbl1->Close();
  delete pBTbl1;
 }
 
 return nRetCode;
}
0
 
LVL 1

Accepted Solution

by:
Yechezkel earned 100 total points
Comment Utility
The function CWnd::GetDlgItemText is used when you only have the object representing the window containing the control. It gives the contents of a control contained within the window. So

m_CurrentRecordCTRL.GetDlgItemText(IDC_EDIT_CurrentRecord, strTemp);

is trying to get the contents of a control with the ID IDC_EDIT_CurrentRecord which is a child of your edit control. Since your edit control has no child controls you can't get any result.

When you actually have the control which you want to get the contents of, simply use the function CWnd::GetWindowText.

So replace the line above with

m_CurrentRecordCTRL.GetWindowText(strTemp);

(Note, by the way, the result you are getting is not NULL (which is supposed to be a pointer) but the integer value 0, because you are getting 0 characters returned.)
0
 

Author Comment

by:Smave
Comment Utility
It worked perfect.

Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
iSeries FTP Exit Program 8 113
only14 challenge 19 63
NotAlone Challenge 20 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now