GetDlgItemText Edit Control

Hi people,

at first, i am very new to VC, i was programming in VB for few years, but i want VC :)
I know, there is something like MFC, i dont want this thing, if i want some Runtimes i can use VB... here is my first problem:

i created a simple dialog based application, with some buttons and one edit box, now if i click on some of the buttons a MessageBox appears with Hello World!...

now i want to show the Text from the Text Box in the MessageBox, i am doing this like that:
CHAR oki[10];
GetDlgItemText(hDlg,IDC_EDIT1,oki,10);
MessageBox(hDlg, oki, "Test", MB_OK);

But i dont want to show just 10 characters, i want to show the whole Data!, maybe 50, 100 or even 1000 or more characters...??? how can i read the whole text from the text box without setting the nMaxCount Var? or is there a function to read the Length of a Text Box so i can use it in the GetDlgItemText like that:

GetDlgItemText(hDlg,IDC_EDIT1,oki,GetLenthText(hDlg,idc_edit1));


Thank you in advance!
mike.-

Comments

  • [b][red]This message was edited by xbob at 2003-5-28 19:3:50[/red][/b][hr]
    [GREY][ITALIC]CHAR oki[10];
    GetDlgItemText(hDlg,IDC_EDIT1,oki,10);
    MessageBox(hDlg, oki, "Test", MB_OK);

    But i dont want to show just 10 characters, i want to show the whole Data!, maybe 50, 100 or even 1000 or more characters...??? how can i read the whole text from the text box without setting the nMaxCount Var?[/ITALIC][/GREY]
    [GREEN]
    First of all; the [ITALIC]nMaxCount[/ITALIC] parameter to GetDlgItemText indicates the maximum number of characters to be copied into the char buffer (ie. the length of the target buffer), so you need alter this value under all circumstances in order to copy more than 10 chars into the buffer.

    Second, since the retrieved string should be zero-terminated, GetDlgItemText will only copy chars until it reaches a NUL;

    [CODE]
    // Set a length you know will suffice.
    CHAR szOki[ 1000 ];

    // Since this program isn't unicode compatible, sizeof( szOki ) is always equivalent to the number of characters that can be stored in szOki.
    GetDlgItemText( hDlg, IDC_EDIT1, szOki, sizeof( szOki ) );

    MessageBox( hDlg, szOki, "Test", MB_OK );
    [/CODE]
    Hope this solves your problem ;-)
    [/GREEN]


  • : Hi people,
    :
    : at first, i am very new to VC, i was programming in VB for few years, but i want VC :)
    : I know, there is something like MFC, i dont want this thing, if i want some Runtimes i can use VB... here is my first problem:
    :
    : i created a simple dialog based application, with some buttons and one edit box, now if i click on some of the buttons a MessageBox appears with Hello World!...
    :
    : now i want to show the Text from the Text Box in the MessageBox, i am doing this like that:
    : CHAR oki[10];
    : GetDlgItemText(hDlg,IDC_EDIT1,oki,10);
    : MessageBox(hDlg, oki, "Test", MB_OK);
    :
    : But i dont want to show just 10 characters, i want to show the whole Data!, maybe 50, 100 or even 1000 or more characters...??? how can i read the whole text from the text box without setting the nMaxCount Var? or is there a function to read the Length of a Text Box so i can use it in the GetDlgItemText like that:
    :
    : GetDlgItemText(hDlg,IDC_EDIT1,oki,GetLenthText(hDlg,idc_edit1));
    :
    :
    : Thank you in advance!
    : mike.-
    :
    [code]
    HWND hEdit = GetDlgItem (hDlg, IDC_EDIT1);
    int iChars = GetWindowTextLength (hEdit)+1; // Room for ''
    CHAR* pstrText;

    if ((pstrText = (CHAR*) malloc (sizeof (CHAR) * iChars)) != NULL) {
    GetWindowText (hEdit, pstrText, iChars);
    MessageBox (hDlg, pstrText, "Edit Box Contents", MB_ICONINFORMATION);
    free (pstrText);
    }
    [/code]
  • : : Hi people,
    : :
    : : at first, i am very new to VC, i was programming in VB for few years, but i want VC :)
    : : I know, there is something like MFC, i dont want this thing, if i want some Runtimes i can use VB... here is my first problem:
    : :
    : : i created a simple dialog based application, with some buttons and one edit box, now if i click on some of the buttons a MessageBox appears with Hello World!...
    : :
    : : now i want to show the Text from the Text Box in the MessageBox, i am doing this like that:
    : : CHAR oki[10];
    : : GetDlgItemText(hDlg,IDC_EDIT1,oki,10);
    : : MessageBox(hDlg, oki, "Test", MB_OK);
    : :
    : : But i dont want to show just 10 characters, i want to show the whole Data!, maybe 50, 100 or even 1000 or more characters...??? how can i read the whole text from the text box without setting the nMaxCount Var? or is there a function to read the Length of a Text Box so i can use it in the GetDlgItemText like that:
    : :
    : : GetDlgItemText(hDlg,IDC_EDIT1,oki,GetLenthText(hDlg,idc_edit1));
    : :
    : :
    : : Thank you in advance!
    : : mike.-
    : :
    : [code]
    : HWND hEdit = GetDlgItem (hDlg, IDC_EDIT1);
    : int iChars = GetWindowTextLength (hEdit)+1; // Room for ''
    : CHAR* pstrText;
    :
    : if ((pstrText = (CHAR*) malloc (sizeof (CHAR) * iChars)) != NULL) {
    : GetWindowText (hEdit, pstrText, iChars);
    : MessageBox (hDlg, pstrText, "Edit Box Contents", MB_ICONINFORMATION);
    : free (pstrText);
    : }
    : [/code]
    :

    [GREEN]I guess a dynamic size of the buffer is more appropriate, after all ;)[/GREEN]
  • : Hi people,
    :
    : at first, i am very new to VC, i was programming in VB for few years, but i want VC :)
    : I know, there is something like MFC, i dont want this thing, if i want some Runtimes i can use VB... here is my first problem:
    :
    : i created a simple dialog based application, with some buttons and one edit box, now if i click on some of the buttons a MessageBox appears with Hello World!...
    :
    : now i want to show the Text from the Text Box in the MessageBox, i am doing this like that:
    : CHAR oki[10];
    : GetDlgItemText(hDlg,IDC_EDIT1,oki,10);


    : MessageBox(hDlg, oki, "Test", MB_OK);
    :
    : But i dont want to show just 10 characters, i want to show the whole Data!, maybe 50, 100 or even 1000 or more characters...??? how can i read the whole text from the text box without setting the nMaxCount Var? or is there a function to read the Length of a Text Box so i can use it in the GetDlgItemText like that:
    :
    : GetDlgItemText(hDlg,IDC_EDIT1,oki,GetLenthText(hDlg,idc_edit1));
    :
    :
    : Thank you in advance!
    : mike.-
    :


    It is so simple u must use char[1000] or u can use char *msg
    if u have still prob reply
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories