Originally posted by Ken Fitlike
>>char *szBuffer;<<
I hope you've allocated memory for that before using it...
To get the length of the text use GetWindowTextLength and then use new/malloc to allocate sufficient memory.
Then use GetWindowText as described by msdn and clarified by JasonD.
edit: On second thoughts, this is nonsense:
>>GetWindowText(hEdit, szBuffer, sizeof(hEdit));<<
So do something like this instead:
Code:
int TxtLen=GetWindowTextLength(hEdit);
TCHAR *buffer=new TCHAR[TxtLen+1]; /*or use malloc if you prefer */
GetWindowText(hEdit,buffer,TxtLen);
//do stuff with 'buffer'
delete [] buffer; /* or use free if you used malloc */
Ok, that gets what I need, now, where the '//do stuff w/ 'buffer'' is, I'd do all the seeking and stuff, right?
<< EDIT >>: Ok, here's my code:
Code:
int GetText()
{
int TxtLen=GetWindowTextLength(hEdit);
if(TxtLen == 0)
{
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpError,
0,
NULL);
szError=new char[strlen(lpError) + 128];
strcpy(szError, lpError);
strcat(szError, "While using GetWindowTextLength");
MessageBox(NULL, szError, "Error", MB_ICONERROR);
return 1;
}
else
{
TCHAR *buffer=new TCHAR[TxtLen+1]; /*or use malloc if you prefer */
TCHAR *buff = new TCHAR[TxtLen];
GetWindowText(hEdit,buffer,TxtLen);
SendMessage(hEdit, EM_GETLINE, 0, (LPARAM)buff);
if(buff == "'{$PBASIC 2.0}")
{
SendMessage(hEdit, EM_SETSEL, 0, 0);
SendMessage(hEdit, EM_REPLACESEL, (WPARAM)true, (LPARAM)"'{$PBASIC 2.5}");
}
//Log what GetWindowText gets from the buffer
FILE *log;
log = fopen("log.txt", "w");
fprintf(log, "");
fprintf(log, "%s", buffer);
fclose(log);
delete [] buff;
delete [] buffer; /* or use free if you used malloc */
}
return 0;
}
No errors or nothing (AFAIK) are happening, but it will not replace. I think it deals w/ the SET & REPLACE parts.