?
Solved

Getting text from a one line CEdit Control

Posted on 1998-07-13
7
Medium Priority
?
254 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

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 400 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

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.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

762 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