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

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) of executable and when I close it and open the second dialog(CDataDialog) 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 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);
	}
	
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
	
	
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;
};
Why don't you simply modify void CDataDialog::InsertItems() to accept an int?
--> void CDataDialog::InsertItems(int conductrowscells)

Then, when you invoke InsertItems() from your instance of CDataDialog, just pass the correct value, something like:
1
2
3
4
CDataDialog cddialog;
CFeaturesDialog cfdialog;
// ...do something with cfdialog...
cddialog.InsertItems(cfdialog.getDialogCon);

Topic archived. No new replies allowed.