[MFC] lost trying to retrieve text from an editBox
Dear All,
I am struggling trying to understand how to retrieve text from an edit box. My view class has the following variables associated to an edit box and a static label:
CEdit inputEditBox;
CStatic flippedNameStaticVar;
I have also set a method associated to the text change in the edit box:
afx_msg void OnEnChangeInputeditbox();
Now, I would like to perform the "simple" task of showing the input provided in the edit box into the static label (flippedNameStatiVar).
Unfortunately I am lost..
I am using Visual Studio 2008 Professional and tried the following:
Unfortunately the text that is displayed is "text displayed" and not the text typed by the user in the frame where the edit box is.
Even more, I am not able to access to the GetWindowText function which I read is sometimes used (the VS code helper doesn't show this as option and if I try to write it then there are compilation errors saying that is not defined).
I then tried to see wheter the buffer of the edit box text was equal to zero but it wasn't. I tried to display the content of the buffer but here again, I am struggling..
I added the following to the code above which I found in another forum:
CString ls;
ls.Format("%d",bufferLenght);
LPTSTR bL;
test = ls.GetBuffer(ls.GetLength);
this->flippedNameStaticVar.SetWindowTextW(bL);
but this time there are compilation errors:
error C2664: 'void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
I am aware that I need to study more MFC but could anyone give me some insight on this?
Also, you are using _W functions (SetWindowTextW). The compiler chooses the _A or _W variant of each function for you. If you define UNICODE the compiler uses the _W functions, if you don't define UNICODE, the compiler uses the _A functions. You don't need to do that yourself.
but if I add the code u suggested it works.. (not sure why it was giving me compilation errors before, but nevermide about this, I had probably written something else stupide somewhere..).
Re: [MFC] lost trying to retrieve text from an editBox
not sure why it was giving me compilation errors before
Because of the _W functions.
Code:
LPTSTR bL;
LPTSTR is for the _A functions. LPWSTR is a char pointer for the _W functions. if you don't use _A or _W combined with CString, the compiler fixes all your problems based on the UNICODE compile switch.
Re: [MFC] lost trying to retrieve text from an editBox
Intellisense is responsible for showing you the options. Microsoft isn't very good in building a Intellisense system . Sometimes is gets lost. The studio studio stores this information in a file (don't know which one exactly) in your project directory. Removing this file will trigger a full rescan. This sometimes fixes the problem.
Bookmarks