From: WP on
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...

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?).
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
From: AliR (VC++ MVP) on
I think if you delete the .aps file in your projects directory and reload
the project, things should be fixed.

AliR.


"WP" <invalid(a)invalid.invalid> wrote in message
news:6aqokkF396mrnU1(a)mid.individual.net...
> 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...
>
> 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?).
> 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


From: WP on
AliR (VC++ MVP) wrote:
> I think if you delete the .aps file in your projects directory and reload
> the project, things should be fixed.
>
> AliR.

Hello AliR and thanks for the quick reply! That was a good tip you
suggested and I'm sure it will be useful. However, I think I might have
solved my problem.

I thought that when you, using the resource editor, added a (control)
variable something "magical" under the hood happened (but I wasn't sure
what it was), so you had to do it that way if you want to have dynamic
data exchange. However, if you already have a dialog class that you want
to convert from using GetDlgItem(), you don't have to do something in
the resource editor to set up dynamic data exchange (hope that's the
correct the term). You do, however, have to call CDialog's
OnInitDialog() if you have overridden OnInitDialog in your dialog class
or DoDataExchange will not be called. I had forgotten to call
CDialog::OnInitDialog and soon as I added that call it worked, my
DoDataExchange was called (it wasn't called before). This has been a
very good lesson for me.

However, it brings me something I've been thinking about: For which
member functions should always make sure to call the base
implementation? I'm unsure about that.

- Eric
[snip]
From: AliR (VC++ MVP) on
The problem you described was the "Add variable" was disabled. compelety
different than DoDataExchange not getting called.

As far as in which overwriten methods you should call the superclasses
method, every single one unless you specifically don't want whatever its
that the superclass does.

AliR.


"WP" <invalid(a)invalid.invalid> wrote in message
news:6aqt5iF37oetkU1(a)mid.individual.net...
> AliR (VC++ MVP) wrote:
>> I think if you delete the .aps file in your projects directory and reload
>> the project, things should be fixed.
>>
>> AliR.
>
> Hello AliR and thanks for the quick reply! That was a good tip you
> suggested and I'm sure it will be useful. However, I think I might have
> solved my problem.
>
> I thought that when you, using the resource editor, added a (control)
> variable something "magical" under the hood happened (but I wasn't sure
> what it was), so you had to do it that way if you want to have dynamic
> data exchange. However, if you already have a dialog class that you want
> to convert from using GetDlgItem(), you don't have to do something in the
> resource editor to set up dynamic data exchange (hope that's the correct
> the term). You do, however, have to call CDialog's OnInitDialog() if you
> have overridden OnInitDialog in your dialog class or DoDataExchange will
> not be called. I had forgotten to call CDialog::OnInitDialog and soon as I
> added that call it worked, my DoDataExchange was called (it wasn't called
> before). This has been a very good lesson for me.
>
> However, it brings me something I've been thinking about: For which member
> functions should always make sure to call the base implementation? I'm
> unsure about that.
>
> - Eric
> [snip]


From: WP on
AliR (VC++ MVP) wrote:
> The problem you described was the "Add variable" was disabled. compelety
> different than DoDataExchange not getting called.

Sorry if I made you irritated, I didn't mean to sound ungrateful or that
you didn't help. I simply didn't describe my problem well enough in my
first post (even though it was so long, lol). I simply thought I had to
go through the resource editor to make dynamic data exchange work. I
should have showed my code also and said that my DoDataExchange wasn't
called (but I was so sure it was due to me not being able to set it up
in the resource editor, lol). Your help is much appreciated and that
..aps-file isn't removed during a make clean, right? (Can't try it from
the computer I'm currently on.)

>
> As far as in which overwriten methods you should call the superclasses
> method, every single one unless you specifically don't want whatever its
> that the superclass does.

Right, thanks, I will go through my code and check where I've forgotten
to do this and add it so I don't get bitten later by such as missing
call as I was today.

- Eric

>
> AliR.
>
>
> "WP" <invalid(a)invalid.invalid> wrote in message
> news:6aqt5iF37oetkU1(a)mid.individual.net...
>> AliR (VC++ MVP) wrote:
>>> I think if you delete the .aps file in your projects directory and reload
>>> the project, things should be fixed.
>>>
>>> AliR.
>> Hello AliR and thanks for the quick reply! That was a good tip you
>> suggested and I'm sure it will be useful. However, I think I might have
>> solved my problem.
>>
>> I thought that when you, using the resource editor, added a (control)
>> variable something "magical" under the hood happened (but I wasn't sure
>> what it was), so you had to do it that way if you want to have dynamic
>> data exchange. However, if you already have a dialog class that you want
>> to convert from using GetDlgItem(), you don't have to do something in the
>> resource editor to set up dynamic data exchange (hope that's the correct
>> the term). You do, however, have to call CDialog's OnInitDialog() if you
>> have overridden OnInitDialog in your dialog class or DoDataExchange will
>> not be called. I had forgotten to call CDialog::OnInitDialog and soon as I
>> added that call it worked, my DoDataExchange was called (it wasn't called
>> before). This has been a very good lesson for me.
>>
>> However, it brings me something I've been thinking about: For which member
>> functions should always make sure to call the base implementation? I'm
>> unsure about that.
>>
>> - Eric
>> [snip]
>
>