#include <windows.h>
#include <Python.h>
#include <pythonwin/win32win.h> // Make sure this is in the include path
static PyObject *g_pModule = NULL;
PyObject* PyObject_fromHWND(HWND window)
{
PyObject *pName, *pArgs, *pValue;
if (g_pModule == NULL) {
char name[] = "pythonwin/win32gui.py"; // Replace with the full path
pName = PyString_FromString(name);
g_pModule = PyImport_Import(pName);
py_DECREF(pName);
if (g_pModule == NULL) {
// Report an error
}
}
pArgs = PyTuple_New(1);
pValue = PyInt_FromLong(static_cast<long>(window));
PyTuple_SetItem(pArgs, 0, pValue);
PyObject *pWindow = PyCWnd::CreateWindowFromHandle(g_pModule, pArgs);
Py_DECREF(pValue);
Py_DECREF(pArgs);
return pWindow;
}