OSDN Git Service

Add facility for control of child window placement.
[mingw/wtklite.git] / wtkraise.cpp
1 /*
2  * wtkraise.cpp
3  *
4  * ---------------------------------------------------------------------------
5  *
6  * Implementation of a minimal C++ class framework for use with the
7  * Microsoft Windows Application Programming Interface.
8  *
9  * $Id$
10  *
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.
14  *
15  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
16  * Copyright (C) 2013, MinGW.org Project.
17  *
18  * ---------------------------------------------------------------------------
19  *
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:
26  *
27  * The above copyright notice, this permission notice, and the following
28  * disclaimer shall be included in all copies or substantial portions of
29  * the Software.
30  *
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.
38  *
39  * ---------------------------------------------------------------------------
40  *
41  */
42 #include <wtklite.h>
43
44 namespace WTK
45 {
46   EXTERN_C int RaiseAppWindow( HINSTANCE Instance, unsigned int ClassID )
47   {
48     /* Helper to search for any running instance of a specified window
49      * class; when one is found, activate it, and bring to foreground.
50      */
51     HWND AppWindow = FindWindow(
52         StringResource( Instance, ClassID ), NULL
53       );
54     if( (AppWindow != NULL) && IsWindow( AppWindow ) )
55     {
56       /* ...and when one is, we identify its active window...
57        */
58       HWND AppPopup = GetLastActivePopup( AppWindow );
59       if( IsWindow( AppPopup ) )
60         AppWindow = AppPopup;
61
62       /* ...bring it to the foreground...
63        */
64       SetForegroundWindow( AppWindow );
65       /*
66        * ...restore it from minimised state, if necessary...
67        */
68       if( IsIconic( AppWindow ) )
69         ShowWindow( AppWindow, SW_RESTORE );
70
71       /* ...and tell caller it may defer execution to this
72        * newly promoted foreground application.
73        */
74       return (int)(true);
75     }
76     return (int)(false);
77   }
78 }
79
80 /* $RCSfile$: end of file */