> Jason Coley wrote:
> 
> Is there a way to bring an Apps window to the front, I have an OLE handle
> to a window (Word) and I want to bring that window to the front, what’s
> the best way to do this?

As Patrick mentioned, BringWindowToFront is the official method, but it
won't work as expected on Win98/2K/ME.  On those platforms when a process
which is not the current owner of the forground window calls
BringWindowToFront it just flashes the icon on the task bar.  To get around
that you have to run the code in the context of the current foreground
process.  Here's some C++ code that I've been using which does it:

bool ForceWindowToFront(HWND hWnd)
{
bool Result;
DWORD ForegroundWindowThreadID;
DWORD WindowThreadID;
  if (hWnd == GetForegroundWindow())
    Result = true;
  else
  {
    ForegroundWindowThreadID =
GetWindowThreadProcessId(GetForegroundWindow(), NULL);
    WindowThreadID = GetWindowThreadProcessId(hWnd, NULL);
    if (ForegroundWindowThreadID != WindowThreadID)
    {
      AttachThreadInput(ForegroundWindowThreadID, WindowThreadID, true);
      Result = SetForegroundWindow(hWnd);
      AttachThreadInput(ForegroundWindowThreadID, WindowThreadID, false);
    }
    else
      Result = SetForegroundWindow(hWnd);
    ShowWindow(hWnd, SW_RESTORE);
  }
  return Result;
}

-- 
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur!"
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"

Reply via email to