Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Member variable for a control v.s. GetDlgItem

59 views
Skip to first unread message

Paul

unread,
Oct 4, 2004, 3:47:09 PM10/4/04
to
Hi,

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

Sigurd Stenersen

unread,
Oct 4, 2004, 4:03:47 PM10/4/04
to

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


Scott McPhillips [MVP]

unread,
Oct 4, 2004, 11:46:22 PM10/4/04
to
Paul wrote:

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]

Doug Harrison [MVP]

unread,
Oct 4, 2004, 10:55:11 PM10/4/04
to
Paul wrote:

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++

Sigurd Stenersen

unread,
Oct 5, 2004, 6:26:10 AM10/5/04
to
Scott McPhillips [MVP] wrote:
> 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.

That depends on what you use it for.


--


Sigurd
http://utvikling.com


Paul

unread,
Oct 5, 2004, 10:37:03 AM10/5/04
to
Very interesting!!! I'll just stick w/ member variables.

Thank you!
-P

0 new messages