From: Cameron_C on
Hello guys, I have one more question relating to nexted CTabCtrls.
I got some great information from Joe, and I have been able to next the
CTabCtrls although I believe I hurt myself getting it to work.

I am now in a position where I would like to change the text on a button on
the main dialog from within the nested CTabCtrl dialog.
I see two options here (maybe there are others).
First, I could pass a pointer to the button control all the way down the
nested control structures, as I am creating the nested controls. This would
be explicit, so easy to follow for future maintenance, but it seems to be a
bit "cludgy".

The second choice would be to send a message to the main dialog window to
change the text. In this case, could I just post the message to the parent,
and if the parent does not handle the message it should be passed up to its
parent, and so on.
This would appear to be a "cleaner" solution.
I guess I am looking for advice again. Which would be a better approach?
I am leaning towards the second approach.

Thanks guys.
From: AliR on
I'm assuming that the parent of your TabDialog is the CTabCtrl, and the
button is on the parent window of the CTabCtrl.

If that's the case and I was doing this, I would do this:
ASSERT(GetParent() != NULL);
ASSERT(GetParent()->GetParent() != NULL);
GetParent()->GetParent()->SendMessage(WM_.......);

AliR.

"Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message
news:1735E30C-9386-46E1-AFAA-DC5EBD7730A2(a)microsoft.com...
> Hello guys, I have one more question relating to nexted CTabCtrls.
> I got some great information from Joe, and I have been able to next the
> CTabCtrls although I believe I hurt myself getting it to work.
>
> I am now in a position where I would like to change the text on a button
> on
> the main dialog from within the nested CTabCtrl dialog.
> I see two options here (maybe there are others).
> First, I could pass a pointer to the button control all the way down the
> nested control structures, as I am creating the nested controls. This
> would
> be explicit, so easy to follow for future maintenance, but it seems to be
> a
> bit "cludgy".
>
> The second choice would be to send a message to the main dialog window to
> change the text. In this case, could I just post the message to the
> parent,
> and if the parent does not handle the message it should be passed up to
> its
> parent, and so on.
> This would appear to be a "cleaner" solution.
> I guess I am looking for advice again. Which would be a better approach?
> I am leaning towards the second approach.
>
> Thanks guys.


From: Cameron_C on
Thanks,
And if it is nested, then I guess I would expand to something like:
ASSERT(GetParent() != NULL);
ASSERT(GetParent()->GetParent() != NULL);
ASSERT(GetParent()->GetParent()->GetParent() != NULL);
ASSERT(GetParent()->GetParent()->GetParent()->GetParent() != NULL);
ASSERT(GetParent()->GetParent()->GetParent()->GetParent()->GetParent() !=
NULL);

GetParent()->GetParent()->GetParent()->GetParent()->GetParent()->SendMessage(WM_.......);

It starts to get interesting....

"AliR" wrote:

> I'm assuming that the parent of your TabDialog is the CTabCtrl, and the
> button is on the parent window of the CTabCtrl.
>
> If that's the case and I was doing this, I would do this:
> ASSERT(GetParent() != NULL);
> ASSERT(GetParent()->GetParent() != NULL);
> GetParent()->GetParent()->SendMessage(WM_.......);
>
> AliR.
>
> "Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message
> news:1735E30C-9386-46E1-AFAA-DC5EBD7730A2(a)microsoft.com...
> > Hello guys, I have one more question relating to nexted CTabCtrls.
> > I got some great information from Joe, and I have been able to next the
> > CTabCtrls although I believe I hurt myself getting it to work.
> >
> > I am now in a position where I would like to change the text on a button
> > on
> > the main dialog from within the nested CTabCtrl dialog.
> > I see two options here (maybe there are others).
> > First, I could pass a pointer to the button control all the way down the
> > nested control structures, as I am creating the nested controls. This
> > would
> > be explicit, so easy to follow for future maintenance, but it seems to be
> > a
> > bit "cludgy".
> >
> > The second choice would be to send a message to the main dialog window to
> > change the text. In this case, could I just post the message to the
> > parent,
> > and if the parent does not handle the message it should be passed up to
> > its
> > parent, and so on.
> > This would appear to be a "cleaner" solution.
> > I guess I am looking for advice again. Which would be a better approach?
> > I am leaning towards the second approach.
> >
> > Thanks guys.
>
>
> .
>
From: AliR on
I didn't think you would have that many nested windows!

If you foresee a case like that, you might want to send a message to the
parent, which turns around and sends it back to it's parent, and so on and
so forth.

AliR.

"Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message
news:F4D4E417-1383-42E7-8F9A-A6BD0B9C1AC0(a)microsoft.com...
> Thanks,
> And if it is nested, then I guess I would expand to something like:
> ASSERT(GetParent() != NULL);
> ASSERT(GetParent()->GetParent() != NULL);
> ASSERT(GetParent()->GetParent()->GetParent() != NULL);
> ASSERT(GetParent()->GetParent()->GetParent()->GetParent() != NULL);
> ASSERT(GetParent()->GetParent()->GetParent()->GetParent()->GetParent() !=
> NULL);
>
> GetParent()->GetParent()->GetParent()->GetParent()->GetParent()->SendMessage(WM_.......);
>
> It starts to get interesting....
>
> "AliR" wrote:
>
>> I'm assuming that the parent of your TabDialog is the CTabCtrl, and the
>> button is on the parent window of the CTabCtrl.
>>
>> If that's the case and I was doing this, I would do this:
>> ASSERT(GetParent() != NULL);
>> ASSERT(GetParent()->GetParent() != NULL);
>> GetParent()->GetParent()->SendMessage(WM_.......);
>>
>> AliR.
>>
>> "Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message
>> news:1735E30C-9386-46E1-AFAA-DC5EBD7730A2(a)microsoft.com...
>> > Hello guys, I have one more question relating to nexted CTabCtrls.
>> > I got some great information from Joe, and I have been able to next the
>> > CTabCtrls although I believe I hurt myself getting it to work.
>> >
>> > I am now in a position where I would like to change the text on a
>> > button
>> > on
>> > the main dialog from within the nested CTabCtrl dialog.
>> > I see two options here (maybe there are others).
>> > First, I could pass a pointer to the button control all the way down
>> > the
>> > nested control structures, as I am creating the nested controls. This
>> > would
>> > be explicit, so easy to follow for future maintenance, but it seems to
>> > be
>> > a
>> > bit "cludgy".
>> >
>> > The second choice would be to send a message to the main dialog window
>> > to
>> > change the text. In this case, could I just post the message to the
>> > parent,
>> > and if the parent does not handle the message it should be passed up to
>> > its
>> > parent, and so on.
>> > This would appear to be a "cleaner" solution.
>> > I guess I am looking for advice again. Which would be a better
>> > approach?
>> > I am leaning towards the second approach.
>> >
>> > Thanks guys.
>>
>>
>> .
>>


From: Joseph M. Newcomer on
On Thu, 3 Dec 2009 07:17:01 -0800, Cameron_C <CameronC(a)discussions.microsoft.com> wrote:

>Hello guys, I have one more question relating to nexted CTabCtrls.
>I got some great information from Joe, and I have been able to next the
>CTabCtrls although I believe I hurt myself getting it to work.
>
>I am now in a position where I would like to change the text on a button on
>the main dialog from within the nested CTabCtrl dialog.
>I see two options here (maybe there are others).
>First, I could pass a pointer to the button control all the way down the
>nested control structures, as I am creating the nested controls. This would
>be explicit, so easy to follow for future maintenance, but it seems to be a
>bit "cludgy".
****
Horrible idea, you are right to reject it. Doesn't generalize, won't handle case where
window might change from a button to something else, requires interdependencies.
****
>
>The second choice would be to send a message to the main dialog window to
>change the text. In this case, could I just post the message to the parent,
>and if the parent does not handle the message it should be passed up to its
>parent, and so on.
****
That's what I would do. So any window in between that wanted to change text could do so
also. I also have used the trick of letting the message flow upward transparently, then
from the topmost window (the one that contains the topmost CTabCtrl) do a
"SendToAllDescendants" and let someone who cares worry about it.

Third solution is to treat the topmost window as a "document" so you send a message to
change its state, and it does a SendMessageToDescendants to say "something changed"
(UpdateAllViews equivalent) and a window that wants something sends it a message that says
"I care about..." and gets a pointer/value in return (e.g., for a BOOL I'd return a value,
but for a string, I'd return a pointer)
joe
****
>This would appear to be a "cleaner" solution.
>I guess I am looking for advice again. Which would be a better approach?
>I am leaning towards the second approach.
>
>Thanks guys.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm