-
December 7th, 2015, 10:42 AM
#1
Variable for a member variable
Hello
I have 2 combo boxes in the same class that use the same code.
So I wrote a function for combobox1 and another for combobox2.
Is it possible to assign a variable for the controls and passing it to the function so that the same code can be used?
Any help is much appreciated.
-
December 7th, 2015, 10:49 AM
#2
Re: Variable for a member variable
Yes. You can assign a control variable using Class Wizard.
-
December 9th, 2015, 01:30 PM
#3
Re: Variable for a member variable
Thanks GCDEF for your clear reply.
Obviously I do something wrong after that.
what I am trying to do is:
CComboBox m_cbtheme;
cbthemea.SubclassDlgItem(IDC_THEMEA,this);
cbthemeb.SubclassDlgItem(IDC_THEMEB,this);
m_cbtheme=cbthemea; //m_cbthemea passed to the function when doing themea
m_cbtheme=cbthemeb; //m_cbthemeb passed to the function when doing themeb
So I can use m_cbtheme.AddString(xxx); for A and for B.
However, the assignment m_cbtheme=cbthemea; results in
Error C2248: 'CObject:perator =' : cannot access private member declared in class 'CObject' d:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxwin.h
I know, most likely a stupid way to do it, but couldn't resist to try to find out.
-
December 10th, 2015, 08:36 AM
#4
Re: Variable for a member variable
You can not copy classes that are derived from CObject (for the reason given in the error message).
You should be able to use a pointer instead:
Code:
CComboBox * m_cbtheme;
m_cbtheme = &cbthemea;
and pass the pointer to the function.
-
December 13th, 2015, 01:22 PM
#5
Re: Variable for a member variable
Thanks a lot Philip Nicoletti
Exactly what I was looking for.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|