Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using SetFocus() in a modeless dialog doesn't seem to work properly

1,234 views
Skip to first unread message

Michael Gaudette

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
Hello! I am trying to set focus to a CEdit box in a modeless dialog
which is created in a CMDIFrameWnd....

...and the function SetFocus() doesn't work. Do I have to do anything
prior to SetFocus()?

If I try creating the dialog as a normal Modal dialog, the SetFocus
works fine.

The whole point is having the cursor flashing the the CEdit box
without click on it.

Thank you for helping.

michael....@videotron.ca

Jean-Claude Hébert

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
Maybe WM_NEXTDLGCTL.


Adeluc

DecoTech Design Software Inc.
Internet: http://www.pulsarsoft.com


Michael Gaudette <mgau...@minacom.com> wrote in message
news:374e8f9d....@news.mlink.net...

Michael Gaudette

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
On Fri, 28 May 1999 11:13:49 -0400, "Jean-Claude Hébert"
<in...@pulsarsoft.com> wrote:

I just tried using WM_NEXTDLGCTL...with no luck. I believe I have
something to do BEFORE setting the focus (or maybe after...). It
probably has something to do with the method of creation. I am
creating a CMIDChildFrm, then creating the dialog (and setting as
parent to the dialog the CMIDChildFrm created earlier.) Then, in the
OnInitDialog function I am setting to the Edit Box...

William Hammond

unread,
May 28, 1999, 3:00:00 AM5/28/99
to
Add OnSetFocus handlers for the frame and the dialog. In the frame's
OnSetFocus, set the focus to the dialog. In the dialog's OnSetFocus, set
the focus to the current control (you'll have to add a member function to
the dialog to handle this).

Michael Gaudette <mgau...@minacom.com> wrote in message

news:374ed941....@news.mlink.net...

David Wilkinson

unread,
May 29, 1999, 3:00:00 AM5/29/99
to
William:

If you use OnInitDialog() to set the focus to a control, then you must return
FALSE from OnInitDialog(). Otherwise Windows will reset the focus to the
first control in the tab order.

HTH,

David Wilkinson

===================

Joseph M. Newcomer

unread,
Jun 1, 1999, 3:00:00 AM6/1/99
to
Presumably the user does something that causes focus to shift to your
modeless dialog and as a consequence you want the dialog's focus to be
on the edit control. To do this, the action the user takes is to do a
SetFocus to the modeless dialog window. OK, that gets the dialog
activated. Now you need to get the focus set to the edit control. I
would do this by putting an OnActivate() handler in the modeless
dialog, check for WA_ACTIVE or WA_CLICKACTIVE (or both, depending on
which activations you want to have the effect), at which point you can
do
c_myEditControl.SetFocus()

where c_myEditControl is a variable name you add for a control-type
variable in ClassWizard (I use c_ instead of m_ for control variables,
so I don't have to have different names). This will set the focus to
the edit control.

A modal dialog actually does this; when control is created, if you
return TRUE from the OnInitDialog handler, the default is to set the
focus to the first visible, enabled, non-static (user-input-capable)
control. If you switch focus from the app, and switch back, the dialog
manager first saves a reference to the window that had the focus and
upon receiving the focus back, sets the focus to the window that last
had it. But for a modeless dialog, you have to handle this yourself.
joe

Joseph M. Newcomer
newc...@flounder.com
http://www3.pgh.net/~newcomer

0 new messages