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
352 Views

Similar Articles

[PageSpeed] 54

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:

How do i make a variable part of a formula
Say I have some vba code that looks like: ActiveCell.Range("A1:B5").Select Selection.FormulaArray = _ "=LINEST(R[1]C[-3]:R[5]C[-3],R[1]C[-2]:R[5]C[2],TRUE,TRUE)" Let's say that I am looping over some variable i, and would someho like to insert that variable into the code: Selection.FormulaArray = _ "=LINEST(R[1]C[*i*]:R[5]C[*i+1 ],R[1]C[-2]:R[5]C[2],TRUE,TRUE)" Obviously, I can't simply insert the i's in there -- what instea should i do? thank -- Message posted from http://www.ExcelForum.com Selection.FormulaArray = _ "=LINEST(R[1]C["...

set a variable to value in a select statement
I know how to do this: SET @total = (SELECT SUM(Salary) FROM Employee) But is it possible to do soemthing like this without 2 separate SET statements?: SET @total, @tipstotal = (SELECT SUM(Salary), SUM(Tips) FROM Employee) If so, how? SELECT @total = SUM(Salary), @tipstotal = SUM(Tips) FROM Employee Tom "Keith G Hicks" <krh@comcast.net> wrote in message news:utAHRun$KHA.5536@TK2MSFTNGP02.phx.gbl... >I know how to do this: > > SET @total = (SELECT SUM(Salary) FROM Employee) > > But is it possible to do soemthing like this with...

Date variables for Column and Worksheet Headings
How can I create a date variable that I can use in both column and worksheet headings? I'm not clear on what you are asking for... can you provide more details please? Rick "Ann" <Ann@discussions.microsoft.com> wrote in message news:16F6DE02-2195-4DB8-B40A-735411C2D463@microsoft.com... > How can I create a date variable that I can use in both column and > worksheet > headings? I have a workbook with multiple worksheets. There are dates within the headers of each worksheet and the column headings of multiple columns with the spreadsheets. I'd like...

Compatibility issues with MS WORD between my MAC and PC's
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I have been sending resume' attachments out for about the last month and I keep on getting emails back saying that the PC's first of all dont associate a program with the attached file, secondly when they do open it in word it opens at 200% or doesn't open at all. What do I do??? Which extension and/or formatting should I use? Using 2008 office for mac Don't send your resume as an attached Word document in the first place... even if you could correct the issues you're running into it leaves the d...

How do I string formulas together in Excel to display variables
I want to display a range of quotes in one cell from a formula in that cell...if you can make sense of that. The first part of the formula works well and displays one of five messages but I cant add any more formulas to the existing one without getting error messages, for example: =IF(AND(B13>84,B13<101),"High Distinction"). This works well but I need to add more to it in order to display Distiction, Credit, NGP, Fail...I am more than willing to send to anyone who can help me, the Excel spreadsheet to have a look at. Cheers David Something like Create a table like so I...

memory leak in webbrowser control
I am using a webbrowser control to render an html page that uses vml and xml. My code changes the html page by locating an id in the page and changing a style, text, or vml attribute. Every time I do this, there is an increase in memory usage and eventually the program crashes when there is no more memory. I originally used a CString's AllocSysString function to get my BSTR's and com smart pointers. When I switched to 'regular' pointers and used AddRef and Release, I saw some improvement, and more improvement when I switched to SysAllocString and SysFreeString. But...

The message reached the recipient's e-mail system, but delivery was refused. At
I sent two emails locally throught my exchange box to local exchange users that are not disabled. My inbox is filling up with these messages: -----Original Message----- From: System Administrator Sent: Monday, December 29, 2003 5:30 PM To: WMS Subject: Undeliverable: EventID : ST0030803 : Override Detected Your message did not reach some or all of the intended recipients. Subject: EventID : ST0030803 : Override Detected Sent: 12/29/2003 5:30 PM The following recipient(s) could not be reached: WMS on 12/29/2003 5:30 PM The message reached the recipient&#...

control chart scale with cell value in excel
I would like to control the Min. and Max. values for the x & y axes in a XY scatter chart with cell values. Does anybody know how to do this? Excel 2003 jjw: Here's a post that shows a simple[le VBA approach. http://processtrends.com/pg_charts_set_x_axis_min__max_dates.htm Kelly O'Day http://processtrends.com "jjw" <jjw@discussions.microsoft.com> wrote in message news:B743C713-7053-42F4-B005-2C7B594AA86F@microsoft.com... >I would like to control the Min. and Max. values for the x & y axes in a XY > scatter chart with cell values. > Does anybody...

Directory Access
Hi All I have an Exchange 2003 server running on a Windows 2003 domain in native mode. There is a DC in Site A with the Exchange server, and a second DC in site B. I noticed that if the DC in site A is down, all access to Exchange goes down. I checked the Directory Access properties of the server in System Manager, and it shows only the DC in the site for the Config, Global Catalog, and Domain Controllers, and All Domain Controllers. It is set to auto right now. I set it to manual, and tried to add Site B DC into the GC area. I added fine. I tried then to add Site B DC into the Domain ...

unable to listen to burned cd's
when I burn a cd I am unable to listen to it on any portable players, I can listen to it in my car cd player, but it takes minutes to "read" before starting to play. also, when it does start they are in folders, unlike my other cd's. I am using the same music and cd's that have previously worked. any help , thanks.... Hi, Could it be that you burned a data CD and previously you had burned audio CD's (CD's that you by in a shop prerecorded with music are usually audio CD's). Not all CD players will play data CD's. That could also explain why...

Axis scaling
I have been trying to use the code that Jon posted to this newsgroup: Option Explicit Private Sub Worksheet_Change(ByVal Target As Excel.Range) Select Case Target.Address Case "$E$2" ActiveWorkbook.Charts("Chart1").Chart.Axes (xlCategory) _ .MaximumScale = Target.Value Case "$E$3" ActiveWorkbook.Charts("Chart1").Chart.Axes (xlCategory) _ .MinimumScale = Target.Value Case "$E$4" ActiveWorkbook.Charts("Chart1").Chart.Axes (xlCategory) _ .MajorUnit = Target.Value ...

Problem calling my function in subclassed CEdit control
Hi, Am quite new to MFC and i am hoping someone can help me out with this problem. I have consulted earlier posts on this topic but still no joy. I am writing a dialog based app. I have subclassed the CEdit control(CMyEdit)in order to process the ENTER key when pressed in the control. I prefer this option rather than overiding PreTranslateMessage. My intention is to call a member function of my dialog class CABCDlg::OnBnClickedSearch() when ENTER is pressed in the CMyEdit control.I do this by sending a message to the dialog box when handling WM_CHAR messages in OnChar() However, ENTER does...

Create IE object in .vbs file, and control the tinymce editor in the page
HI, my friends, In a standalone .vbs file, I create an IE object and navigate to a page containing a javascript tinymce editor. Now I want to get/set the content of the tinymce editor. Is it possible to do that? P.S. Can javacript be run as standalone application, just like the .vbs file? Thanks! Any help will be appreciated! On Dec 8, 12:08=A0pm, Zhiguo <zhiguoyo...@gmail.com> wrote: > HI, my friends, > > In a standalone .vbs file, I create an IE object and navigate to a > page containing a javascript tinymce editor. > Now I want to get/set the content...

search analog meter control
Hello, i search a free good (well GUI) Analog meter control with C++ source code. On codeproject i found a very simple control, but the GUI was.... Jimmy On Aug 12, 2:47=A0pm, Johann Obermayr <Johann.Oberm...@sigmatek.at> wrote: > Hello, > > i search a free good (well GUI) Analog meter control with > C++ source code. > On codeproject i found a very simple control, but the GUI > was.... > > =A0 =A0 =A0 =A0 Jimmy Well.. fast, robust and cheap - you can choose only 2 of those! http://www.codeproject.com/KB/miscctrl/3dmeter.aspx http://www.codeproject.com/KB/mis...

Counting number of "N",s
This is a multi-part message in MIME format. ------=_NextPart_000_0008_01C541D5.7092DE40 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Is there a way to count the number of "N",s in a row. How would you = handle if the "N" is "n" or "N" colours. Many thanks Darren ------=_NextPart_000_0008_01C541D5.7092DE40 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML&...

Variable File Naming Using Macros
Is there a way to open a file and rename it using cells within the document itself using a macro? (Variable File Name?) Also, is there a way to open a file, using a macro again, by using criteria on a cell in an open worksheet? (Variable File Call?) Hi yes you can do this. e.g. sub save_it() with activesheet.range("A1") activeworkbook.saveas filename:= "C:\temp\" & .value & ".xls" end with end sub Similar with opening workbooks. See workbooks.open in the vBA help -- Regards Frank Kabel Frankfurt, Germany Kris S wrote: > Is there a way to ...

Removing Blanks from a variable length string
Hi. I have a problem which I am hoping someone will be able to help me with? I have a text field which is variable length and could have anything in it. Example: Baileys 190g Black What I want it to say is: Example: Baileys190gBlack Is this possible? Cheers AJ With the use of the Replace function Replace([FieldName]," ","") To replace space with no space -- Good Luck BS"D "AJCB" wrote: > Hi. > I have a problem which I am hoping someone will be able to help me with? > I have a text field which is variable length and could have anything i...

How can I change a text to a cell's address?
I'm trying to use the down formula, but the result is a text. I need the result from de cel, but the Excel don't understand the result as a cell's addres. Some one could help me? This is the formulas: A5 = ENDREÇO(BDCONTAR(S8:S29988;S8;Fórmulas!H17:H18)+8;19;1) P4 = CÉL("CONTEÚDO";A5) => Result "$S$495" I need that the Excel understand the result as a cell's address. PS.: My Excel is in portuguese. ...

Variable Length Columns
I am trying to set up a template with formulas into which I can simply drop data into and Excel will then run the calculations. However, the data I will be entering will have many different lengths. How can I make formulas and equations to handle the variable lengths of my data? For example, how do I sum the entries in a column if I do not know how many entries the column will have? Or, how do I sum a column and omit the #DIV/0 entries that will appear in that column? Hi, I'd fix my formula to eliminate the errors but you can sum the full column and ignore the errors ...

controlling where a form opens up
Is there a way to set where a form opens up. I have an Exit Program button set as popup which a user can use from anywhere in the program to quit. But I would like it to open up after the user logs in and be place in the upper right hand corner. -- TIA On Fri, 11 Jan 2008 13:20:04 -0800, tsison7 wrote: > Is there a way to set where a form opens up. I have an Exit Program button > set as popup which a user can use from anywhere in the program to quit. But > I would like it to open up after the user logs in and be place in the upper > right hand corner. Look up the Mov...

Problem with static variables in a Dll
When a Dll is compiled with _UNICODE directive, static variables will not retain their values (reseted to zeros) All go well when compling without _UNICODE directive MSDN says static variable required initialisation has to declared in #pragma init_seg but I have tried with no luck. Pls help! On Tue, 26 Jul 2005 03:53:04 -0700, ifi wrote: > When a Dll is compiled with _UNICODE directive, static variables will not > retain their values (reseted to zeros) > All go well when compling without _UNICODE directive > MSDN says static variable required initialisation has to declared in ...

Trying To Add a Line to an Excel chart using variable cell values
I'm using an XY Scatter chart and I want to draw a straight line between 2 points which passes through a 3rd point on the chart. The line represents the Security Market Line (relating risk and return) with Standard Deviation on the X axis and Portfolio Return Percentage on the Y axis. One point is the 3 Month TBill. The point that the line is passing through is an index point (e.g. S&P 500) and the 3rd point will be one that is calculated based on the slope of relationship between the TBill point and the index point. The 3rd point needs to be plotted on either the top or bott...

Problem with Variable allocation accounts and Reversing Entry
I want to post a reversing journal entry to an allocation account. However, since the two postings to the allocation account are in different periods, the allocation is NOT the same for the reversing entry. I tried using both YTD and current period to determine the distribution and neither works. What I'm trying to do, is to post accrued wages by using the total payroll amount and allocating it to different departments based on the YTD payroll by using a variable allocation account. Since our departments don't change much this should give me a pretty good estimate of accrued wag...

Why is the font tab missing from Format Control box?
I'm trying to set up option buttons in my excel file, but I cannot find a way to change the font of the text in the option button. In the excel help page it says to select the control, right click, select the Format Control button, then select the "Font" tab. For some reason... I'm not finding this "Font" tab. Am I missing something? If you are using an Option button from the Forms Toolbar there is no Font changing. Try an Option Button from the Control Toolbox. Then right-click>Properties. You will find you can make many customizations, inclu...

Login Control form authentication to Active Directory (AD)
Hello, We have a form designed using Visual Web Developer (VWD) 2008 (Express Edition), which utilizes the Login control. The form works fine when launched via VWD 2008. That is, when typing in the credentials (username & password) at the Login.aspx form, the account is successfully authenticated against AD, and the user is directed to the Default.aspx page. However, when we launch the site via IIS 7.0 the authentication against AD does not work. If we type in the "correct" credentials, the Login.aspx page simply re-displays (with no error message). This...