Board index » cppbuilder » Re: Focus

Re: Focus


2005-02-25 10:04:13 AM
cppbuilder25
Georges wrote:
Quote
Jos? many thanks for your help - I've saved all that in case I need it again
some time - in the meantime I got round the problem by calling setFocus from
outside SetupWindow();

I'm most grateful for your help

Georges
You're welcome.
/JJ.
--
** Para responderme directamente, cambie 'jose_j_armenta'
por 'jose_armenta'
** To respond directly, change 'jose_j_armenta' by
'jose_armenta'
 
 

Re:Re: Focus

Many thanks to you. Actually both formats seem to work but the problem
occurs only when they are called during SetupWindow(); I've got round it
by setting the focus elsewhere in the routine - works a treat.
many thanks again - sorry for the delay in this reply bt have been away!
Bruce Salzman wrote:
Quote
>Georges < XXXX@XXXXX.COM >writes:
>
>>I have several TEdits in a dialog box (5.02), I want to bring the
>>cursor into
>>a specified one. I've tried
>>EBox[3]->SetFocus();
>>but that doesn't work.

Shouldn't that be SetControlFocus(EBox[3]->HWindow)?

--
Bruce
 

Re:Re: Focus

Jos? many thanks for your help - I've saved all that in case I need it again
some time - in the meantime I got round the problem by calling setFocus from
outside SetupWindow();
I'm most grateful for your help
Georges
"Jos?J. Armenta E." wrote:
Quote
I found this workaround (OK, maybe more work *and* rounds) many years
ago, and embedded it in a macro:

#define POSTCOMMAND(w,n) ::PostMessage(w, WM_COMMAND,(WPARAM)n, \
MAKELPARAM((HWND)LOWORD(GetDlgItem(n)),HIWORD(BN_CLICKED)))

Later, is used in SetupWindow:

void SetupWindow()
{
TDialog::SetupWindow();
POSTCOMMAND(HWindow,11111);
}

And managed in the related response function:

void PostEntry()
{
EBox[3]->SetFocus();
}

DEFINE_RESPONSE_TABLE1(YourDialog,TDialog)
EV_COMMAND(11111,PostEntry),
END_RESPONSE_TABLE;

or within the EvCommand msmber function:

LRESULT EvCommand(uint id, HWND hwnd, uint NotifyCode)
{
if(NotifyCode==BN_CLICKED)
{
switch(id)
{
case IDOK: // aceptar
case IDCANCEL: // cancelar
break;
case 11111:
EBox[3]->SetFocus();
break;
}
}
return TDialog::EvCommand(id,hwnd,NotifyCode);
}

I don't like to deal with EV_COMMAND response function, because in the
vast majority of my dialogs, the command buttons are used mainly to call
functions that are not contained on them, and feel more easy to
manage the commands within the EvCommand member function.

Of course, IdleAction will work well, but the previous method assure
that the call will be made only one time, without the creation of an
additional variable that maybe will be used for that purpose, only. Also
I feel this method more suitable for other circumstances, like testing
for a premature program or dialog termination condition, for example,
but this can a taste-related issue, and, surely, too, exists another
more elegant and/or simple way to deal whit this :o).

/JJ.

Georges wrote:
>
>"Thomas Maeder [TeamB]" wrote:
>
>
>>"Jos?J. Armenta E." < XXXX@XXXXX.COM >writes:
>>
>>
>>>EBox[3]->SetFocus(); should work OK. This fails if you make the call
>>>from SetupWindow. If this is the case, you need to call the method from
>>>a point after the window/dialog creation is completed and visible, like
>>>in the following code:
>>>
>>>void SetupWindow()
>>>{
>>>TDialog::SetupWindow();
>>>::PostMessage(HWindow, WM_COMMAND,(WPARAM)11111, \
>>>MAKELPARAM((HWND)LOWORD(GetDlgItem(11111)),HIWORD(BN_CLICKED)))
>>>}
>>
>>It's a long time since I last programmed the OWL.
>>
>>Could SetFocus() also be called from the dialog's IdleAction() member
>>function? That would require a flag to avoid doing it more than once,
>>but I think that the resulting code would still be simpler.
>
>
>Yes, sounds great! I'll try that and report back.
>Thanks again
>
>Gs
>
>
>

--
** Para responderme directamente, cambie 'jose_j_armenta'
por 'jose_armenta'
** To respond directly, change 'jose_j_armenta' by
'jose_armenta'
 

{smallsort}

Re:Re: Focus

Hi,
Sorry for no doubt being in the wrong NG, but this is the only one I
frequently visit. In BDS 2006 (Delphi W32) I Have a form with a TPageControl
containing a few editable TDB. controls, one of which I want to give focus
when the form is opened. And that simply will NOT work. I tried
TForm.ActiveControl, I tried SetFocus in TForm.OnShow, .OnActivate, also I
tried PostMessage(Self.Handle,WM_NEXTDLGCTL,0,0), but no luck. When the form
is opened and I manually move the mouse inside the control or use the Tab
key doing that, it woks fine, alterations I then make are neatly saved in
the dataset. No problem. I just can't do it programmatically.
Anyone please
 

Re:Re: Focus

Jennifer-Ashley wrote:
Quote
Hi,

Sorry for no doubt being in the wrong NG, but this is the only one I
frequently visit. In BDS 2006 (Delphi W32) I Have a form with a
TPageControl containing a few editable TDB. controls, one of which I
want to give focus when the form is opened. And that simply will NOT
work. I tried TForm.ActiveControl, I tried SetFocus in TForm.OnShow,
.OnActivate, also I tried PostMessage(Self.Handle,WM_NEXTDLGCTL,0,0),
but no luck. When the form is opened and I manually move the mouse
inside the control or use the Tab key doing that, it woks fine,
alterations I then make are neatly saved in the dataset. No problem.
I just can't do it programmatically.

Anyone please
You should really try to post this to the delphi.language groups for
the simple (but good) reason that many of the experts (like Peter
Below) never seem to read this group. Missing out on a response from
Peter Below is, IMO, a big loss...
--
 

Re:Re: Focus

Francois Malan wrote:
Quote

You should really try to post this to the delphi.language groups for
the simple (but good) reason that many of the experts (like Peter
Below) never seem to read this group. Missing out on a response from
Peter Below is, IMO, a big loss...
Not to say that any of the other TeamB members or people{*word*154} out in
those groups would not also be able to provide excellent advise.
--
 

Re:Re: Focus

Jennifer-Ashley wrote:
Quote
Hi,

Sorry for no doubt being in the wrong NG, but this is the only one I
frequently visit. In BDS 2006 (Delphi W32) I Have a form with a TPageControl
containing a few editable TDB. controls, one of which I want to give focus
when the form is opened. And that simply will NOT work. I tried
TForm.ActiveControl, I tried SetFocus in TForm.OnShow, .OnActivate, also I
tried PostMessage(Self.Handle,WM_NEXTDLGCTL,0,0), but no luck. When the form
is opened and I manually move the mouse inside the control or use the Tab
key doing that, it woks fine, alterations I then make are neatly saved in
the dataset. No problem. I just can't do it programmatically.

Anyone please


Have you tried setting the Form's ActiveControl property (at design
time) to the required control?
Also, make sure that the Page Control's active page is set to the parent
of the control you wish to focus.
John
 

Re:Re: Focus

Quote
Have you tried setting the Form's ActiveControl property (at design time)
to the required control?

Yes, I did. Also at runtime. No luck.
Quote
Also, make sure that the Page Control's active page is set to the parent
of the control you wish to focus.

I did that too, John, thanks.
 

Re:Re: Focus

Actually John, what I found is that the focus is indeen on the (TDBEdit)
Control, but the cursor inside it is not showing. Would there be a way to
correct that, you reckon?
"John Furlong" < XXXX@XXXXX.COM >schreef in bericht
Quote
Jennifer-Ashley wrote:
>Hi,
>
>Sorry for no doubt being in the wrong NG, but this is the only one I
>frequently visit. In BDS 2006 (Delphi W32) I Have a form with a
>TPageControl containing a few editable TDB. controls, one of which I want
>to give focus when the form is opened. And that simply will NOT work. I
>tried TForm.ActiveControl, I tried SetFocus in TForm.OnShow, .OnActivate,
>also I tried PostMessage(Self.Handle,WM_NEXTDLGCTL,0,0), but no luck.
>When the form is opened and I manually move the mouse inside the control
>or use the Tab key doing that, it woks fine, alterations I then make are
>neatly saved in the dataset. No problem. I just can't do it
>programmatically.
>
>Anyone please
>
>
Have you tried setting the Form's ActiveControl property (at design time)
to the required control?

Also, make sure that the Page Control's active page is set to the parent
of the control you wish to focus.

John
 

Re:Re: Focus

Jennifer-Ashley wrote:
Quote
Actually John, what I found is that the focus is indeen on the (TDBEdit)
Control, but the cursor inside it is not showing. Would there be a way to
correct that, you reckon?

Jennifer,
Is Autosize set to true? If not, maybe the control is not tall enough
for the font being used.
Is AutoSelect true? If not, experiment by setting it to true (this will
cause all of the text to be selected), and see if the cursor then is
visible?
Sorry, I don't have any other suggestions.
John
 

Re:Re: Focus

"John Furlong" < XXXX@XXXXX.COM >schreef in bericht
Quote
Jennifer-Ashley wrote:
>Actually John, what I found is that the focus is indeen on the (TDBEdit)
>Control, but the cursor inside it is not showing. Would there be a way to
>correct that, you reckon?
>
Jennifer,

Is Autosize set to true? If not, maybe the control is not tall enough for
the font being used.

Is AutoSelect true? If not, experiment by setting it to true (this will
cause all of the text to be selected), and see if the cursor then is
visible?

Thanks again for your response, John. Tried both, no luck. Funny thing is, I
recompiled in D7 and that does work. So, I guess I'll need some kind of
Post/SendMessage to make the blinking cursor visible within the TDBEdit,
'cause that's really the only issue now.
 

Re:Re: Focus

On Fri, 15 Sep 2006 12:31:44 +0200, Jennifer-Ashley wrote:
Quote
Sorry for no doubt being in the wrong NG, but this is the only one I
frequently visit.
Jennifer,,
Please use the appropriate technical groups and not this one. It is
not that hard to subscribe to a group long enough to post a question
and get the answers you need.
--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
 

Re:Re: Focus

Quote
On Fri, 15 Sep 2006 12:31:44 +0200, Jennifer-Ashley wrote:
>Sorry for no doubt being in the wrong NG, but this is the only one I
>frequently visit.
Marc Rohloff [TeamB] wrote:
Jennifer,,
Please use the appropriate technical groups and not this one. It is
not that hard to subscribe to a group long enough to post a question
and get the answers you need.
Right! Plus, as was previously pointed out to you, you're missing out
on getting answers from the "heavy hitters" like Peter Below, who hang
out at the language.delphi.* and components.using* forums, but never
come here.
Rick Carter
XXXX@XXXXX.COM
Chair, Delphi/Paradox SIG, Cincinnati PC Users Group
--- posted by geoForum on delphi.newswhat.com
 

Re:Re: Focus

Jennifer-Ashley wrote:
Quote

Thanks again for your response, John. Tried both, no luck. Funny
thing is, I recompiled in D7 and that does work. So, I guess I'll
need some kind of Post/SendMessage to make the blinking cursor
visible within the TDBEdit, 'cause that's really the only issue now.
Rather than adding more "kludges", I would suggest there is something in the
code that happens to not have this effect in D7 but is causing it in
BDS2006 - look for code that is *already* trying to mess with control or
form focus, perhaps that can be fixed.
--
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"Some see private enterprise as a predatory target to be shot, others
as a cow to be milked, but few are those who see it as a sturdy horse
pulling the wagon." - Winston Churchill