1515
1616#include < agg_basics.h> // agg:int8u
1717
18+ #ifdef _WIN32
19+ #include < windows.h>
20+ #endif
21+
1822// Include our own excerpts from the Tcl / Tk headers
1923#include " _tkmini.h"
2024
@@ -245,15 +249,45 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
245249 }
246250}
247251
252+ #ifdef _WIN32
253+ static PyObject *
254+ Win32_GetForegroundWindow (PyObject *module , PyObject *args)
255+ {
256+ HWND handle = GetForegroundWindow ();
257+ if (!PyArg_ParseTuple (args, " :GetForegroundWindow" )) {
258+ return NULL ;
259+ }
260+ return PyLong_FromSize_t ((size_t )handle);
261+ }
262+
263+ static PyObject *
264+ Win32_SetForegroundWindow (PyObject *module , PyObject *args)
265+ {
266+ HWND handle;
267+ if (!PyArg_ParseTuple (args, " n:SetForegroundWindow" , &handle)) {
268+ return NULL ;
269+ }
270+ if (!SetForegroundWindow (handle)) {
271+ return PyErr_Format (PyExc_RuntimeError, " Error setting window" );
272+ }
273+ Py_INCREF (Py_None);
274+ return Py_None;
275+ }
276+ #endif
277+
248278static PyMethodDef functions[] = {
249279 /* Tkinter interface stuff */
250- { " tkinit" , (PyCFunction)_tkinit, 1 },
251- { " blit" , (PyCFunction)mpl_tk_blit, 1 },
280+ { " tkinit" , (PyCFunction)_tkinit, METH_VARARGS },
281+ { " blit" , (PyCFunction)mpl_tk_blit, METH_VARARGS },
282+ #ifdef _WIN32
283+ { " Win32_GetForegroundWindow" , (PyCFunction)Win32_GetForegroundWindow, METH_VARARGS },
284+ { " Win32_SetForegroundWindow" , (PyCFunction)Win32_SetForegroundWindow, METH_VARARGS },
285+ #endif
252286 { NULL , NULL } /* sentinel */
253287};
254288
255289// Functions to fill global TCL / Tk function pointers by dynamic loading
256- #if defined( _WIN32) || defined(__WIN32__) || defined(WIN32)
290+ #ifdef _WIN32
257291
258292/*
259293 * On Windows, we can't load the tkinter module to get the TCL or Tk symbols,
@@ -262,7 +296,6 @@ static PyMethodDef functions[] = {
262296 * Python, we scan all modules in the running process for the TCL and Tk
263297 * function names.
264298 */
265- #include < windows.h>
266299#define PSAPI_VERSION 1
267300#include < psapi.h>
268301// Must be linked with 'psapi' library
0 commit comments