All UpdataData(TRUE/FALSE) does is call DoDataExchange. Now if you have
saved/validated or set depending on the bool paramater of UpdateData.
AliR.
Joseph M. Newcomer wrote:
See below...
On Thu, 05 Jun 2008 20:12:34 +0200, WP <invalid@invalid.invalid> wrote:
Hello! I have done very little MFC programming since last summer but
now
I'm back again. One of the things I learned about late during my last
MFC session was DoDataExchange. Now I have a few old mfc projects
which
are currently using GetDlgItem() and I want to "fix" them. However,
fixing them turned out to be much more difficult than I anticipated...
****
Depends what you mean by "fix". If by "fix" you mean "I'm calling
UpdateData" then you
lose, big. I think this is a very poorly designed technology and it
should be avoided.
THere is no reason to use GetDlgItem, but there is also no reason to
use
UpdateData.
Mostly, when I get code that doesn't work, I fix it by first removing
all
UpdateData
calls.
****
No, not using UpdateData(). In fact, I have never used Updatedata(), I
don't even know how it works, but I do know that many have said to stay
away from it, so I am. I just wanted to replace my GetDlgItem() calls
and
that's done now.
Last time I was using MSVC++ 2005 sp1 but now I'm using MSVC++ 2008,
so
my old projects are in 2005:s format. I started by converting my only
project that was using DoDataExchange to MSVC++ 2008, the program
compiles and runs fine. I didn't have to modify any code or my
resource
files.
Then I converted a project that's using GetDlgItem() and the problem
here's that in the resource editor the option "Add variable..." when I
right click a control placed on the dialog is grayed out. I can only
select "Add class..." (which is for the dialog itself, right?).
****
There are lots of bugs in VS2005 with respect to adding control
variables. Mostly, we
just add them "by hand" these days, because the "new improved" system
is
so screwed up.
Just add a declaration
CWhatever c_MyWhateverControl;
and add the line
DDX_Control(pDX, IDC_WHATEVER, c_MyWhateverControl);
given the flakiness of VS these days, this is, alas, the most efficient
way to add control
variables. Do not use data variables within your dialog.
****
This is what I'm doing. One of the reasons I had such problems with the
resource editor was that my dialog was missing an IDD assigned the
dialog
resource ID (as described earlier in the thread). Also, first I had
accidently removed the call to CDialog::OnInitDialog() first in my
OnInitDialog() so DoDataExchange() wasn't called (in time, at least).
I found that if I remove my already written dialog class (I #if 0:ed
it
out) and add a class to the dialog, then "Add variable" gets enabled.
Woohoo, I solved it there I thought at first, but it didn't last long
because as soon as I had modified the generated code to contain the
actual logic it was supposed to contain, "Add variable..." was grayed
out again.
So I checked my converted project that was already using
DoDataExchange,
that actually works but I see the same behavior in the resource
editor,
"Add variable..." is grayed out. Where's the information stored that
dynamic data exchange should be used anyway?
Sigh, long post, hope you made it this far...guess my question is how
do
I, in MSVC++ 2008, convert existing projects from using GetDlgItem()
to
using dynamic data exchange? This is driving me crazy, spent more than
three hours on it already.
Hope you could make sense of this post, if not, let me know and I will
clarify. I can even upload screenshots to my website if needed. As I
said in the beginning, I haven't used MFC for some time and I feel
rusty.
- Eric
Joseph M. Newcomer [MVP]
- Eric