Board index » cppbuilder » Child form won't accept input focus

Child form won't accept input focus

Don't set any Parent property for the modal dialog form, GetStart.  It
cripples the form by sticking it to the parent form.  But now you'll
have to position it on the screen.

--
Timothy H. Buchman
========================================
City Center Theater New York NY
tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland newsgroup archives at:
http://www.mers.com/searchsite.html

Quote
Pat Henderson <phen...@flash.net> wrote in message

news:3abc0fbe$1_2@dnews...
Quote
> Here's the constructor for TfrmTutorial.  It's just the standard

code that
 

Re:Child form won't accept input focus


I have an SDI application in which I need to display a series of tutorial
screens the first time a user logs into the application.  If this is a
first-time user, I create a child form whose parent is the main form.  The
child form contains a rich edit control and three buttons.  The child
control displays just fine and is aligned with the main form's client area.
But the buttons on the child form don't accept mouse or keyboard input.
Based on some of the NG messages, I tried the TAB + ENTER keys, but that
doesn't do anything at all.  Clicking the buttons with the mouse just
produces the system "bong".  The main form doesn't have input focus
either --- if you click the X on it, you also get the system "bong" .  But
if you press the ESC key or Alt-C, the child form closes (the Cancel
property for the Cancel button on the child form is set to true & keyboard
shortcut is Alt-C).

What do I need to do so the buttons on the child form will accept mouse
input?

Here's the code that creates & displays the child form.  GetStart is the
child form; frmMain is the main form.  TfrmTutorial has Border Style set to
bsNone.  I'm using BCB 3.0.

TfrmTutorial *GetStart;
GetStart = new TfrmTutorial(Application);    // Create the child form
GetStart->Parent = frmMain;                       // Set child's parent to
main form
BringWindowToTop(GetStart);                   // Added this, but it didn't
fix the focus problem
GetStart->qInitData();                                // Perform some screen
prep
GetStart->ShowModal();
delete GetStart;

Re:Child form won't accept input focus


Quote
Pat Henderson <phender> wrote in message news:3abbdf38$1_1@dnews...
> I have an SDI application in which I need to display a series of

tutorial
<snip>
Quote
> child form; frmMain is the main form.  TfrmTutorial has Border Style
set to
> bsNone.  I'm using BCB 3.0.

> TfrmTutorial *GetStart;
> GetStart = new TfrmTutorial(Application);    // Create the child

form
This is unusual, but I suppose it's legal. Most main forms are owned
by the Application object.  Why isn't the owner frmMain or (I presume)
"this"?  In fact, since you delete the form below, it doesn't need an
owner, so you could say new TfrmTutorial(NULL)  Is the argument, in
fact, the owner of the child window?  Can you show the BCB boilerplate
part of the constructor for TfrmTutorial?  Please also show the
creation and parenting of one of the input controls on the child form.

Quote
> GetStart->Parent = frmMain;                       // Set child's
parent to
> main form
> BringWindowToTop(GetStart);                   // Added this, but it
didn't
> fix the focus problem

I think this is unnecessary, and the argument is a Windows HWND,  so
you'd say (GetStart->Handle). The function:

"The BringWindowToTop function brings the specified window to the top
of the Z order. If the window is a top-level window, it is activated.
If the window is a child window, the top-level parent window
associated with the child window is activated. "

However, GetStart has not yet been "show"n, so I don't know if this
helps you.

Quote
> GetStart->qInitData();                                // Perform
some screen
> prep
> GetStart->ShowModal();

Do you have buttons on GetStart that return ModalResults?
Quote
> delete GetStart;

Re:Child form won't accept input focus


Here's the constructor for TfrmTutorial.  It's just the standard code that
BCB generates, and I haven't added anything to it.
__fastcall TfrmTutorial::TfrmTutorial(TComponent* Owner) : TForm(Owner)
{

Quote
}

All of the components are defined in the header file for the unit, which is
shown below:
class TfrmTutorial : public TForm
{
__published: // IDE-managed Components
 TzcShapeColorBtn *btnNext;
 TzcShapeColorBtn *btnPrevious;
 TStaticText *txtFrame;
 TzcShapeColorBtn *btnClose;
 THQRichText *HQRichText1;
 TLabel *Label1;

 void __fastcall btnCloseClick(TObject *Sender);

 void __fastcall FormShow(TObject *Sender);
private: // User declarations
 void __fastcall CreateParams(TCreateParams &Params);
 int screenNumber;

public:  // User declarations
   __fastcall TfrmTutorial(TComponent* Owner);
 bool __fastcall qInitData();

Quote
};

Yes, all three buttons on frmTutorial return modal results.  What's
interesting is that frmTutorial closes if I press the ESC key or ALT+C, so I
think that means that frmTutorial has focus.  But it doesn't recognize mouse
clicks or the TAB or ENTER keys.

"Timothy H. Buchman" <tbuch...@citycenter.org> wrote in message
news:3abc0b7d_1@dnews...

Quote

> Pat Henderson <phender> wrote in message news:3abbdf38$1_1@dnews...
> > I have an SDI application in which I need to display a series of
> tutorial
> <snip>
> > child form; frmMain is the main form.  TfrmTutorial has Border Style
> set to
> > bsNone.  I'm using BCB 3.0.

> > TfrmTutorial *GetStart;
> > GetStart = new TfrmTutorial(Application);    // Create the child
> form
> This is unusual, but I suppose it's legal. Most main forms are owned
> by the Application object.  Why isn't the owner frmMain or (I presume)
> "this"?  In fact, since you delete the form below, it doesn't need an
> owner, so you could say new TfrmTutorial(NULL)  Is the argument, in
> fact, the owner of the child window?  Can you show the BCB boilerplate
> part of the constructor for TfrmTutorial?  Please also show the
> creation and parenting of one of the input controls on the child form.

> > GetStart->Parent = frmMain;                       // Set child's
> parent to
> > main form
> > BringWindowToTop(GetStart);                   // Added this, but it
> didn't
> > fix the focus problem

> I think this is unnecessary, and the argument is a Windows HWND,  so
> you'd say (GetStart->Handle). The function:

> "The BringWindowToTop function brings the specified window to the top
> of the Z order. If the window is a top-level window, it is activated.
> If the window is a child window, the top-level parent window
> associated with the child window is activated. "

> However, GetStart has not yet been "show"n, so I don't know if this
> helps you.

> > GetStart->qInitData();                                // Perform
> some screen
> > prep
> > GetStart->ShowModal();

> Do you have buttons on GetStart that return ModalResults?

> > delete GetStart;

Re:Child form won't accept input focus


I removed the lines that sets the Parent property & then added code to set
the Left, Top, Height & Width properties of the child form, and that works
OK.  Thanks for your help.

If I change GetStart to be a modeless form, can I then set its Parent
property & still have usable buttons?  I thought I had tried that (used Show
instead of showModal), but it still wouldn't work.  FYI, I'm using
CreateParams on GetStart to eliminate the window caption,

"Timothy H. Buchman" <tbuch...@citycenter.org> wrote in message
news:3abc4831$1_1@dnews...

Quote
> Don't set any Parent property for the modal dialog form, GetStart.  It
> cripples the form by sticking it to the parent form.  But now you'll
> have to position it on the screen.

> --
> Timothy H. Buchman
> ========================================
> City Center Theater New York NY
> tbuchmanPLEASE(at sign)REMOVEcitycenter.org
> Please treat this signature information as confidential.
> ========================================
> Search .borland newsgroup archives at:
> http://www.mers.com/searchsite.html

> Pat Henderson <phen...@flash.net> wrote in message
> news:3abc0fbe$1_2@dnews...
> > Here's the constructor for TfrmTutorial.  It's just the standard
> code that

Re:Child form won't accept input focus


I don't want to change the subject, but have you already done this
"visually" in the IDE, and are now converting it to run-time creation?
I think most of your problems and extra work are coming from creating
the forms yourself.  This is something the IDE does very well.  Just
my 2 cents.

Quote
Pat Henderson <phender> wrote in message news:3abd1ab0_1@dnews...
> I removed the lines that sets the Parent property & then added code
to set
> the Left, Top, Height & Width properties of the child form, and that
works
> OK.  Thanks for your help.

Have you tried setting GetStart->Position=poScreenCenter;  ?
GetStart->Align=alClient; might also be helpful if the second form is
parented to the first form.

Quote

> If I change GetStart to be a modeless form, can I then set its
Parent
> property & still have usable buttons?  I thought I had tried that

(used Show

I'm not sure, you'll have to try it.  This is not my forte, since I
use mostly autocreated forms.  If you are trying to control the user's
options until they have seen the GetStart dialog, why not ->Hide() the
main form, or use the ShowModal()?  If you had BCB5, I'd ask whether
TFrame was what you were really looking for.

Think about the gruesomely prevalent applications Word and Excel.
When the program wants to give *you* orders, or you want to give the
program orders, it's done with ordinary dialog boxes with "x" buttons
and captions.  Is that so bad?  It sounds like you want these special
dialogs to look like they are part of the main window.  Would it work
to maximize (GetStart->WindowState=wsMaximized;) so it covers the
entire application?

Quote
> instead of showModal), but it still wouldn't work.  FYI, I'm using
> CreateParams on GetStart to eliminate the window caption,

Would you be satisfied with one of the standard
GetStart->BorderStyle=bs..... choices?
Quote

Anyhow, to get back to what *you* want to do, I think you should read
*all* the messages in this thread:
http://www.mers.com/MERLIST/BORLAND/PUBLIC/CPPBUILDER/VCL/COMPONENTS/U
SING/13449.HTML
(very long link - repaste in your browser URL window until it's all
there, ending in HTML)

Although this thread uses the IDE's autocreated forms, the techniques
Mark Cashman describes are perfectly suitable for dynamically created
components like you are using.  Good luck.
-------
Timothy H. Buchman
========================================
City Center Theater, New York NY
mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland message archive on http://www.mers.com/searchsite.html

Re:Child form won't accept input focus


Thanks, Timothy.  I checked out the thread that you mentioned, and it was
very helpful.

To answer your questions about my application, I created the child form
visually through the IDE, but I don't use the auto-create feature, since I
only need to display the form the first time a user logs into the app.

And yes, I'm trying to have the child form look like it's part of the main
form.  In fact, the main form must be visible, since the tutorial (child)
form explains various features of the main form.

Thanks so much for your help.  Mark Cashman's technique of reparenting the
panel from the child form to the main form is excellent.

"Timothy H. Buchman" <tbuch...@citycenter.org> wrote in message
news:3abd63f2$1_2@dnews...

Quote
> I don't want to change the subject, but have you already done this
> "visually" in the IDE, and are now converting it to run-time creation?
> I think most of your problems and extra work are coming from creating
> the forms yourself.  This is something the IDE does very well.  Just
> my 2 cents.

> Pat Henderson <phender> wrote in message news:3abd1ab0_1@dnews...
> > I removed the lines that sets the Parent property & then added code
> to set
> > the Left, Top, Height & Width properties of the child form, and that
> works
> > OK.  Thanks for your help.

> Have you tried setting GetStart->Position=poScreenCenter;  ?
> GetStart->Align=alClient; might also be helpful if the second form is
> parented to the first form.

> > If I change GetStart to be a modeless form, can I then set its
> Parent
> > property & still have usable buttons?  I thought I had tried that
> (used Show

> I'm not sure, you'll have to try it.  This is not my forte, since I
> use mostly autocreated forms.  If you are trying to control the user's
> options until they have seen the GetStart dialog, why not ->Hide() the
> main form, or use the ShowModal()?  If you had BCB5, I'd ask whether
> TFrame was what you were really looking for.

> Think about the gruesomely prevalent applications Word and Excel.
> When the program wants to give *you* orders, or you want to give the
> program orders, it's done with ordinary dialog boxes with "x" buttons
> and captions.  Is that so bad?  It sounds like you want these special
> dialogs to look like they are part of the main window.  Would it work
> to maximize (GetStart->WindowState=wsMaximized;) so it covers the
> entire application?

> > instead of showModal), but it still wouldn't work.  FYI, I'm using
> > CreateParams on GetStart to eliminate the window caption,

> Would you be satisfied with one of the standard
> GetStart->BorderStyle=bs..... choices?

> Anyhow, to get back to what *you* want to do, I think you should read
> *all* the messages in this thread:
> http://www.mers.com/MERLIST/BORLAND/PUBLIC/CPPBUILDER/VCL/COMPONENTS/U
> SING/13449.HTML
> (very long link - repaste in your browser URL window until it's all
> there, ending in HTML)

> Although this thread uses the IDE's autocreated forms, the techniques
> Mark Cashman describes are perfectly suitable for dynamically created
> components like you are using.  Good luck.
> -------
> Timothy H. Buchman
> ========================================
> City Center Theater, New York NY
> mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
> Please treat this signature information as confidential.
> ========================================
> Search .borland message archive on http://www.mers.com/searchsite.html

Other Threads