Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3026

How to use a variable declared in another dialog class in Visual C++

$
0
0
Hello everyone,
I have created a list view(Declared in dialog class CDataDialog) with data . I want the list view to have as rows-cells as the conductors so I used :for (int i = 1; i<= m_DialogCon; i++) (m_DialogCon is the variable which representes the number of conductors but was declared in another dialog class, CFeaturesDialog). Basiclly,when the executable runs I want to give the value of conductors in the first dialog (CFeaturesDialog)Name:  Features.jpg
Views: 29
Size:  23.9 KB of executable and when I close it and open the second dialog(CDataDialog)Name:  Data.jpg
Views: 26
Size:  25.5 KB I want the list view there to have as rows-cells as the number of conductors i typed in the first dialog. How could I use m_DialogCon variable in CDataDialog to obtain this?
Here is the code:
Code:

void CDataDialog::InsertItems()
{
       
        HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST1);
        // Set the LVCOLUMN structure with the required
        // column information
        LVCOLUMN list;
       
        list.mask = LVCF_TEXT | LVCF_WIDTH |
                LVCF_FMT | LVCF_SUBITEM;
        list.fmt = LVCFMT_LEFT;
        list.cx = 50;
        list.pszText = L"Conductor";
        list.iSubItem = 0;
        //Inserts the column
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)0, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"Resistivity";
        list.iSubItem = 1;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)1, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"Permeability";
        list.iSubItem = 2;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)2, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"Outer Diameter";
        list.iSubItem = 3;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)3, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"Inner Diameter";
        list.iSubItem = 4;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)4, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"Rdc";
        list.iSubItem = 5;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)5, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"x component";
        list.iSubItem = 6;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)6, (WPARAM)&list);

        list.cx = 100;
        list.pszText = L"y component";
        list.iSubItem = 7;
        ::SendMessage(hWnd, LVM_INSERTCOLUMN,
                (WPARAM)7, (WPARAM)&list);
       
        // Inserts first Row with four columns .
       
        for (int i = 1; i<=m_DialogCon; i++)
        {
                SetCell(hWnd, L"1", 0, 0);
                SetCell(hWnd, L"0.0000386063", 0, 1);
                SetCell(hWnd, L"1", 0, 2);
                SetCell(hWnd, L"0.025146", 0, 3);
                SetCell(hWnd, L"0.00971", 0, 4);
                SetCell(hWnd, L"0.09136", 0, 5);
                SetCell(hWnd, L"0", 0, 6);
                SetCell(hWnd, L"15.24", 0, 7);
        }
       
}



Code:

class CDataDialog : public CDialog
{
        DECLARE_DYNAMIC(CDataDialog)
       
public:
        CDataDialog(CWnd* pParent = NULL);  // standard constructor
        virtual ~CDataDialog();

// Dialog Data
#ifdef AFX_DESIGN_TIME
        enum { IDD = IDD_DIALOG2 };
#endif

protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

        DECLARE_MESSAGE_MAP()
public:
        afx_msg void OnBnClickedOk();
        afx_msg void OnBnClickedExit();
        void InsertItems();
        //void InsertItems(int nCond);
        //void InsertItems();
        void SetCell(HWND hWnd1, CString value, int nRow, int nCol);
        CString GetItemText(HWND hWnd, int nItem, int nSubItem) const;
        afx_msg void OnClickList1(NMHDR *pNMHDR, LRESULT *pResult);
        afx_msg void OnOK();
        BOOL OnInitDialog();
        int nItem;
        int nSubItem;
        //void SetCon(int nCon);
        //{ m_DialogCon = nCon; }
   
        //int m_DialogCon;
       
       
};


Code:

class CFeaturesDialog : public CDialog
{
        DECLARE_DYNAMIC(CFeaturesDialog)

public:
        CFeaturesDialog(CWnd* pParent = NULL);  // standard constructor
        virtual ~CFeaturesDialog();

// Dialog Data
#ifdef AFX_DESIGN_TIME
        enum { IDD = IDD_DIALOG1 };
#endif

protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

        DECLARE_MESSAGE_MAP()
public:
        int m_DialogCon;
        afx_msg void OnEnChangeEdit1();
        //void SomeFunc();
        int m_DialogLayers;
        int m_DialogPermeability;
        int m_DialogAirConductivity;
        int m_DialogAirPermittivity;
        int m_DialogEarthPermeability1;
        double m_DialogEarthConductivity1;
        int m_DialogEarthPermittivity1;
        double m_DialogDepth;
        int m_DialogEarthPermeability2;
        double m_DialogEarthConductivity2;
        int m_DialogEarthPermittivity2;
};

Attached Images
  

Viewing all articles
Browse latest Browse all 3026

Trending Articles