From: RB on
What is the best way to get and set the contents of an EditControl
(in a FormView) , other than using DDX.
Could I use the below, and how would I get the handle of the FormView?
UINT GetDlgItemText(
HWND hDlg, // handle of dialog box
int nIDDlgItem, // identifier of control
LPTSTR lpString, // address of buffer for text
int nMaxCount // maximum size of string
);


From: David Ching on
"RB" <NoMail(a)NoSpam> wrote in message
news:eVE5mcs7KHA.3276(a)TK2MSFTNGP02.phx.gbl...
> What is the best way to get and set the contents of an EditControl
> (in a FormView) , other than using DDX.
> Could I use the below, and how would I get the handle of the FormView?
> UINT GetDlgItemText(
> HWND hDlg, // handle of dialog box
> int nIDDlgItem, // identifier of control
> LPTSTR lpString, // address of buffer for text
> int nMaxCount // maximum size of string
> );
>
>

CFormView has a method GetDlgItemText:
http://msdn.microsoft.com/en-us/library/xcws9sbs%28VS.80%29.aspx

int GetDlgItemText(int nID, CString& rString ) const;


-- David

From: RB on
Thanks David, I did check this out and experimented with it
along with CWnd::GetWindowText. I have the debugger
results behind comments below. All of this code is in my ViewClass
and occurs incremetally with nothing in between that is not shown.
Execution comes to here from an Button Ctrl handler.
The intial 444 was entered into the IDC_Editbox prior to clicking
the Button.
I welcome comments from everyone on these:

CString rString, rString2; // the two receiving items

GetDlgItemText( IDC_EditBox, rString);
//rString now equals {"444"} from initial user input to editbox

SetWindowText(_T("555"));
GetWindowText(rString2);
//rString2 now equals {"555"} from the SetWindowText

GetDlgItemText( IDC_EditBox, rString);
//rString still equals {"444"} however rString remains unchanged?
//rString2 still equals {"555"}
// Shouldn't rString have changed to 555 ?


From: RB on
Actually I added a couple of lines and seemingly solved this myself
but would also like comments on another question at bottom.

CString rString, rString2;
GetDlgItemText( IDC_EditBox, rString);
//rString now equals {"444"}
SetWindowText(_T("555"));
GetWindowText(rString2);
GetDlgItemText( IDC_EditBox, rString);
//rString still equals {"444"}
//rString2 still equals {"555"}
SetDlgItemText(IDC_EditBox, _T("555"));
GetDlgItemText( IDC_EditBox, rString);
//rString now equals {"555"}
//rString2 still equals {"555"}

It appears that Get(or Set)DlgItem does reference the EditBox control
but GetWindowText does not.
Additionally I find that accessing the IDC_EditBox in this method ties the
value to a string, which could be converted of course, but to actually get
the value to be a double to start with you have to declare IDC_EditBox
variable of double type in the class wizard. And then it would appear you
would have to use DDX (?? ) to access this variable or am I missing
something ?


From: Joseph M. Newcomer on
See below...

It is not clear why you would need an HWND at this point, and it NEVER makes sense to
manipulate the contents of a dialog from outside the dialog; therefore, none of this makes
any sense,

If I want to get the contents of an edit control in a CFormView, I create a control
variable for the control, e.g., c_Name which would be of type CEdit. I would then do


CString s;
c_Name.GetWindowText(s);

Note that I consider the use of ::GetDlgItem to be always and forever inappropriate in MFC
code, and even CWnd::GetDlgItem should be used no more than about once a year, assuming
you can write a hundred or more lines of code an hour (if you write more slowly, it might
be once every two or three years you need it)

SetWindowText will set the text.
joe

On Sat, 8 May 2010 11:57:22 -0400, "RB" <NoMail(a)NoSpam> wrote:

>What is the best way to get and set the contents of an EditControl
>(in a FormView) , other than using DDX.
>Could I use the below, and how would I get the handle of the FormView?
> UINT GetDlgItemText(
> HWND hDlg, // handle of dialog box
> int nIDDlgItem, // identifier of control
> LPTSTR lpString, // address of buffer for text
> int nMaxCount // maximum size of string
> );
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm