You are here:

C++/text of a window with known HWND


 Hello sir,
 I have the handle of a window(e.g. an edit box). How can I get it's text(i.e the text of this window)?
 thank you very much.

mohammad , Thank you for your question.

If this is an EDIT control, it stores its text in its caption (title) buffer. Use the 'GetWindowTextLength' function to get the length of the text, allocate a buffer of size one greater than that number (for the terminating NUL character), then call the 'GetWindowText' function to copy the text into the buffer. Don't forget to deallocate the buffer when you are finished using it.

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.