non-class member function problem

This is a discussion on non-class member function problem within the Windows Programming forums, part of the Platform Specific Boards category; hi i wanna set a value for a CEdit control on a dlgbox, from within a non-class member function which ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386

    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.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386
    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.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386
    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.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386
    the dialog exsists -- it displays. what i want is to change things within it from an outside function. maybe that's not possible?
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    386
    ok thx i'll do that.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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-17-2006, 12:35 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21