WM_GETTEXT

I'm using EnumChildWindwos to find the control I'm looking for, then read the caption of the control using WM_GETTEXT.

1
2
3
4
5
6
7
8
9
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam) {

	TCHAR param[1000];
	LONG lResult;
	char display[1024] = "";
	lResult = SendMessage(hwnd,WM_GETTEXT,1000,(LPARAM)display);
	printf(display);
     return true; // must return TRUE; If return is FALSE it stops the recursion
}

That does indeed find the control, but it only returns the First character of the char array, obviously i don't know enough of how to get the full string out. Can I get some help with syntax?
closed account (DSLq5Di1)
Likely due to mixing c-string data types, webJose wrote a nice post on the issue that I think you should read:- http://www.cplusplus.com/forum/general/56526/#msg304164

1
2
3
TCHAR display[1024] = "";
lResult = SendMessage(hwnd,WM_GETTEXT,1024,(LPARAM)display);
_tprintf(display);
I think sloppy9 pretty much nailed this because WM_GETTEXT is below WM_USER and therefore the OS will do all the memory marshaling, and I suspect it also does ANSI/UNICODE conversion as well.

BUT if this weren't the case, you may want to consider the IsWindowUnicode() function http://msdn.microsoft.com/en-us/library/windows/desktop/ms633529(v=vs.85).aspx . This can tell you if the target window is a Unicode window and explicitly use a wchar_t buffer to receive the text.

But then again, I think it won't be needed. Most likely the modifications made by sloppy9 are sufficient.
Topic archived. No new replies allowed.