From: Joseph M. Newcomer on 11 May 2010 11:31 See below... On Tue, 11 May 2010 09:53:25 +0200, Oliver Regenfelder <oliver.regenfelder(a)gmx.at> wrote: >Hello Joseph, > >I have a question regarding control variables and their binding to >controls. > >Joseph M. Newcomer wrote: >> A control is bound to a Control variable using the DDX_Control call; note that I said I >> avoid DDX *except* for the DDX_Control calls. I never, ever use any DDX control that >> returns a value! > >The DDX_Control calls are placed in the DoDataExchange Method, which is >called everytime on UpdateData. But it seems to me from the >described/observed that it only takes one call to bind the control >variable to the windows control itself and from there on any methods >of the control variable work on the control ''instantaneuously'' >(meaning no more need for an UpdateData call). Am I right with this >observation? **** DDX_Control handles the issue of multiple calls to DoDataExchange correctly. When your OnInitDialog calls CDialog::OnInitDialog, CDialog::OnInitDialog calls DoDataExchange, so once the superclass OnInitDialog is called, the controls are bound. After that, any method of the class of the control can be invoked on the variable to which the control is bound. These almost always end up being implemented as a SendMessage to the control. And if you look at any product I deliver, there is never an UpdateData call in any CFormView or CDialog derived class. So I consider the whole idea superfluous. Especially because it doesn't work in any reasonable way. I find more errors in code that relies on it than code that doesn't rely on it. **** > >A second question (in case I am right on the first one). If controls >and control variables are bound on the first call to DDX_Control, then >why is that binding call placed in a method that potentially gets >called several times, and not somewhere in a fixed dialog initialization >method? **** Why should it matter? Answer: it doesn't, so don't worry about it. joe **** > >Best regards, > >Oliver Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Oliver Regenfelder on 11 May 2010 12:38 Hello, Thanks for the explanation. > **** >> A second question (in case I am right on the first one). If controls >> and control variables are bound on the first call to DDX_Control, then >> why is that binding call placed in a method that potentially gets >> called several times, and not somewhere in a fixed dialog initialization >> method? > **** > Why should it matter? Answer: it doesn't, so don't worry about it. > joe Well it doesn't really matter. I was just wondering why they didn't separate one time setup code (DDX_Control) from repeatedly called data update methods (DDX_text,...). Best regards, Oliver
From: Oliver Regenfelder on 11 May 2010 12:41 Hello, RB wrote: > Currently I am struggling with > hard to reach easy. I think my problem is that my app requirements have > reached a level beyond my programming competence and I will have to return > to the books I first read years ago. I will have to practice the more advanced > concepts I have not seen since my first reading long ago. If you have to learn for new anyway why don't you have a look at C# and ..Net? You don't have to deal with 'legacy' MFC stuff so you could just as easy go for the newer technologies. Best regards, Oliver
From: Stephen Myers on 11 May 2010 12:54 Oliver Regenfelder wrote: > Hello, > > RB wrote: >> Currently I am struggling with >> hard to reach easy. I think my problem is that my app requirements have >> reached a level beyond my programming competence and I will have to >> return >> to the books I first read years ago. I will have to practice the more >> advanced >> concepts I have not seen since my first reading long ago. > > If you have to learn for new anyway why don't you have a look at C# and > ..Net? You don't have to deal with 'legacy' MFC stuff so you could just > as easy go for the newer technologies. > > Best regards, > > Oliver I second this suggestion. Any number of deficiencies in MFC are handled better in C#. Steve
From: David Ching on 11 May 2010 13:00
"Oliver Regenfelder" <oliver.regenfelder(a)gmx.at> wrote in message news:c4538$4be90cf5$5477403e$26252(a)news.inode.at... > The DDX_Control calls are placed in the DoDataExchange Method, which is > called everytime on UpdateData. But it seems to me from the > described/observed that it only takes one call to bind the control > variable to the windows control itself and from there on any methods > of the control variable work on the control ''instantaneuously'' (meaning > no more need for an UpdateData call). Am I right with this > observation? > > A second question (in case I am right on the first one). If controls > and control variables are bound on the first call to DDX_Control, then > why is that binding call placed in a method that potentially gets > called several times, and not somewhere in a fixed dialog initialization > method? > The binding takes place once invisibly by MFC when your window/dialog is constructed. DoDataExchange() is a virtual functioin containing your AFX_DATA_MAP which specifies what member variables are bounded to what HWND controls. DDX_Control binds a member variable like CEdit m_myEdit; to a window control (HWND). It is not used with UpdateData(). DDX_Text binds a member variable like CString m_strEditContents; to e.g. an edit box's contents. To refresh it's value you must call UpdateData(). -- David |