Archived

This topic is now archived and is closed to further replies.

ELS1

WM_GETTEXT help

Recommended Posts

hmm...how come this doesnt work:
  
char* CButtonControl::GetText()
{
	char* buffer = NULL ;
	int length ;

	length = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0) ;
	SendMessage(hwnd, WM_GETTEXT, length, (LPARAM)buffer) ;

	return buffer ;

}
[source]  

Share this post


Link to post
Share on other sites
From the documentation for WM_GETTEXT:

quote:

An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.



The most important part to observe in the above is "a buffer provided by the caller"

You already get the length using GETTEXTLENGTH so you know how big to make the buffer, so just after that do something like:

buffer = new char[length];

and then remember to delete[] that buffer when the caller of your function has finished with it.


If CButtonControl inherits from any MFC classes, make sure that the hWnd is valid (use CWnd::GetSafeHwnd).

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites