Contents of an EditBox

Posted on 2002-03-23
Medium Priority
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);


The problem is the GetDlgItemText returns NULL.


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

Question by:Smave

Expert Comment

ID: 6891961
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;
  // TODO: code your application's behavior here.
  CString strHello;
  cout << (LPCTSTR)strHello << endl;
  //here is where I want to 'cout' the contents of the fields in
  //the table
  BTable* pBTbl1 = new BTable(NULL);
  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;
  delete pBTbl1;
 return nRetCode;

Accepted Solution

Yechezkel earned 400 total points
ID: 6891989
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


(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.)

Author Comment

ID: 6892213
It worked perfect.

Thank you!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

597 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