Solved

How can I get a WinForms text control's text string, given a pointer to its CWnd.

Posted on 2014-09-16
6
365 Views
Last Modified: 2014-09-20
I have a Winforms app whose window contains several controls.   From a separate MFC process I need to be able to retrieve the value of one of the text controls in the Winforms app.

I enumerate those controls to get a CWnd pointer for each  one.  That all works fine.

The window has several pushbuttons and several text controls.  On each pushbutton, when I call GetWindowText() I get the pushbutton's caption returned.  As expected.

However when I call GetWindowText() on a text object I get nothing back even though there is clearly a non-null string there.

I'm assuming that one cannot use GetWindowText()  on a Winforms text object but I don't know what I can use that would give me back the text that's stored within a text object.
0
Comment
Question by:allanephillips
  • 3
  • 2
6 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 40327032
I think GetWindowText should work fine. Can you post some code, there could be a problem. Also, can you check that the windows class of your edit controls is a correct one. It should have a value similar to "WindowsForms10.EDIT.app.0.34f5582_r9_ad1" (ignore the last bit, it is always different). It must have "EDIT" in it
0
 
LVL 24

Expert Comment

by:chaau
ID: 40327048
Please note that for normal Winform Edit controls the EDIT window will be a child of the form. If the edit is a toggle EDIT (with up and down arrows) then it will be part of a composite control and the actual EDIT control will be one level below. Check the spy++ for the well know WinForms program below:A WinForm windowIts spy
0
 

Author Comment

by:allanephillips
ID: 40327084
Well the window class that I seem to be seeing is: "WindowsForms10.Window.8.app.0.202c666".  It sounds as though that is not the right one.

When I use spy++ I don't see any descendant window that has ".EDIT" in its class name so it may be that the window that spy++ shows that looks like an edit control really isn't one.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 40327089
it may as well be a "custom control". The developers of the WinForm app may have developed a custom control, or imported an OCX control (e.g. a mask edit control or something). In this case you need to explore some other options, like windows hooking
0
 
LVL 32

Expert Comment

by:sarabande
ID: 40328131
when using spy, you could "search" for the control by dragging the search icon of spy to the text control.

try to get the window handle of the parent window and the id of the text control. then you can do:

HWND hwndTextCtrl == ::GetDlgItem(hwndParent, id);
TCHAR text[1024] = { 0 };
int len = ::GetWindowText(hwndTextCtrl,  text, 1024);

Open in new window


note, the windows form uses utf-16 character set which is called UNICODE by MS. the mfc application might use 'multibyte character set' where the TCHAR is a single char. if that is the case and the GetWindowText returns a positive length but the text seems to be empty, you may try to using WCHAR instead of TCHAR and call the ::GetWindowTextL which could handle wide strings.

Sara
0
 

Author Closing Comment

by:allanephillips
ID: 40334845
The solution really just told me that there is likely no way to get at the data in what's probably a "Custom Control".   I guess I'll have to try to get the data using an OCR converter.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now