Member variable for a control v.s. GetDlgItem

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
0
Paul297 (622)
10/4/2004 7:47:09 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
388 Views

Similar Articles

[PageSpeed] 21

Paul wrote:
> 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.

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


0
sigurds (118)
10/4/2004 8:03:47 PM
Paul wrote:

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

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++
0
dsh (2498)
10/5/2004 2:55:11 AM
Paul wrote:

> 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

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]

0
Scott
10/5/2004 3:46:22 AM
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


0
sigurds (118)
10/5/2004 10:26:10 AM
Very interesting!!!  I'll just stick w/ member variables.

Thank you!
-P

"Doug Harrison [MVP]" 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++
> 
0
Paul297 (622)
10/5/2004 2:37:03 PM
Reply:

Similar Artilces:

Control Access to groups of contacts
I have a client who wants to have a master contact list so he can see the entire list. He has a handful of clients who will need to be able to view overlapping subsets of those contacts, but should not be able to view the entire list. Can access control be applied at this granularity? User Attributes or other Security groups are acceptible components of this access control. For instance, UserA needs to see contacts 1, 3 and 5 UserB needs to see contacts 1, 2, and 3 UserC needs to see contacts 2, 4, and 5 UserD needs to see contacts 1, 3, 4, and 5 ...

OnEvent Click and Tab Controls
Good Day All.. I have an issue that I had posted previously but it did not get resolved. It may partially be my fault for not explaining my need/question correctly. I have a form. The form contains a subform. & a tab control. The subform has 3 fields listed for the user: ShipTo, BillTo & Account Name The tab control has 3 tabs. The first tab is where I am struggling right now. I want the user to select ('click') on the "account" in the subform (data sheet) at the top. Once they click the "account" the fields on the tab control will then fill wit...

How do I find the location of the font control in Win XP
Hi All, I'd like to change my fonts every now and then but don't know where to find them. Could someone please tell me where they are an how to use them? Thanks, Don Don, This newsgroup deals with Microsoft Access, a relational database application. You'll have better luck posting this on a newsgroup related to Windows Fonts. Try... microsoft.public.word.printingfonts -- hth Al Campagna Microsoft Access MVP http://home.comcast.net/~cccsolutions/index.html "Find a job that you love... and you'll never work...

>> Calendar Control drag to select range
Hi, using MS Access 2003, is it possible to allow a user to drag to select a range of dates and, if 'yes', how do you store the selected date range? Many thanks, Jonathan Not that I know of. Storing a range of dates is quite simple though. You store the start date and the end date and use a calculation to show all the dates between. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Jonathan" <Jonathan@discussions.microsoft.com> wrote in message news:4F22299F-3765-40D2-AA03-67FB42FFC07A@microsoft.com... > ...

What's the use of LOG file in MDBDATA
To whom it may concern I am now using Exchange 2003 now. I find there are many .LOG files in the folder MDBDATA where 5 G each What's the use of this files ? Can I delete those file ? On Thu, 16 Mar 2006 09:57:35 +0800, "Hughs Man" <hughs@easystem-hk.com> wrote: >To whom it may concern > >I am now using Exchange 2003 now. >I find there are many .LOG files in the folder MDBDATA where 5 G each > >What's the use of this files ? >Can I delete those file ? > Those are your transaction logs. DO NOT delete them. Run a full, online exchange awa...

Boot-start of system driver(s) failed to load
My event log keeps showing error 7026, The following boot-start or system start driver(s) failed to load ftsata2. Could someone please help me with this? ...

export CRM contacts\mail address's to outlook
Is there a way that anyone knows how to AUTO export and import the contacts from MSCRM, into outlook contacts. either by using windows scheduler or some other means. I have a client that will be using CRM with ExactTarget so having the ability to send mailshots on behalf of others (like outlook). BUT not all of their users have access to CRM, they want to have some scheduler to auto export the crm mail contacts out of CRM and into a public folder contacts list. Anyone got some great ideas? cheers J -- Thanks again for all the help Hi, We are using scrib from scribesoft, who can sche...

Cview and Tree control
I have an MDI application which renders opengl scenes in a document. The CView class continously calls opengl library and paints the scene. Here is a screenshot: http://limefocus.net/screenshot.jpg I would like to add a tree control inside the document to manupilate the image generated in the CView. Is it possible to embed a tree control in a CDocument? Thanks. Jess You are mixing the paradigms here. A document does not care how its data is represented. Question you shoud ask is if you can put a tree control in your view. The answer is : absolutely. You can use a splitter to put a t...

Ignore Zero's
Hi I have used the following to get the average value from a set of data whilst ignoring zero values within the data set. =SUM(K4:AP4)/COUNTIF(K4:AP4,">0") I would like to use the percentile command on the same set of data. Is there a way that I can use Percentile and also ignore zero values ? Many Thanks Chris Hi, with an ARRAY formula =PERCENTILE(IF(K4:AP4>0,K4:AP4),0.1) This is an array formula which must be entered by pressing CTRL+Shift+Enter 'and not just Enter. If you do it correctly then Excel will put curly brackets 'around the formu...

Control Button
Hello I need some help with a form. What I am trying to do is, to place a button on a form in MS Access so that when you click on it, in another field it will display a number one. If you click on the same button again it will change the one to a two and so on. Wes Private Sub YourCommandButton_Click() YourTextBox = YourTextBox + 1 End Sub -- There's ALWAYS more than one way to skin a cat! Answers/posts based on Access 2000 Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200705/1 "Wes Derhak" <derhak.wg@shaw.ca&...

Alt S wont send anymore
I can't be dreaming - installed outlook 2003 about 2 weeks ago. After creating a message, I was able to just hit alt S and the message would be sent. Now, I have to hit enter after alt S. What changed? Any ideas? thanks, larry ...

Why does portfolio review show N/A for DJIA and S&P500 peformance?
I am evaluating Money 2004, and am using the Portfolio Review. (Portfolio -> Analyze my portfolio -> Portfolio Review). When I scroll down to the performance section, I see the year to date performance of my portfolio and the performance for the last 12 months. The performance of the DJIA and S&P500 are also listed below my portfolio, but instead of a percentage return, the performance is listed as "N/A". How can I get the portfolio review to show the performance of the DJIA and S&P500 to compare to my portfolio? Thanks, Jeff ...

Exchange 5.5 DL's in Exchange 2003 GAL
we are currently running a mixed mode environment (Exchange 5.5 and Exchange 2003) which has two domains. Exchange 2003 is running in Domain A, and Domain B contains both 2003 and 5.5. The problem that we have is that Exchange 5.5 DL's in doamin A show up in the Exchange 2003 GAL, but Exchange 5.5 DL's from domain B do not. I have had a look at the ADC and everything appears to be ok. Take a look at these: http://support.microsoft.com/default.aspx?scid=kb;en-us;275194 http://support.microsoft.com/default.aspx?scid=kb;en-us;329200 "swingman" <steven.jones@arup.com&g...

How do you control the color/pattern of a pie chart?
I need help with my pie charts. I need to create pie charts that are easily understood in B&W. How do I set the color or pattern for each portion of my pie chart? Hi, To format a slice you need to select it first. Click the pie once to select all slices. Click again to select individual slice. You can use the Fill Effects > Patterns to fill with b/w patterns. Also in print preview the Setup dialog has a Print Black & White option on the Chart Tab. Note this is only visible if you have a chart sheet or select the chartobject before print preview. If you are printing chartobje...

how can I insert text file's text into my email in outlook 2007
I used to use outlook express. There is a lovely function to insert text file's text into my currently writing email. How can I do that in my outlook 2007 ? Time before, I first create a text file, say 'payment method.txt', then type in all my standard payment method information to my customer. When I was replying an email with my standard text, I simply use the "insert - text file" function, instead of openning the 'payment method.txt', copy and paste to my email. Can I do that similar in outlook 2007 ? Thank you very much Henry Fung wrote: > I used t...

Bank Rec void check date s/b same as GL void date
When voiding a check in the payables management module and the Void date and Posting date are changed from the original check date, Bank reconciliation should recognize that void date instead of the original check date as the voided date. Please refer to Knowledgebase Article 857704 to see how Ban Rec handles the date of a void check. If a check is voided in Payables Mgmt on a different date than the original date, and bank rec uses the original date trying to reconcile to the general ledger is a problem because the adjusted bank book balance is different than the GL balance becuase th...

Money 02 can't delete Apay tx's from budget
I called MS Money support and was told that Apay transactions, once added to the budget, are permenant. Even if you delete the Apay transaction from Bills & Deposits, the entry remains in all budgets. There is no way to remove this amount so your planned expenses/income is in correct forever. It is possible to delete any non-Apay transaction from the budget. I'm really annoyed that there is no mention of this anywhere on any Microsoft Money support site. ...

Printer Control
I have a printer control on my form and when I use it, it prints to the default printer. I would like for it to bring up the screen to allow me to select which printer to use, like when you use the file/print way. thanks Blair Private Sub Command310_Click() On Error GoTo Err_Command310_Click DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.PrintOut acSelection DoCmd.GoToControl "CloseFemaleCards" Exit_Command310_Click: Exit Sub Err_Command310_Click: MsgBox Err.Description Resume Exit_Command310_Click End Sub This will call the print...

ActiveX control being added to outgoing e-mail?
I have a user running Outlook 2003 via Exchange 2000. All outgoing messages sent by his system apparently have an ActiveX control in them. Any messages I try to open on another machine give the alert "Your current Security settings prohibit running ActiveX controls..." Could this mean the user has a virus? Something else? Any help is appreciated, and a direct reply to me is appreciated as well. Thanks, John M John discovered this was due to bad signature or stationary files in Outlook. I had the same problem with a user and tested this theory. There was indeed some c...

How to make Bullen's FilterCriteria() data refresh real-time?
Using XL 2003 & 2000 OK, with help, I was able to utilize Steve Bullen's FilterCriteria() Function. That said, apparently the only way to refresh the data in the display cell is to re-activate the formula by pressing <ENTER> in the Fx Box. Can the display cells be made to refresh in real-time or, second best, by F9? FYI (Background Info): ************************************************************II placed this formula into cell A1: =FilterCriteria(A3) Cell A3 contains the Autofilter down-arrow for column A ************************************************************* Fu...

VC++ .NET 2002: How To Use the Class View's Properties window to add a message handler for the WN_KEYDOWN message
Hi all I used "The EX05c Example: Scrolling" of the book "Programming With Microsoft Visual C++ .NET Core Reference" (6th Edition) as my 3rd example of MFC exercises to catch up my VC++ .NET 2002 (VC++ 7.0) programming. I started my 'Eg05c' project in the MFC Application Wizard and followed the 1 thru 7 steps instructed in the book (pages 82-85) I believed I did the steps 1, 2 and 3 correctly: 1 - In MFC Application Wizard -Eg05c, I setthe CEg05cView to "CScrollView" 2 - I added the m_rectEllipse and m_nColor data members in Eg05cView.h by typing in "...

Outlook Express v.6
When I attempt to open my address book I get the following message: "Unable to open the Address Book. The Address Book may not be installed properly." Microsoft has some solutions to the problem in their database but no articles for Windowws Xp pro. I also have Business Contact Manager installed. Bryan This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different program, despite its similar name.. You will probably get a faster and more expert answer if you post this to an Outlook Express news g...

Problem with multiline tab control #2
Hi, I have a problem with a tab control that I just can't seem to figure out. I have a tab control that made multi-line capable with m_ctrlTab.ModifyStyle(TCS_MULTILINE,TCS_MULTILINE); but, ever since I made the change I can't seem to display whichever tab I want upon application startup. It used to be a regular single-line tab (with 5 tabs) but I'm running out of space which is why I need a multiline solution. I have 6 tabs right now, three in one row. My code looks like this: ------------------------------- snip ------------------------------- BOOL Cxxxx:OnInitDialog() { ...

USB KVM's always plays 'Device Connect' sound
It appears that USB KVM's with Audio support always make Windows XP computers play the 'Device Connect' sound when you switch between computers. Does anyone know of a USB KVM with Audio that can properly emulate the USB connection to the inactive computer, so that the 'device connect' event doesn't occur when switching between computers? <prubin@equilter.com> wrote in message news:293fbb08-74eb-4b65-8807-1c43540b4c88@o10g2000yqa.googlegroups.com... > It appears that USB KVM's with Audio support always make Windows XP > computers play the &...

Upper Control Limits
I have a line chart that shows 12 months of data and a trend line. I computed the Upper & Lower Control Limits using the Standard Deviation. Is there a way to put these lines on my charts so that when my boss looks at it she can tell if one or more of the points are out of control? Thanks In Advance Wm. William: This link will show you how to build a control chart in Excel. http://processtrends.com/pg_charts_control_chart.htm ....Kelly koday@processtrends.com "williamr" <williamr@discussions.microsoft.com> wrote in message news:64B0E55A-F4F1-4FE9-9566-C9BCCF2...