Lets say I have a form with two text boxes txt1 and txt2. I also have a
Context Menu cm1 with a single menu item mnuToUpper. I set the ContextMenu
property of both text boxes to cm1.

At Runtime when mnuToUpper_Click() is fired, how do I determine which text
box contents I should convert to upper case?

--
Ron W
www.WorksRite.com

RE: How to find the Parent Control of a Context Menu by Joe

Joe
Thu Aug 17 10:31:03 CDT 2006

The control that has focus, I would imagine.

If there is the possibility that neither control has focus when
mnuToUpper_Click() is fired, then do nothing:

void Project1::OnToUpperClick()
{
if (txt1 has focus)
{
txt1.Text = ToUpper(txt1.Text);
}
else if (txt2 has focus)
{
txt2.Text = ToUpper(txt2.Text);
}
}

I'm struggling with this whole VC thing, so the code above certainly will
not compile, but you get my drift. Right?

If you (or someone else) can write the psudo-code above in a way that
actually works, I would appreciate it if you'd display it in its correct form.

Re: How to find the Parent Control of a Context Menu by Ron

Ron
Thu Aug 17 10:51:00 CDT 2006

Well that's my problem, the text box that the Context Menu pop'd up in, does
not get the focus. I can't believe that something seemingly as simple as
this could possibly be so obtuse.

--
Ron W
www.WorksRite.com
"Joe" <Joe@discussions.microsoft.com> wrote in message
news:A9974B83-2087-4E26-BF66-479C92BBB99E@microsoft.com...
> The control that has focus, I would imagine.
>
> If there is the possibility that neither control has focus when
> mnuToUpper_Click() is fired, then do nothing:
>
> void Project1::OnToUpperClick()
> {
> if (txt1 has focus)
> {
> txt1.Text = ToUpper(txt1.Text);
> }
> else if (txt2 has focus)
> {
> txt2.Text = ToUpper(txt2.Text);
> }
> }
>
> I'm struggling with this whole VC thing, so the code above certainly will
> not compile, but you get my drift. Right?
>
> If you (or someone else) can write the psudo-code above in a way that
> actually works, I would appreciate it if you'd display it in its correct
form.



Re: How to find the Parent Control of a Context Menu by Joe

Joe
Thu Aug 17 11:18:02 CDT 2006

I had a case like that once, and here's what I did:

Declare a boolean value, call it bTxt1Focus. Whenever your textbox txt1
receives focus, set it to true; whenever your textbox txt2 receives focus,
set it to false.

Then, in your code, modify it to something like:

void Project1::OnToUpperClick()
{
if (bTxt1Focus == true)
{
txt1.Text = ToUpper(txt1.Text);
}
else
{
txt2.Text = ToUpper(txt2.Text);
}
}

Would something like that work?

"Ron Weiner" wrote:

> Well that's my problem, the text box that the Context Menu pop'd up in, does
> not get the focus. I can't believe that something seemingly as simple as
> this could possibly be so obtuse.
>


Re: How to find the Parent Control of a Context Menu by Ron

Ron
Thu Aug 17 12:01:42 CDT 2006

I appreciate your help, but what if txt2 has the focus, then the user tap'd
/ held txt1 and choose ToUpper from the context menu. In this scenario txt2
was the last to have the focus, txt1 NEVER received the focus and now the
user wants to make txt1 uppercase. Can it really be this hard?

--
Ron W
www.WorksRite.com
"Joe" <Joe@discussions.microsoft.com> wrote in message
news:05FD3BD1-85FC-4B69-9BE7-3EFCE541670F@microsoft.com...
> I had a case like that once, and here's what I did:
>
> Declare a boolean value, call it bTxt1Focus. Whenever your textbox txt1
> receives focus, set it to true; whenever your textbox txt2 receives focus,
> set it to false.
>
> Then, in your code, modify it to something like:
>
> void Project1::OnToUpperClick()
> {
> if (bTxt1Focus == true)
> {
> txt1.Text = ToUpper(txt1.Text);
> }
> else
> {
> txt2.Text = ToUpper(txt2.Text);
> }
> }
>
> Would something like that work?
>
> "Ron Weiner" wrote:
>
> > Well that's my problem, the text box that the Context Menu pop'd up in,
does
> > not get the focus. I can't believe that something seemingly as simple
as
> > this could possibly be so obtuse.
> >
>



Re: How to find the Parent Control of a Context Menu by Joe

Joe
Thu Aug 17 13:32:57 CDT 2006

Well, you could add something like this:

int rep;
CString strQ;
strQ.Format("Convert %s to %s?", txt1.Text, ToUpper(txt1.Text));
rep = MessageBox(strQ, "Confirm Conversion", MB_YESNO | MB_ICONQUESTION);
if (rep == IDYES)
{
txt1.Text = ToUpper(txt1.Text);
}
else
{
strQ = _T("Please select the text box you would like to convert to upper
case.");
MessageBox(strQ, "Conversion Help", MB_OK | MB_ICONINFORMATION);
}

Not as pretty.

Of course, you could also put more event handlers for your CEdit control
into your code, like something to handle the OnChange and OnSetFocus.
Anytime one of these is accessed, update your boolean value.

Otherwise, I'm at a loss as to what to recommend.

"Ron Weiner" wrote:

> I appreciate your help, but what if txt2 has the focus, then the user tap'd
> / held txt1 and choose ToUpper from the context menu. In this scenario txt2
> was the last to have the focus, txt1 NEVER received the focus and now the
> user wants to make txt1 uppercase. Can it really be this hard?