Finding strings in a control and replacing them

I'm having a trouble to figure out how to replace strings in a control. I was trying to use
1
2
Size = GetWindowTextLength(hEdit);
GetDlgItemText(hwnd, IDC_MAIN_EDIT, FileText, Size);
but then I was stuck cause FileText in this case is LPWSTR and not a string so I cant use the function string:find and string:replace.

Is there any other way to go about things so I'd get a content in a string?
You need to learn how to use low level character string buffers, which, when declared can take the following forms (among others)...

TCHAR szBuffer[SOME_NUMBER];
char szBuffer[SOME_NUMBER];
wchar_t szBuffer[SOME_NUMBER];

Here is an example using char...

1
2
3
4
5
6
7
//assume edit control has control id of IDC_EDIT
char szBuffer[256];
HWND hEdit;

hEdit=GetDlgItem(hParent,IDC_EDIT);
GetWindowTextA(hEdit,szBuffer,256);
MessageBoxA(hParent,szBuffer,"Here Is Your Text",MB_OK);
Regardless of how you get your C string, you can create a STL string by means of assignment.

std::string strFile = FileText;

Now you can use find(). There is also a way to use a STL string directly by reserving the needed memory beforehand and passing &strFile[0] to the function.
Last edited on
Topic archived. No new replies allowed.