I know there are 2 ways to access a control in a dialog.
1. Via member variable ("m_" something) - hooked by DDX_Control()
2. Via GetDlgItem()
Can someone please tell me if there're differences in choosing either one of
them? I mean... like... which one is faster or more efficient in terms of
memory usage and stuff.
Please advice, thanks!
-P
That depends on how you use them. A member variable is very convenient, and
repeatedly calling GetDlgItem() is not desirable. However, if you don't use
the control much then maybe GetDlgItem() is a better choice. On modern
computers it doesn't really make a whole hexx of a lot of a difference
anyway...
--
Sigurd
http://utvikling.com
The control member variable is superior in virtually all respects. It
is typesafe, more CPU efficient, object-oriented, and makes the code
more readable, obvious and maintainable.
--
Scott McPhillips [VC++ MVP]
Efficiency is not an issue here. ISTR reading that interacting with UI
elements like dialog items is perceived as instantaneous if response follows
user action within 20 msec or so, which is an eternity even for old
computers. There are two considerations here, convenience and correctness;
member variables are normally more convenient than GetDlgItem, and member
variables aren't subject to the downcasting errors that can affect careless
use of GetDlgItem. See these messages for more:
http://groups.google.com/groups?selm=gof6605c2hrujpd2htk0oael3ht5d3dqp3%404ax.com
http://groups.google.com/groups?selm=o4a9001kms81r7vhjio0eq9vt06o8n7ssp%404ax.com
In addition, if you have a control which you want to act like an instance of
some control class, you must bind the control to a member variable of that
type for the class's message handlers to be invoked. That's one case where
you absolutely have to use a control member variable.
--
Doug Harrison
Microsoft MVP - Visual C++
That depends on what you use it for.
--
Sigurd
http://utvikling.com
Thank you!
-P