Thread: content passing in dialog box?

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Smile content passing in dialog box?

    hi,
    i am to new to windows programming.(Non - MFC)
    i have create an application having 2 dialog boxes. i have to take input in the editbox of first dialog box.
    and to display it on static text field of second dialog box.
    i have created dialog boxes but i need to know how i pass contents of edit box to other dialog box.

    Please help me.
    Last edited by akshaydch; 10-06-2009 at 11:24 AM. Reason: giving more info

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    So, you'd need to retrieve the text from your edit control, store that and then transfer it to your static control. You could try something like what is shown below, though it's an old, layman's way of doing it.

    Code:
                    char* temp_buf;
                    std::string AddString;
                
                    int len = GetWindowTextLength(GetDlgItem(hwnd,ID_EDITBOX));
                   
                    if(len > 0 ) 
                    {
                    temp_buf = (char*)GlobalAlloc(GPTR, len + 1);
                    GetDlgItemText(hwnd, ID_EDITBOX, temp_buf, len + 1);
                    
                    AddString = temp_buf;
    
                    SetDlgItemText((HWND)hwnd,IDS_STATICBOX, AddString.c_str());
    
                    GlobalFree((HANDLE)temp_buf);
                    }

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Is the second dialog a child of the first?

    If so you can use GetParent()

    Code:
    char szBuf[MAX_PATH]={0}; // dynamic memory alloc is not required as edit has set limit lower than MAX_PATH and GetDlgItemText checks buffer size
    
    if(GetDlgItemText( GetParent(h2ndDlg), IDC_EDIT1, szBuf, MAX_PATH-1))//we got text
    {
           SetDlgItemText( h2ndDlg, IDC_STATIC1 , szBuf);
    }
    //else handle error.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by novacain View Post
    // edit has set limit lower than MAX_PATH
    That's incorrect.

    Quote Originally Posted by http://msdn.microsoft.com/en-us/library/bb775456(VS.85).aspx#text_buffer
    When the system creates an edit control, it automatically creates a text buffer, sets its initial size, and increases the size as necessary. The size can be up to a predefined limit of approximately 32 kilobyte (KB) for single-line edit controls
    Sure, you can set a limit so that your statement is true, but it's not in general. For example, the initial size on Win7 as reported by EN_GETLIMITTEXT is 30000 chars.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Sorry bad editing.

    I thought I said 'you can set the limit lower than MAX_PATH but this is not required as GetDlgItemText checks buffer length.'

    The default text lenght is 32,767 characters for edits (unless rich).

    EDIT: BTW the limit is only on text the USER enters, the limit is not checked for programatically entered text.
    Last edited by novacain; 10-07-2009 at 08:46 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Parent of a BrowseForFolder dialog box
    By @nthony in forum Windows Programming
    Replies: 4
    Last Post: 01-08-2007, 02:54 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  4. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM