Getting a Control From the Other Dialog

This is a discussion on Getting a Control From the Other Dialog within the Windows Programming forums, part of the Platform Specific Boards category; How can I access a control from another class ( in MFC )? Example: COtherClass *other; other->m_TheControl.GetWindowText( buffer ); or ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    10

    Getting a Control From the Other Dialog

    How can I access a control from another class ( in MFC )? Example:

    COtherClass *other;
    other->m_TheControl.GetWindowText( buffer );


    or

    COtherClass other;
    other.m_TheControl.GetWindowText( buffer );


    I've tryed both, but in the execution of the program an "Debug Assertion Error" is showed.

    What's going wrong?
    I'm using VC++.

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    When you are doing

    COtherClass *other;
    other->m_TheControl.GetWindowText( buffer );

    or

    COtherClass other;
    other.m_TheControl.GetWindowText( buffer );


    You are fist declaring a dialog class variable. For a dialog to come into existance only declaration of an object of that dialog class is not sufficient. I mean when you write "COtherClass Other;" a new dialog will not come into existance, you are only creating an object of a dialog class. You can get dialog by using DoModal() function of a dialog class.

    For example
    COtherClass Other;
    Other.DoModal();

    So....In your case, in second line you are requesting for a control which is not exist. So "Debug Assertion Error" will come definitely
    Chintan R Naik

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    10
    OK, thanks for the information.

    But what I really want to is to pass variables from one class to other class.

    Example:

    CString sSheet;
    sSheet = ptrDlg->m_OneString;


    Think I'm doing something wrong, but I don't know exactly what.
    Last edited by Rodrigo; 07-04-2003 at 02:28 PM.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    70
    Following is an example which will help you.

    Suppose you have one dialog class called "CTestDlg".

    class CTestDlg : public CDialog
    {
    public :
    int i;
    }

    Now you can use this class in following manner from your application dialog class.

    {
    CTestDlg Dlg;
    Dlg.i = 101;

    Dlg.DoModal();

    int ii = Dlg.i;
    }

    Here, you are creating an object of class CTestDlg. Then you are setting class variable 'i' with value 101. Then you are displaying that dialog. Suppose during dialog's lifetime you have changed value of 'i'. So by writing last statement you can get value of dialog class's 'i' variable into local variable 'ii'.
    Chintan R Naik

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Dialog Edit Control and Enter Key
    By Quantrizi in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2004, 08:59 AM
  4. edit control in dialog box problems
    By Bajanine in forum Windows Programming
    Replies: 11
    Last Post: 11-11-2002, 06:55 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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