CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2012
    Posts
    4

    Display data immediately - C++ Dialog domodal?

    I haven't seen it anywhere and I've been looking. Is it possible to display data, say in a CEdit field in a dialog as soon as the dialog starts? Either before or after DoModal is fine.. These are essentially the same.

    Using Visual Studio 2013 - trial version. It's nice. Coming from VC6. Many things are familiar (so far), at least in the C++ part.

  2. #2
    Join Date
    Mar 2012
    Posts
    4

    Re: Display data immediately - C++ Dialog domodal?

    BTW, mentioned VC6 because I'm wondering if maybe I missed something when drawing out the CEdit field. Is it still the same- just draw it out, make it a value field and assign a variable to it? I'm thinking that should work for the message handler methods anyways.

    Used:

    dlg.SetDlgItemText(IDC_TARGETAPP, _T("test tester testing"));

    and nothing showed up upon dialog program startup.

  3. #3
    Join Date
    Mar 2012
    Posts
    4

    Re: Display data immediately - C++ Dialog domodal?

    Did some more research and ran across the DDE thing. I guess somehow that needs to be done upon Dialog startup for this to work. Any suggestions, as in examples of calling DoDataExchange(CDataExchange* pDX);

    Thanks for any help.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Display data immediately - C++ Dialog domodal?

    Quote Originally Posted by MarkJS View Post
    I haven't seen it anywhere and I've been looking. Is it possible to display data, say in a CEdit field in a dialog as soon as the dialog starts? Either before or after DoModal is fine..
    It is not possible to display data in a CEdit field in a dialog before dialog starts.
    Do it in the CDialog::OnInitDialog override.
    Victor Nijegorodov

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Display data immediately - C++ Dialog domodal?

    The Windows part of the dialog and its associated controls don't exist before or after DoModal, so that part doesn't makes sense.

    The DDX mechanism is an easy way to do it. Just give a value to the member variable associated with the control before calling CDialog::OnInitDialog.

    Another way is to call SetWindowText in your OnInitDialog after it calls CDialog::OnInitDialog.

  6. #6
    Join Date
    Mar 2012
    Posts
    4

    Re: Display data immediately - C++ Dialog domodal?

    Quote Originally Posted by VictorN View Post
    It is not possible to display data in a CEdit field in a dialog before dialog starts.
    Do it in the CDialog::OnInitDialog override.
    Yep... A WELL-PLACED - Thank You, simple:

    SetDlgItemText(IDC_CEDITFIELD, CString);

    worked... There is an area in OnInitDialog to put initialized data in (at least in VS 2013).
    ---------------------------

    Nice technique.

    I like it, as the program is doing stuff immediately... not staring me in the face, so to speak- with a duhhhh... expression upon startup.

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Display data immediately - C++ Dialog domodal?

    Quote Originally Posted by MarkJS View Post
    There is an area in OnInitDialog to put initialized data in (at least in VS 2013).
    That "area" exists in VS6.0 and even older versions, as well.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Display data immediately - C++ Dialog domodal?

    Quote Originally Posted by MarkJS View Post
    Yep... A WELL-PLACED - Thank You, simple:

    SetDlgItemText(IDC_CEDITFIELD, CString);
    You might be better off at least learning what the DDX control approach has to offer rather than using the older WinAPI style of setting control values.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured