Re: How to get around new limitations on SetForegroundWindow()?

From: James Brown (james.brown7_nosp_at_m_virgin.net)
Date: 03/21/04


Date: Sun, 21 Mar 2004 09:18:24 -0000


"Dean Roddey" <droddey@charmedquark.com> wrote in message
news:OBol8IvDEHA.3408@tk2msftngp13.phx.gbl...
> I have an issue that I'm not sure how to get around with setting the
> foreground window. My company is the vendor of a distributed control and
> automation product. It's concentrated on the more traditional aspects of
C&A
> so far, i.e. external device control. But I'm extending it for application
> control. But this raises a fundamental problem. The product is network
> distributed, so the bits are spread out, and among those pieces is an app
> control server programs, which is a GUI app that the user runs on any
> machines that he wants to control applications on. That server program is
a
> kind of proxy for the control system on that host, and it starts, stops,
> etc... applications based on remote commands from 'device' drivers loaded
> into various other hosts in the network (where device is an app in this
> case.)
>
> But, because of the distributed nature of the system, the user is not
> directly interacting with program that ultimately will control the app
(and
> try to feed it faked input and whatnot.) So, that server program will not
be
> the active application in most cases when commands come in. Because of the
> recent changes to foreground setting, it will not be able to bring up
> another app, that app will just blink it's task bar item and not come up.
>
> This is clearly not going to be acceptable to my users, so there has to be
a
> way around this. Clearly if a system is going to be remotely controlled,
it
> must be possible for a server program to start and stop apps and bring
them
> to the foreground as required, when that program wouldn't (under current
> rules) have the technical right to bring an app forward.
>
> So is there some way to get around this limitation? I don't see how I can
> create a useful app control system within the current limitations.
>
> ------------------------------------
> Dean Roddey
> The Charmed Quark Controller
> www.charmedquark.com
>
>

The key to solving this problem is the AttachThreadInput API call:

DWORD pid, tid;
HWND hwnd;

hwnd = GetForegroundWindow();
tid = GetWindowThreadProcessId(hwnd, &pid);

AttachThreadInput(GetCurrentThreadId(), tid, TRUE);
SetForegroundWindow(hwnd);
AttachThreadInput(GetCurrentThreadId(), tid, FALSE);

James

-- 
www.catch22.org.uk
Free Win32 Software, Source Code and Tutorials


Relevant Pages

  • Re: How to get around new limitations on SetForegroundWindow()?
    ... > is not the proper method for industrial grade app. ... my system is a control and automation system. ... for a given application will connect to the proxy on the host it is told to, ... that only a current foreground app can bring other apps to the foreground. ...
    (microsoft.public.win32.programmer.ui)
  • Re: How to get around new limitations on SetForegroundWindow()?
    ... is not the proper method for industrial grade app. ... > foreground window. ... > so far, i.e. external device control. ... that server program will not ...
    (microsoft.public.win32.programmer.ui)
  • How to get around new limitations on SetForegroundWindow()?
    ... so far, i.e. external device control. ... distributed, so the bits are spread out, and among those pieces is an app ... that server program will not be ... recent changes to foreground setting, it will not be able to bring up ...
    (microsoft.public.win32.programmer.ui)
  • Re: How to get around new limitations on SetForegroundWindow()?
    ... > must be possible for a server program to start and stop apps and bring them ... > to the foreground as required, when that program wouldn't (under current ... > So is there some way to get around this limitation? ... > create a useful app control system within the current limitations. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Opinion wanted
    ... the details including the nature of my own app (which you mischaraterized ... correct the current control (provided that control is invalid but invalid ... causes you to validate controls that have already been ... largely discreditted for good reason and has very little use these days. ...
    (microsoft.public.dotnet.framework.windowsforms)

Loading