4 * ---------------------------------------------------------------------------
6 * Implementation of a minimal C++ class framework for use with the
7 * Microsoft Windows Application Programming Interface.
11 * This file provides the implementation for RaiseAppWindow(), a helper
12 * function which checks for any already running instance of the calling
13 * application, and promotes any such existing instance to foreground.
15 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
16 * Copyright (C) 2013, MinGW.org Project.
18 * ---------------------------------------------------------------------------
20 * Permission is hereby granted, free of charge, to any person obtaining a
21 * copy of this software and associated documentation files (the "Software"),
22 * to deal in the Software without restriction, including without limitation
23 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24 * and/or sell copies of the Software, and to permit persons to whom the
25 * Software is furnished to do so, subject to the following conditions:
27 * The above copyright notice, this permission notice, and the following
28 * disclaimer shall be included in all copies or substantial portions of
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37 * DEALINGS IN THE SOFTWARE.
39 * ---------------------------------------------------------------------------
46 EXTERN_C int RaiseAppWindow( HINSTANCE Instance, unsigned int ClassID )
48 /* Helper to search for any running instance of a specified window
49 * class; when one is found, activate it, and bring to foreground.
51 HWND AppWindow = FindWindow(
52 StringResource( Instance, ClassID ), NULL
54 if( (AppWindow != NULL) && IsWindow( AppWindow ) )
56 /* ...and when one is, we identify its active window...
58 HWND AppPopup = GetLastActivePopup( AppWindow );
59 if( IsWindow( AppPopup ) )
62 /* ...bring it to the foreground...
64 SetForegroundWindow( AppWindow );
66 * ...restore it from minimised state, if necessary...
68 if( IsIconic( AppWindow ) )
69 ShowWindow( AppWindow, SW_RESTORE );
71 /* ...and tell caller it may defer execution to this
72 * newly promoted foreground application.
80 /* $RCSfile$: end of file */