Solved

Getting text from a one line CEdit Control

Posted on 1998-07-13
7
235 Views
Last Modified: 2013-11-20
How do you get the text out of a CEdit Control?  I have tried using GetWindowText but that always returns NULL.
I am using add printer wizard and am trying to get the name of the printer on about the 5th page  I've used spy++ and have been able to get a handle to the CEdit window, then I  called Getline off of that, and it works in Debug mode but not release.  Any ideas on how to solve this so I can get the text

Thanks
0
Comment
Question by:curtisn
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 2

Expert Comment

by:jstolan
ID: 1319088
It's not obvious is it?  I struggled for over half a day the first time I had to do this.  The answer is

CString cszBuffer;
int iCnt = m_ctrlEditShow.GetLine(0,cszBuffer.GetBuffer(10),10);
cszBuffer.ReleaseBuffer();

In this case I knew I never needed more than 10 characters, you may need to change that slightly
0
 
LVL 2

Expert Comment

by:jstolan
ID: 1319089
I should add that I used the GetDlgItem function to attach the CEdit m_ctrlEditShow member variable to the Edit box of interest.  I'd be very careful using spy to get the handle, I think that will vary from run to run.
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319090
My favorite answer is to assign a CString member variable to it and call UpdateData( TRUE ) to retrieve the data.

Phillip

0
Technology Partners: 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!

 

Author Comment

by:curtisn
ID: 1319091
Now for the tricky part, I don't have the resource for this edit control.  I get the handle to some unknown window and there is an edit control in it, I've tried the method from jstolan but I can't get that to work.  Can I assign the CString to it if I don't own it?
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319092
Absolutely.  If you can get a CWnd* to it, and you know it's a CEdit, then cast it to a CEdit*.

Phillip

0
 
LVL 2

Accepted Solution

by:
warmcat earned 100 total points
ID: 1319093
Sometimes you have to go behind the back of MFC :)  Remember that under the hood it's an old-stype Windows API Edit Control as well as a potential attached CEdit.

Try using SendMessage to the edit control handle with WM_GETTEXT.  Definition of WM_GETTEXT:

An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.

WM_GETTEXT
wParam = (WPARAM) cchTextMax;   // number of characters to copy
lParam = (LPARAM) lpszText;     // address of buffer for text
 
Parameters
cchTextMax

Value of wParam. Specifies the maximum number of characters to be copied, including the terminating null character.

lpszText

Value of lParam. Points to the buffer that is to receive the text.

Return Values
The return value is the number of characters copied.

Default Action
The DefWindowProc function copies the text associated with the window into the specified buffer and returns the number of characters copied.

Remarks
For an edit control, the text to be copied is the content of the edit control. For a combo box, the text is the content of the edit control (or static-text) portion of the combo box. For a button, the text is the button name. For other windows, the text is the window title. To copy the text of an item in a list box, an application can use the LB_GETTEXT message.

When the WM_GETTEXT message is sent to a static control with the SS_ICON style, the handle of the icon will be returned in the first four bytes of the buffer pointed to by lpszText. This is true only if the WM_SETTEXT message has been used to set the icon.


0
 

Author Comment

by:curtisn
ID: 1319094
Thanks that was what I needed, I tried all those other ways but they just wouldn't work, I'll have to remember to go in the back side of MFC

curtis
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 129
Perl Awk Need Help 3 145
Generic progress indicator 6 121
pre4 challenge 19 115
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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