Article View: comp.os.ms-windows.programmer.misc
Article #1997Re: Bringing Application Windows to the top
From: Chris Marriott
Date: Thu, 17 Dec 1992 18:40
Date: Thu, 17 Dec 1992 18:40
53 lines
2325 bytes
2325 bytes
In article <1992Dec17.122321.20939@cs.nott.ac.uk> mak@vulcan.xtel.co.uk writes:
>
>Hi,
>I`ve got fairly simple question:
>
> Given a HWND, how can I bring an Application window to the top?
>
>I want only one instance of my application to run, and like in the
>File Manager I'd like the current instance of my program to come
>to the front when the user selects my program-item from the
>Program Manager.
>To do this I check for a previous instance on startup, and if there
>is one I use EnumWindows to step through the windows looking for
>the one belonging to the previous instance. This works fine, I
>can set the title of that window. But now I want to bring that
>application to the top. I tried SetWindowPos(hwnd, HWND_TOPMOST,
>0, 0, 0, 0, WPS_NOSIZE | WPS_NOMOVE), but nothing happens.
>
>Any suggestions greatly appreciated.
>
>-- Martijn
>
Using "EnumWindows" isn't necessary. All you need to do is say:
if (hPrevInstance!=NULL) {
// Find the window handle of the previous instance.
hWnd = FindWindow( "MyClassName", NULL );
// If the window is iconic, restore it.
if (IsIconic(hWnd)) OpenIcon(hWnd);
// Bring the window to the front.
BringWindowToTop( hWnd );
return 0;
}
This should do the trick.
Chris
--
--------------------------------------------------------------------------
| Chris Marriott | chris@chrism.demon.co.uk |
| Warrington, UK | BIX: cmarriott |
| (Still awaiting inspiration | CIX: cmarriott |
| for a witty .sig .... ) | CompuServe: 100113,1140 |
--------------------------------------------------------------------------
Technical Details
Message-ID:
<724617656snz@chrism.demon.co.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!chrism.demon.co.uk!chrisReferences:
<1992Dec17.122321.20939@cs.nott.ac.uk>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc From: chris@chrism.demon.co.uk (Chris Marriott) Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!demon!chrism.demon.co.uk!chris Subject: Re: Bringing Application Windows to the top Distribution: world References: <1992Dec17.122321.20939@cs.nott.ac.uk> Organization: None Reply-To: chris@chrism.demon.co.uk X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19) Lines: 53 Date: Thu, 17 Dec 1992 18:40:56 +0000 Message-ID: <724617656snz@chrism.demon.co.uk> Sender: usenet@demon.co.uk