Solved

Contents of an EditBox

Posted on 2002-03-23
3
1,205 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 92
List out all word 7 291
unix example issues 18 90
Message not shown 5 50
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

776 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