For Programmers: Free Programming Magazines  


Home > Archive > VC Language > November 2005 > How can set the input focus for the Edit Box of another process









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How can set the input focus for the Edit Box of another process
John Carson

2005-11-23, 7:04 pm

"aman" <aman@hotmail.com> wrote in message
news:OtIw5ND8FHA.636@TK2MSFTNGP10.phx.gbl
>
> it can set the input focus for the ComboBox of another process, but
> can't for Edit Box, Why?


WM_SETFOCUS is a message sent by the operating system to a window to notify
it that it has gained the focus. You have no business sending it yourself
and no reason to expect it to have the effect you s. The fact that it
seems to work for a ComboBox is just good luck (or bad luck, because it has
encouraged you along a wrong path).

The way to set focus to a window is with the function SetFocus. In order to
do this from another process, some trickery is required, the simplest of
which is to use AttachThreadInput. See the MSDN documentation for SetFocus
and AttachThreadInput.

--
John Carson

Igor Tandetnik

2005-11-23, 7:04 pm

aman <aman@hotmail.com> wrote:
> But I don't understand yet, Why can't I use SendMessage function to
> do it?


WM_SETFOCUS is not the "do something" kind, it's "something has happend,
just in case you are interested" kind. It does not by itself set the
focus anywhere. Rather, if the control aquired focus for whatever
reason, WM_SETFOCUS is sent to this control to allow it to, say, change
the appearance (e.g. a list box might want to draw a focus rectangle
around an item).

> I use spy++ and get the window message with press TAB key in
> fact, I find trigger the WM_KILLFOCUS message and the WM_SETFOCUS
> message


You are confusing cause and effect. Hitting TAB key is the cause (well,
actually, the dialog box calling SetFocus in response to TAB key is the
cause). The messages are the effect.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


aman

2005-11-24, 7:59 am

Thanks.
It seems I err in that question.
I think the "WM_SETFOCUS" message is the "cause"(do something) all along. be
similar to the "CBN_SETFOCUS" notification message is the "effect"(something
has happend, just in case you are interested) yet.
so, I don't think the "CBN_SETFOCUS" notification message has any use,
right?

With best wishes

"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:uzzFgzE8FHA.2040@TK2MSFTNGP14.phx.gbl...
> aman <aman@hotmail.com> wrote:
>
> WM_SETFOCUS is not the "do something" kind, it's "something has happend,
> just in case you are interested" kind. It does not by itself set the
> focus anywhere. Rather, if the control aquired focus for whatever
> reason, WM_SETFOCUS is sent to this control to allow it to, say, change
> the appearance (e.g. a list box might want to draw a focus rectangle
> around an item).
>
>
> You are confusing cause and effect. Hitting TAB key is the cause (well,
> actually, the dialog box calling SetFocus in response to TAB key is the
> cause). The messages are the effect.
> --
> With best wishes,
> Igor Tandetnik
>
> With sufficient thrust, pigs fly just fine. However, this is not
> necessarily a good idea. It is hard to be sure where they are going to
> land, and it could be dangerous sitting under them as they fly
> overhead. -- RFC 1925
>
>



Igor Tandetnik

2005-11-24, 7:59 am

"aman" <aman@hotmail.com> wrote in message
news:OcK0$uP8FHA.2192@TK2MSFTNGP14.phx.gbl
> It seems I err in that question.
> I think the "WM_SETFOCUS" message is the "cause"(do something) all
> along. be similar to the "CBN_SETFOCUS" notification message is the
> "effect"(something has happend, just in case you are interested) yet.
> so, I don't think the "CBN_SETFOCUS" notification message has any use,
> right?


Not at all. WM_SETFOCUS is sent to the control that got foucs.
CBN_SETFOCUS is then sent by that control to its parent. Without it, the
parent (e.g. the dialog box) would have a hard time finding out that the
control has acquired focus. You typically don't write the window proc
for each control, but you do write one for the dialog, and that's where
you'd prefer to receive your notifications.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com