Copying Data from an Edit Control to a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tawanda diza
    New Member
    • Sep 2011
    • 29

    Copying Data from an Edit Control to a variable

    Hie Team.

    i am copying data from an EditControl called IDC_EDIT1 to a variable called ReqInfo.Amount

    i am using the followong code:
    Code:
    CEdit *DSP;
    CString text;
    
    DSP = reinterpret_cast<CEdit *>(GetDlgItem(AMOUNT));
    DSP->GetWindowTextW(text);
    	
    if(text.GetLength() == 0)
    {
     SetDlgItemText(IDC_STATIC_NOTIFY,L"Field is Blank");
     return;
    }
    else
    {
      sprintf_s(ReqInfo.Amount, 15,"%s",CT2CA(text));
    		
      ReqInfo.Amount[text.GetLength()] = 0;
    }
    what i would like to ask is "is there any other way to do this"
    i am finding it hard to follow this code
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    your main code to get the text from your text edit control is
    Code:
    CEdit *DSP;
    CString text;
     
    DSP = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDIT1));
    DSP->GetWindowTextW(text);

    Comment

    • tawanda diza
      New Member
      • Sep 2011
      • 29

      #3
      hie Johny.

      how else can i save the contents of that dialogue beside using

      Code:
      sprintf_s(ReqInfo.Amount, 15,"%s",CT2CA(text));
       
        ReqInfo.Amount[text.GetLength()] = 0;
      THANKS

      Comment

      Working...