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

Unable to set focus to window application using WM_SETFOCUS...?

1 view
Skip to first unread message

Mark Johnson

unread,
May 21, 1996, 3:00:00 AM5/21/96
to

BC4.5, win95, win3.x
-------------------------------

I'm trying to set focus to some an applications using WM_SETFOCUS, but the
windows won't respond. However, the windows do respond to WM_CLOSE messages.
I don't understand what's happening here. For example:

hAppInst = (HINSTANCE)WinExec("c:\\windows\\calc.exe", SW_SHOW);
...
hAppWnd = GetHWndFromHInstance(hAppInst);
::PostMessage(hAppWnd, WM_SETFOCUS, (WPARAM)HWindow, 0L);

Windows Calculator program does not get focus, however:

hAppInst = (HINSTANCE)WinExec("c:\\windows\\calc.exe", SW_SHOW);
...
hAppWnd = GetHWndFromHInstance(hAppInst);
::PostMessage(hAppWnd, WM_CLOSE, 0, 0L);

works beautifully... what's the catch?

thanks for your help, mark.

---= -=- -=- =---
..we come spinning out of nothingness scattering stars like dust; look at
these worlds spinning out of nothingness -- this is within your power. out
beyond ideas of right doing and wrong doing there is a field - i'll meet you
there. -- rumi

Norman Bullen

unread,
May 21, 1996, 3:00:00 AM5/21/96
to Mark Johnson
I'm just guessing by I would say that "focus" is a concept that applies
to child windows (usually controls) belonging to a parent(a dialog) and
for it to have any affect the parent must be active. Try sending a
WM_ACTIVATE instead of WM_SETFOCUS.


Andrew Walker

unread,
May 22, 1996, 3:00:00 AM5/22/96
to

mjoh...@centuryinter.net (Mark Johnson) wrote:
>BC4.5, win95, win3.x
>-------------------------------
>
>I'm trying to set focus to some an applications using WM_SETFOCUS, but the
>windows won't respond. However, the windows do respond to WM_CLOSE messages.
>I don't understand what's happening here. For example:
>
> hAppInst = (HINSTANCE)WinExec("c:\\windows\\calc.exe", SW_SHOW);
> ...
> hAppWnd = GetHWndFromHInstance(hAppInst);
> ::PostMessage(hAppWnd, WM_SETFOCUS, (WPARAM)HWindow, 0L);
>
>Windows Calculator program does not get focus, however:
>
> hAppInst = (HINSTANCE)WinExec("c:\\windows\\calc.exe", SW_SHOW);
> ...
> hAppWnd = GetHWndFromHInstance(hAppInst);
> ::PostMessage(hAppWnd, WM_CLOSE, 0, 0L);
>
>works beautifully... what's the catch?
>
>thanks for your help, mark.
>
>
>---= -=- -=- =---
>..we come spinning out of nothingness scattering stars like dust; look at
>these worlds spinning out of nothingness -- this is within your power. out
>beyond ideas of right doing and wrong doing there is a field - i'll meet you
>there. -- rumi


You should use the API function SetFocus(). The WM_SETFOCUS message does
not serve the purpose you want. Read the Windows API help.


Alf P. Steinbach

unread,
May 22, 1996, 3:00:00 AM5/22/96
to

Mark Johnson wrote:
> I'm trying to set focus to some an applications using WM_SETFOCUS, but the
> windows won't respond. However, the windows do respond to WM_CLOSE messages.
> I don't understand what's happening here.

Some messages have an *effect* (by way of default processing in DefWindowProc),
other messages are just notifications of things happening. WM_CLOSE is in the
former category. WM_SETFOCUS is in the latter category. Documentation is
often vague about this.

- Alf

0 new messages