Solved

Contents of an EditBox

Posted on 2002-03-23
3
1,213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:gandalf79
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;
 }
 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
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

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
ID: 6892213
It worked perfect.

Thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

615 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