• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A light-weight C++ object model framework Windows API Tool Kit


Commit MetaInfo

Revisión07b8d6fc74c335514ab40326b6408e323626e955 (tree)
Tiempo2013-08-19 21:40:03
AutorKeith Marshall <keithmarshall@user...>
CommiterKeith Marshall

Log Message

Add facility for activation of a running application window.

Cambiar Resumen

Diferencia incremental

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
11 2013-08-19 Keith Marshall <keithmarshall@users.sourceforge.net>
22
3+ Add facility for activation of a running application window.
4+
5+ * wtkdefs.h: New file; it defines...
6+ (EXTERN_C, BEGIN_NAMESPACE, END_NAMESPACE): ...these new macros.
7+
8+ * wtkraise.cpp: New file; it implements...
9+ (RaiseAppWindow): ...this new extern "C" function.
10+
11+ * wtklite.h (RaiseAppWindow): Declare it; it is designated by...
12+ (EXTERN_C): ...this new macro, within WTK namespace demarcated by...
13+ (BEGIN_NAMESPACE, END_NAMESPACE): ...this new macro pair.
14+
15+ * Makefile.in (LIBWTK_OBJECTS): Add wtkraise.$OBJEXT
16+ (SRCDIST_FILES): Add wtkdefs.h and wtkraise.cpp
17+ (install-headers): Add wtkdefs.h
18+
19+2013-08-19 Keith Marshall <keithmarshall@users.sourceforge.net>
20+
321 Do not track .orig files.
422
523 * .hgignore (**.orig): Add pattern.
--- a/Makefile.in
+++ b/Makefile.in
@@ -63,7 +63,8 @@ all: libwtklite.a
6363 #
6464 LIBWTK_OBJECTS = wtkbase.$(OBJEXT) wtkmain.$(OBJEXT) wndproc.$(OBJEXT) \
6565 dlgproc.$(OBJEXT) wtkchild.$(OBJEXT) wtkexcept.$(OBJEXT) errtext.$(OBJEXT) \
66- sashctrl.$(OBJEXT) hsashctl.$(OBJEXT) vsashctl.$(OBJEXT) strres.$(OBJEXT)
66+ sashctrl.$(OBJEXT) hsashctl.$(OBJEXT) vsashctl.$(OBJEXT) strres.$(OBJEXT) \
67+ wtkraise.$(OBJEXT)
6768
6869 libwtklite.a: $(LIBWTK_OBJECTS)
6970 $(AR) $(ARFLAGS) $@ $^
@@ -103,7 +104,7 @@ install: install-dirs install-headers install-libs
103104 install-dirs:
104105 $(MKDIR_P) ${includedir} ${libdir}
105106
106-install-headers: wtklite.h wtkexcept.h
107+install-headers: wtklite.h wtkdefs.h wtkexcept.h
107108 $(INSTALL_DATA) $^ ${includedir}
108109
109110 install-libs: libwtklite.a
@@ -113,8 +114,9 @@ install-libs: libwtklite.a
113114 #
114115 TARNAME = $(PACKAGE)-$(VERSION)-mingw32
115116 SRCDIST_FILES = ChangeLog configure configure.ac Makefile.in install-sh \
116- wtklite.h wtkexcept.h wtkbase.cpp wtkmain.cpp wtkchild.cpp wndproc.cpp \
117- dlgproc.cpp sashctrl.cpp wtkexcept.cpp errtext.cpp strres.cpp
117+ wtklite.h wtkdefs.h wtkexcept.h wtkbase.cpp wtkmain.cpp wtkchild.cpp \
118+ wndproc.cpp dlgproc.cpp sashctrl.cpp wtkexcept.cpp errtext.cpp strres.cpp \
119+ wtkraise.cpp
118120
119121 dist: srcdist devdist
120122
--- /dev/null
+++ b/wtkdefs.h
@@ -0,0 +1,65 @@
1+#ifndef WTKDEFS_H
2+/*
3+ * wtkdefs.h
4+ *
5+ * ---------------------------------------------------------------------------
6+ *
7+ * Implementation of a minimal C++ class framework for use with the
8+ * Microsoft Windows Application Programming Interface.
9+ *
10+ * $Id$
11+ *
12+ * This header file provides a set of utility macro definitions, which
13+ * may be required by other more user visible header files.
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+#define WTKDEFS_H 1
43+
44+/* Some functions expose an extern "C" interface, (some may even be written
45+ * in C), but within C++ clients we subsume them into the WTK namespace; we
46+ * provide a set of macros to facilitate this...
47+ */
48+#ifdef __cplusplus
49+/*
50+ * ...for the (normal) C++ case...
51+ */
52+# define EXTERN_C extern "C"
53+# define BEGIN_NAMESPACE(NAME) namespace NAME {
54+# define END_NAMESPACE(NAME) }
55+
56+#else
57+/* ...while also providing an interface which exposes them globally,
58+ * so that they may also be called from C code.
59+ */
60+# define EXTERN_C extern
61+# define BEGIN_NAMESPACE(NAME)
62+# define END_NAMESPACE(NAME)
63+#endif
64+
65+#endif /* WTKDEFS_H: $RCSfile$: end of file */
--- a/wtklite.h
+++ b/wtklite.h
@@ -13,7 +13,7 @@
1313 * C++ class framework.
1414 *
1515 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
16- * Copyright (C) 2012, MinGW.org Project.
16+ * Copyright (C) 2012, 2013, MinGW.org Project.
1717 *
1818 * ---------------------------------------------------------------------------
1919 *
@@ -44,6 +44,7 @@
4444 #include <stdlib.h>
4545 #include <windows.h>
4646 #include "wtkexcept.h"
47+#include "wtkdefs.h"
4748
4849 /* This header file is primarily intended to be used only for C++. However,
4950 * configure scripts may try to compile it as C, when checking availability;
@@ -304,6 +305,21 @@ namespace WTK
304305 void SetDisplacementFactor( unsigned long );
305306 };
306307 }
307-
308308 #endif /* __cplusplus */
309+
310+/* We also provide a small collection of functions which, for C++
311+ * applications, are considered to live within the WTK namespace,
312+ * but may also be invoked from C; to facilitate this, we reopen
313+ * the namespace in a C transparent manner...
314+ */
315+BEGIN_NAMESPACE( WTK )
316+ /*
317+ * ...which allows us to declare extern "C" function prototypes,
318+ * each of which will be directly visible in C, but subsumed into
319+ * the namespace when compiling C++.
320+ */
321+ EXTERN_C int RaiseAppWindow( HINSTANCE, unsigned int );
322+
323+END_NAMESPACE( WTK )
324+
309325 #endif /* ! WTKLITE_H: $RCSfile$: end of file */
--- /dev/null
+++ b/wtkraise.cpp
@@ -0,0 +1,80 @@
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 */