Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSettings Files Pin
Peter Liddle25-Aug-01 7:46
Peter Liddle25-Aug-01 7:46 
GeneralRe: Settings Files Pin
Ravi Bhavnani25-Aug-01 7:58
professionalRavi Bhavnani25-Aug-01 7:58 
GeneralRe: Settings Files Pin
Anders Molin25-Aug-01 9:01
professionalAnders Molin25-Aug-01 9:01 
GeneralRe: Settings Files Pin
Carlos Antollini25-Aug-01 10:35
Carlos Antollini25-Aug-01 10:35 
GeneralRe: Settings Files Pin
Christian Graus25-Aug-01 12:16
protectorChristian Graus25-Aug-01 12:16 
GeneralGetWindowText and processes Pin
25-Aug-01 3:05
suss25-Aug-01 3:05 
GeneralRe: GetWindowText and processes Pin
Paolo Messina25-Aug-01 5:53
professionalPaolo Messina25-Aug-01 5:53 
GeneralRe: GetWindowText and processes Pin
Paul A. Howes25-Aug-01 8:33
Paul A. Howes25-Aug-01 8:33 
I was just working on a program that needs to do what you are asking. The problem here, is that you do not know how much text is in the control in order to read it. To exaserbate the problem further, you cannot get a pointer to the buffer that holds the text, because different controls keep the text in different places.

The solution is to send a pair of messages to the window you want to extract text from. The first queries the window for the size of the text it contains, and the second retrieves the text. Some sample code:

//  hWnd is the handle of the window you want to query.
int len = ::SendMessage( hWnd, WM_GETTEXTLENGTH, 0, 0 ) + 1;
TCHAR* text = new TCHAR[len];
::SendMessage( hWnd, WM_GETTEXT, len, LPARAM( text ) );
//  ... Do something with the text ...
delete[] text;


Adding one(1) to the length is important, because the WM_GETTEXTLENGTH message does not include the terminating null character in the length. Using the TCHAR type will allow your code to compile on both ANSI and Unicode environments.

One caveat: You cannot extract the text of a password-protected edit field on Win2k and WinXP. Microsoft finally plugged that little security problem Smile | :)


--
Paul

"I drank... WHAT?"
GeneralKeyboard Oem scan codes Pin
24-Aug-01 22:36
suss24-Aug-01 22:36 
QuestionMakeing changes to static text background color and text color?? Pin
Bryan Tyson24-Aug-01 21:46
Bryan Tyson24-Aug-01 21:46 
AnswerRe: Makeing changes to static text background color and text color?? Pin
Michael Dunn24-Aug-01 21:50
sitebuilderMichael Dunn24-Aug-01 21:50 
GeneralRe: Makeing changes to static text background color and text color?? Pin
Bryan Tyson24-Aug-01 22:13
Bryan Tyson24-Aug-01 22:13 
GeneralRe: Makeing changes to static text background color and text color?? Pin
Michael Dunn24-Aug-01 22:16
sitebuilderMichael Dunn24-Aug-01 22:16 
GeneralComposite Control Pin
KingsGambit24-Aug-01 20:53
KingsGambit24-Aug-01 20:53 
Generalregarding flexgrid and mfc dialog based Pin
Cnoob24-Aug-01 18:23
Cnoob24-Aug-01 18:23 
GeneralSimple Toolbar Question. Pin
Mike Doner24-Aug-01 17:33
Mike Doner24-Aug-01 17:33 
GeneralRe: Simple Toolbar Question. Pin
Ben Burnett24-Aug-01 18:00
Ben Burnett24-Aug-01 18:00 
QuestionConvert FILETIME to DATE for ADO ? Pin
Christian Graus24-Aug-01 16:35
protectorChristian Graus24-Aug-01 16:35 
AnswerRe: Convert FILETIME to DATE for ADO ? Pin
Ben Burnett24-Aug-01 16:48
Ben Burnett24-Aug-01 16:48 
AnswerRe: Convert FILETIME to DATE for ADO ? Pin
Carlos Antollini24-Aug-01 16:55
Carlos Antollini24-Aug-01 16:55 
GeneralADO/ATL problems - my life is hell. Pin
Christian Graus24-Aug-01 16:32
protectorChristian Graus24-Aug-01 16:32 
GeneralRe: ADO/ATL problems - my life is hell. Pin
Carlos Antollini24-Aug-01 16:49
Carlos Antollini24-Aug-01 16:49 
GeneralRe: ADO/ATL problems - my life is hell. Pin
Christian Graus24-Aug-01 17:03
protectorChristian Graus24-Aug-01 17:03 
GeneralRe: ADO/ATL problems - my life is hell. Pin
Carlos Antollini24-Aug-01 17:11
Carlos Antollini24-Aug-01 17:11 
GeneralRe: ADO/ATL problems - my life is hell. Pin
Christian Graus24-Aug-01 17:27
protectorChristian Graus24-Aug-01 17:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.