which one is better?
-
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
Hello, It's just a matter of preference. Using the
GetDlgItem()
involves a lot of ugly typecasts and unnassecary code. Using them_Control
variable looks much more cleaner. I even think that it is slightly faster than the other method, since you already have aCWnd
derived object. (Unless you use primitive types or CStrings for managing dialog data.) Behind every great black man... ... is the police. - Conspiracy brother Blog[^] -
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
as bob said, using
GetDlgItem()
each time you want to access a control add several function calls to your code that you could avoid. but of course, using a member variable to store theCWnd*
of a control is working unless you initialize it correctly (with...GetDlgItem()
:-D ) what i used to do personnaly is having a set of m_p???????? variables in my Dialog classes, that i initialize intoOnInitDialog()
with a set ofGetDlgItem()
calls...
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
Hello, It's just a matter of preference. Using the
GetDlgItem()
involves a lot of ugly typecasts and unnassecary code. Using them_Control
variable looks much more cleaner. I even think that it is slightly faster than the other method, since you already have aCWnd
derived object. (Unless you use primitive types or CStrings for managing dialog data.) Behind every great black man... ... is the police. - Conspiracy brother Blog[^] -
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
IMO depends on the situation. eg: if you have lots of string resources and you need to reset its value it would be a good thing to create all of them consecutively to permit looping from the base one to the last just incresing a counter. Marc Soleda ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
IMO depends on the situation. eg: if you have lots of string resources and you need to reset its value it would be a good thing to create all of them consecutively to permit looping from the base one to the last just incresing a counter. Marc Soleda ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
-
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
Hi, Well you could use either method is correct however, using m_Control has a slight overhead. The reason is that m_Controls are MFC controls while the form has windows controls. So when the form is instantiated the MFC code kicks in and creates the m_Controls. I would prefer this method if I have a lot of interaction with the controls. However if I dont have to interact with the controls or have only to interact with them one time then it is better to use the GetDlgItem method. Prady
-
Hi, Well you could use either method is correct however, using m_Control has a slight overhead. The reason is that m_Controls are MFC controls while the form has windows controls. So when the form is instantiated the MFC code kicks in and creates the m_Controls. I would prefer this method if I have a lot of interaction with the controls. However if I dont have to interact with the controls or have only to interact with them one time then it is better to use the GetDlgItem method. Prady
Overhead you say? If you use the other method for a lot of controls you typically use not so much (controls in option dialogs for exemple), you create more unnaccesary overhead using more code to initialze and use the controls. All the unaccessary error checks, function calls are also overhead. The initialization done by MFC is behind the scenes and in GUI applications, the overhead added by MFC doesn't matter very much. So why go through all the fuss of writing pure API code with all the trouble it brings when you can do without? IMHO, one should write as few lines of Win32 API code for the GUI when he / she uses MFC. This is not only for consistancy, but also saves a lot of troubles. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
-
Overhead you say? If you use the other method for a lot of controls you typically use not so much (controls in option dialogs for exemple), you create more unnaccesary overhead using more code to initialze and use the controls. All the unaccessary error checks, function calls are also overhead. The initialization done by MFC is behind the scenes and in GUI applications, the overhead added by MFC doesn't matter very much. So why go through all the fuss of writing pure API code with all the trouble it brings when you can do without? IMHO, one should write as few lines of Win32 API code for the GUI when he / she uses MFC. This is not only for consistancy, but also saves a lot of troubles. Behind every great black man... ... is the police. - Conspiracy brother Blog[^]
True, but you did not read my post. I said only if you wanted to do one or two interactions with the control you could use GetDlgIt.. fn. Prady
-
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
-
True, but you did not read my post. I said only if you wanted to do one or two interactions with the control you could use GetDlgIt.. fn. Prady
If you realize that only 10% of your code is used 90% of the time leaves you 90% of your code that is used almost never. Believing this, most of your controls are almost never used. If I would use your method and write
GetDlgItem()
code, I would be better off writing pure C windows applications, simply because it would make more sense. The control variable method on the contrary, fits perfectly in the MFC. Thats one part of the MFC that is specially designed that way, jsut because you don't have to useGetDlgItem()
anyore! Why would you use MFC in the first place if you bypass all the fancy stuff it was designed for? Behind every great black man... ... is the police. - Conspiracy brother Blog[^] -
To acess a control... * using GetDlgItem(IDC_) is better or using the control Variable m_Control is better? :confused: regards, Rookie
There may be times when you create controls dynamically then
GetDlgItem()
is usually easier, otherwisem_Control
makes for clearer and more compact code. Elaine :rose: The tigress is here :-D -
as bob said, using
GetDlgItem()
each time you want to access a control add several function calls to your code that you could avoid. but of course, using a member variable to store theCWnd*
of a control is working unless you initialize it correctly (with...GetDlgItem()
:-D ) what i used to do personnaly is having a set of m_p???????? variables in my Dialog classes, that i initialize intoOnInitDialog()
with a set ofGetDlgItem()
calls...
TOXCCT >>> GEII power
[toxcct][VisualCalc]toxcct wrote: what i used to do personnaly is having a set of m_p???????? variables in my Dialog classes, that i initialize into OnInitDialog() with a set of GetDlgItem() calls... You do realize that the return value of
GetDlgItem()
points to a temporaryCWnd
object that is only valid for the current Windows message? This means you can't save that return value and use it later, sinceCWnd
object may no longer exist.
Software Zen:
delete this;