how to use arguments Control in another class
-
i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good
-
i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good
You have defined the function this way:
BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId)
but you are calling it this way:
ctr.GetAllProcess(IDC_LIST1,arrProcId);
. You can't convert from IDC_LIST1 to a CListCtrl; one is a numeric id, the other is a class. Look at the examples here on Codeproject about how to use the CListCtrl class. Basically, you need to use the resource editor to create a CListCtrl variable; a DDX statement will attach the CListCtrl variable to IDC_LIST1. And you probably want to write the function like this:
BOOL CControl::GetAllProcess(CListCtrl& list1, int *arrProcId)
Best wishes, Hans
-
i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good
You need to use GetDlgItem()[^] to get the window handle from the control ID. If this is called from within a CWnd derived class this will return a CWnd object which can be cast to the list control. See CWnd::GetDlgItem()[^] Also, window classes are generally passed around as pointers. At a very minimum they should be passed as a reference as Hans suggested. Passing by value will create a copy of the class. Properties changed in the copied class may not reflect back on the original.
BOOL CControl::GetAllProcess(CListCtrl *list1, int *arrProcId) {
//do stuff
}CControl ctr;
ctr.GetAllProcess(GetDlgItem(IDC_LIST1), arrProcId); -
You have defined the function this way:
BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId)
but you are calling it this way:
ctr.GetAllProcess(IDC_LIST1,arrProcId);
. You can't convert from IDC_LIST1 to a CListCtrl; one is a numeric id, the other is a class. Look at the examples here on Codeproject about how to use the CListCtrl class. Basically, you need to use the resource editor to create a CListCtrl variable; a DDX statement will attach the CListCtrl variable to IDC_LIST1. And you probably want to write the function like this:
BOOL CControl::GetAllProcess(CListCtrl& list1, int *arrProcId)
Best wishes, Hans
oh thanks for your help :)..so much
-
You need to use GetDlgItem()[^] to get the window handle from the control ID. If this is called from within a CWnd derived class this will return a CWnd object which can be cast to the list control. See CWnd::GetDlgItem()[^] Also, window classes are generally passed around as pointers. At a very minimum they should be passed as a reference as Hans suggested. Passing by value will create a copy of the class. Properties changed in the copied class may not reflect back on the original.
BOOL CControl::GetAllProcess(CListCtrl *list1, int *arrProcId) {
//do stuff
}CControl ctr;
ctr.GetAllProcess(GetDlgItem(IDC_LIST1), arrProcId);nice....thanks ^^