Board index » cppbuilder » How can i send key strokes to underlying parent control?

How can i send key strokes to underlying parent control?


2004-03-03 12:17:24 PM
cppbuilder78
Hello.
I want to close child form when it recieves Navigation Key messages. But
when that happens i want the parent control to recive that message as well.
I implemented WMDialogKey handler to close the child form. But i m not
sure how to pass the message to its parent.
Following is what i have got so far...
//------------------------------------------------------------------------
void __fastcall TChildForm::WMDialogKey(TWMKey& Msg)
{
switch (Msg.CharCode) {
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
PostMessage(ParentForm->Handle,
Msg.Msg,
Msg.CharCode,
Msg.Unused);
Close();
break;
}
}
//------------------------------------------------------------------------
 
 

Re:How can i send key strokes to underlying parent control?

"Jaepil Kim" < XXXX@XXXXX.COM >wrote in message
Quote
PostMessage(ParentForm->Handle,
Msg.Msg,
Msg.CharCode,
Msg.Unused);
Change that to this instead:
if( HasParent() )
PostMessage(Parent->Handle, Msg.Msg, Msg.CharCode, Msg.KeyData);
Or, if you want the Parent to process the message immediately:
if( HasParent() )
Parent->Perform(Msg.Msg, Msg.CharCode, Msg.KeyData);
Or
if( HasParent() )
Parent->WindowProc(*(TMessage*)&Msg);
Or
if( HasParent() )
Parent->Dispatch(&Msg);
Gambit
 

Re:How can i send key strokes to underlying parent control?

Hi, thanks for the reply.
I could send the navigation message the parent form. Though i had one
slight problem.
When the parent form's active control is a text control. I want it to
keep the focus but change its caret position.
I tried sending message directly to the control. But not getting the
expected results.
How should i do this?
 

{smallsort}

Re:How can i send key strokes to underlying parent control?

"Jaepil Kim" < XXXX@XXXXX.COM >wrote in message
Quote
I tried sending message directly to the control. But not
getting the expected results.
Please show your actual code.
BTW, your component shouldn't even be receiving keystrokes to begin with
unless it has the focus, not some other component. Unless you have some
kind of hook installed. Do you?
Gambit
 

Re:How can i send key strokes to underlying parent control?

What i really want to do is to pass navigational key messages to the
text control which is placed on the parent form. So that the text
control can update its selection and caret position.
When i passed message to the parent form by
PostMessage(ParentForm->Handle, Msg.Msg, Msg.CharCode, Msg.KeyData);
The focus moved to a neighbour control even though the text control had
the focus.
So i tried to send the message to the text control directly by replacing
the 'ParentForm->Handle' with 'ParentForm->TextEditor->Handle'.
But after studying a bit more, i figure that i might not be able to send
the raw message directly. Is that correct?
What should i do?
Also i noticed that VK_PRIOR, VK_NEXT, VK_HOME, VK_END keys are not
captured to my message handler. What other message handler can i use to
get to their original message strucutres? I want to send these messages
to the text control on the parent form as well.
//------------------------------------------------------------------------
void __fastcall TChildForm::WMDialogKey(TWMKey& Msg)
{
switch (Msg.CharCode) {
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
PostMessage(ParentForm->TextEditor->Handle,
Msg.Msg,
Msg.CharCode,
Msg.KeyData);
Close();
break;
}
}
//------------------------------------------------------------------------
Remy Lebeau (TeamB) wrote:
Quote
Please show your actual code.

BTW, your component shouldn't even be receiving keystrokes to begin with
unless it has the focus, not some other component. Unless you have some
kind of hook installed. Do you?


Gambit


 

Re:How can i send key strokes to underlying parent control?

"Jaepil Kim" < XXXX@XXXXX.COM >wrote in message
Quote
When i passed message to the parent form by
PostMessage(ParentForm->Handle, Msg.Msg, Msg.CharCode, Msg.KeyData);

The focus moved to a neighbour control even though the text control had
the focus.
You are posting the messages to the form itself, not the Edit control. Try
this instead:
if( ParentForm->ActiveControl )
PostMessage(ParentForm->ActiveControl->Handle, Msg.Msg,
Msg.CharCode, Msg.KeyData);
Alternatively:
if( Screen->ActiveControl )
PostMessage(Screen->ActiveControl->Handle, Msg.Msg, Msg.CharCode,
Msg.KeyData);
Quote
But after studying a bit more, i figure that i might not
be able to send the raw message directly. Is that correct?
Not true. However, just sending the message is no guarantee that it will
actually be processed.
Quote
What should i do?
Why exactly do you need this? And you still haven't answered my question
regarding how you are obtaining the keystrokes to begin with if your
component is not the one with the focus at the time.
Gambit
 

Re:How can i send key strokes to underlying parent control?

I thought i made it clear... but let me try one more time.
I require this process because the child form behaves like a context
menu of a text control. The text control is placed on the parent form.
The child form is shown when the user holds the CTRL key. The child form
is shown while CTRL is pressed. But when the user uses one of the
navigational keys, i want to close/hide the child form then send the key
message to the text control. So that the caret position and selection is
updated appropriately.
Quote
Why exactly do you need this? And you still haven't answered my question
regarding how you are obtaining the keystrokes to begin with if your
component is not the one with the focus at the time.
The keystrokes are received on the child form NOT the text control. The
child form has a message handler for CM_DIALOGKEY. Included the function
at the previous message. I called it WMDialogKey by mistake but that's
the one.
Quote
You are posting the messages to the form itself, not the Edit
control. Try
Quote
this instead:

if( ParentForm->ActiveControl )
PostMessage(ParentForm->ActiveControl->Handle, Msg.Msg,
Msg.CharCode, Msg.KeyData);

I already tried that, :-) And i mentioned that i had done that at the
previous message.
Even tried to set a focus on the text control first before sending the
message.
Well... Does this mean the text control doesn't know how to handle the
messages? I guess i could be as the text editor is a ThridParty control.
What do you think?