Thread: non-class member function problem

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    non-class member function problem

    hi
    i wanna set a value for a CEdit control on a dlgbox, from within a non-class member function which resides in the cpp file of the dlgbox. what's the correct way to do this?
    thx.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    dlg.yourcontrol.SetWindowText("...");
    But perhaps you can elaborate a little more on what you're trying to do and show some code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    sorry not a CEdit it's a CList.

    tried this but i get an assertion faliure:

    Code:
    CServerDlg sd;
    sd.m_clrecvd.InsertString(-1, szServerW);
    i do this in a non-class member function.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Did you create the dialog first?
    Code:
    CServerDlg sd;
    sd.Create(IDD_YOURDLGID_HERE);
    sd.m_clrecvd.InsertString(-1, szServerW);
    EnableWindow(FALSE); // Disable parent
    sd.ShowWindow(SW_SHOW);
    sd.RunModalLoop();
    EnableWindow(TRUE); // Enable parent
    sd.DestroyWindow(); // Destroy window
    This is the typical sequence if you want to initialize data inside your dialog before showing it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    ow... it's the default dlg of a mfc project. im just trying to insert a string into a clist on it -- from a function which is not in dlg's members list.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ya, create an object of the class and create the window first, then you can add items to the list. You can't add items to a nonexistant window.
    Just make a function or something.
    If the dialog is created then you can mess around with it all you want.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    the dialog exsists -- it displays. what i want is to change things within it from an outside function. maybe that's not possible?
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It is. So long as you create it before.
    Common belief may be that when you do
    Code:
    CServerDlg sd;
    It also creates the window. But it doesn't.
    It actually creates the dialog when you do
    Code:
    sd.DoModal();
    Therefore, you can't just do
    Code:
    CServerDlg sd;
    sd.m_clrecvd.InsertString(-1, szServerW);
    Because the window (or its child window [or controls]) have not been created yet.
    The solution is to do what I posted above. Call Create to create the dialog first, THEN add your strings to the list.
    Then you have to emulate the behavior of DoModal yourself because it will ASSERT if you've created the dialog before the call to the function.

    Or, if you just want a modeless dialog, just call ShowWindow.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    ok thx i'll do that.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I always test the control exists with GetSafeHwnd() before adding to it from another app/dlg.

    I also use GetParent(). If a child dlg wants to update the LV on the parent, it calls a wrapper method;

    GetParent()->InsertLVItem(iIndex,sText);

    If not a child dialog then

    AfxGetApp() will get the main apps CWnd.
    "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: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM