Problem in MFC AppWizard(exe)

my code is like this:
void CRrDlg::OnGetText()
{
CString kk;
int f;
CRrDlg* pEdit=(CRrDlg*)GetDlgItem(IDC_EDIT7);
{
f=22;
kk=f;
pEdit->SetWindowText(kk);
}

}

I cant show 22 as output and i don't want to use kk.Format() to display. Is there any way to put variable f as variable kk



Answer this question

Problem in MFC AppWizard(exe)

  • Dan B.

    Example on GetDlgItemText and Append:

    #include <stdlib.h>

    CString Data, ConvNum;

    int Num = 100;

    char NumberChar[10];

    GetDlgItemText(IDC_EDIT1, Data); //Get The Data

    _itoa_s(Num, NumberChar, 9, 10) //Convert Int To Char

    ConvNum = NumberChar;

    Data += _T(" "); // Insert a Blank Space So Data Is Not Bunched Together;

    Data += ConvNum;

    SetDlgItemText(IDC_EDIT1, Data); // Place Data Back Into Edit Control



  • needhelpbad

    You'll have to GetWindowText the existing text, append your extra text, and SetWindowText it back to the edit control.

    KitZ_CK wrote:
    Actually, i want to display many string and int variables at the edit box. if i use SetDlgItemInt(), it will overwrite my previous data in the edit box. How can i display all my data



  • Tstay

    Actually, i want to display many string and int variables at the edit box. if i use SetDlgItemInt(), it will overwrite my previous data in the edit box. How can i display all my data
  • ErikH

    SetDlgItemInt is the best. Just want to complete your Question though.

    To change an int to a char:

    #include <stdlib.h>

    int Number = 100;

    char NumChar[10];

    _itoa_s(Number, NumChar, 9, 10);

    /* 9 is how many characters to convert 10 is the base. _s is for security only. Oh it also prevents that horrible warning "Declared Depreciated" */

    I would use SetDlgItemInt. Less code is always better.

    Kindest Regards

    Quintin Immelman



  • Roberto Barrantes

    Can you please give me an example on how to do that
  • Delucia

    how to convert int to a char string And, how to use SetDlgItemInt I can't use Format because everytime i use it,it will overwrite the previous data.
  • Dave1111

    And why don't you want to use Format You need to convert the int into a char string. Or use use SetDlgItemInt.

  • PaulTH

    It looks as if you are casting a CWnd* to an edit window to a pointer to a CDialog-derived class. Since all you do is call SetWindowText, it's alright, but it's not something I'd do if I were you.

    You can do this :-

    SetDlgItemInt(IDC_EDIT7, f);

    KitZ_CK wrote:

    my code is like this:
    void CRrDlg::OnGetText()
    {
    CString kk;
    int f;
    CRrDlg* pEdit=(CRrDlg*)GetDlgItem(IDC_EDIT7);
    {
    f=22;
    kk=f;
    pEdit->SetWindowText(kk);
    }

    }

    I cant show 22 as output and i don't want to use kk.Format() to display. Is there any way to put variable f as variable kk



  • Problem in MFC AppWizard(exe)