Thread: [pywin32-checkins] pywin32/com/win32comext/shell/src shell.cpp,1.17,1.18
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2004-04-09 11:32:09
|
Update of /cvsroot/pywin32/pywin32/com/win32comext/shell/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27825 Modified Files: shell.cpp Log Message: Various fixes and enhancements, including addition of SHChangeNotifyRegister and SHChangeNotifyDeregister. Index: shell.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/com/win32comext/shell/src/shell.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** shell.cpp 19 Mar 2004 04:33:01 -0000 1.17 --- shell.cpp 9 Apr 2004 11:18:37 -0000 1.18 *************** *** 340,348 **** &pci->nShow, &pci->dwHotKey, &pci->hIcon)) return FALSE; ! if (!PyInt_Check(obVerb)) { ! PyErr_Format(PyExc_TypeError, "verb must be an int (strings not yet supported)"); return FALSE; } - pci->lpVerb = MAKEINTRESOURCE(PyInt_AsLong(obVerb)); return TRUE; } --- 340,351 ---- &pci->nShow, &pci->dwHotKey, &pci->hIcon)) return FALSE; ! if (PyString_Check(obVerb)) { ! pci->lpVerb = PyString_AsString(obVerb); ! } else if (PyInt_Check(obVerb)) { ! pci->lpVerb = MAKEINTRESOURCE(PyInt_AsLong(obVerb)); ! } else { ! PyErr_Format(PyExc_TypeError, "verb must be an int or string"); return FALSE; } return TRUE; } *************** *** 577,580 **** --- 580,600 ---- } + + BOOL PyObject_AsOLEMENUGROUPWIDTHS( PyObject *oblpMenuWidths, OLEMENUGROUPWIDTHS *pWidths) + { + return PyArg_ParseTuple(oblpMenuWidths, "iiiiii", + &pWidths->width[0], &pWidths->width[1], + &pWidths->width[2], &pWidths->width[3], + &pWidths->width[4], &pWidths->width[5]) != NULL; + } + + PyObject *PyObject_FromOLEMENUGROUPWIDTHS(OLEMENUGROUPWIDTHS *pWidths) + { + return Py_BuildValue("(iiiiii)", + pWidths->width[0], pWidths->width[1], + pWidths->width[2], pWidths->width[3], + pWidths->width[4], pWidths->width[5]); + } + ////////////////////////////////////////////////// // *************** *** 746,750 **** } ! // @pymethod <o SHFILEINFO>|shell|SHGetFileInfo|Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root. static PyObject *PySHGetFileInfo(PyObject *self, PyObject *args) { --- 766,770 ---- } ! // @pymethod int, <o SHFILEINFO>|shell|SHGetFileInfo|Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root. static PyObject *PySHGetFileInfo(PyObject *self, PyObject *args) { *************** *** 754,758 **** LPITEMIDLIST pidl = NULL; TCHAR *pidl_or_name; ! int attr, flags, info_attrs; BOOL ok; if (!PyArg_ParseTuple(args, "Oii|i", --- 774,778 ---- LPITEMIDLIST pidl = NULL; TCHAR *pidl_or_name; ! int attr, flags, info_attrs=0; BOOL ok; if (!PyArg_ParseTuple(args, "Oii|i", *************** *** 772,776 **** &attr, // @pyparm int|dwFileAttributes||Combination of one or more file attribute flags (FILE_ATTRIBUTE_ values). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored. &flags, // @pyparm int|uFlags||Flags that specify the file information to retrieve. See MSDN for details ! &info_attrs)) // @pyparm int|infoAttrs|0|Flags copued to the SHFILEINFO.dwAttributes member - useful when flags contains SHGFI_ATTR_SPECIFIED return NULL; if (flags & SHGFI_PIDL) { --- 792,796 ---- &attr, // @pyparm int|dwFileAttributes||Combination of one or more file attribute flags (FILE_ATTRIBUTE_ values). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored. &flags, // @pyparm int|uFlags||Flags that specify the file information to retrieve. See MSDN for details ! &info_attrs)) // @pyparm int|infoAttrs|0|Flags copied to the SHFILEINFO.dwAttributes member - useful when flags contains SHGFI_ATTR_SPECIFIED return NULL; if (flags & SHGFI_PIDL) { *************** *** 787,797 **** info.dwAttributes = info_attrs; PY_INTERFACE_PRECALL; ! HRESULT hr = SHGetFileInfo(name, attr, &info, sizeof(info), flags); PY_INTERFACE_POSTCALL; ! if (FAILED(hr)) { ! OleSetOleError(hr); ! goto done; ! } ! ret = PyObject_FromSHFILEINFO(&info); done: if (name) PyWinObject_FreeTCHAR(name); --- 807,813 ---- info.dwAttributes = info_attrs; PY_INTERFACE_PRECALL; ! DWORD dw = SHGetFileInfo(name, attr, &info, sizeof(info), flags); PY_INTERFACE_POSTCALL; ! ret = Py_BuildValue("iN", dw, PyObject_FromSHFILEINFO(&info)); done: if (name) PyWinObject_FreeTCHAR(name); *************** *** 971,976 **** LONG wEventID; UINT flags; ! PyObject *ob1, *ob2; ! if(!PyArg_ParseTuple(args, "iiOO:SHChangeNotify", &wEventID, &flags, --- 987,992 ---- LONG wEventID; UINT flags; ! PyObject *ob1, *ob2 = Py_None; ! if(!PyArg_ParseTuple(args, "iiO|O:SHChangeNotify", &wEventID, &flags, *************** *** 980,984 **** void *p1, *p2; ! if (flags & SHCNF_DWORD) { if (!PyInt_Check(ob1) || !(ob2==Py_None || PyInt_Check(ob2))) { PyErr_SetString(PyExc_TypeError, "SHCNF_DWORD is set - items must be integers"); --- 996,1000 ---- void *p1, *p2; ! if (flags == SHCNF_DWORD) { if (!PyInt_Check(ob1) || !(ob2==Py_None || PyInt_Check(ob2))) { PyErr_SetString(PyExc_TypeError, "SHCNF_DWORD is set - items must be integers"); *************** *** 987,991 **** p1 = (void *)PyInt_AsLong(ob1); p2 = (void *)(ob2==Py_None ? NULL : PyInt_AsLong(ob2)); ! } else if (flags & SHCNF_IDLIST) { ITEMIDLIST *pidl1, *pidl2; if (!PyObject_AsPIDL(ob1, &pidl1, FALSE)) --- 1003,1007 ---- p1 = (void *)PyInt_AsLong(ob1); p2 = (void *)(ob2==Py_None ? NULL : PyInt_AsLong(ob2)); ! } else if (flags == SHCNF_IDLIST) { ITEMIDLIST *pidl1, *pidl2; if (!PyObject_AsPIDL(ob1, &pidl1, FALSE)) *************** *** 997,1001 **** p1 = (void *)pidl1; p2 = (void *)pidl2; ! } else if (flags & SHCNF_PATH || flags & SHCNF_PRINTER) { if (!PyString_Check(ob1) || !(ob2==Py_None || PyString_Check(ob2))) { PyErr_SetString(PyExc_TypeError, "SHCNF_PATH/PRINTER is set - items must be strings"); --- 1013,1017 ---- p1 = (void *)pidl1; p2 = (void *)pidl2; ! } else if (flags == SHCNF_PATH || flags == SHCNF_PRINTER) { if (!PyString_Check(ob1) || !(ob2==Py_None || PyString_Check(ob2))) { PyErr_SetString(PyExc_TypeError, "SHCNF_PATH/PRINTER is set - items must be strings"); *************** *** 1019,1022 **** --- 1035,1109 ---- } + // @pymethod int|shell|SHChangeNotifyRegister|Registers a window that receives notifications from the file system or shell. + static PyObject *PySHChangeNotifyRegister(PyObject *self, PyObject *args) + { + typedef ULONG (WINAPI * PFNSHChangeNotifyRegister)(HWND hwnd, + int fSources, + LONG fEvents, + UINT wMsg, + int cEntries, + SHChangeNotifyEntry *pfsne); + + HMODULE hmod = GetModuleHandle(TEXT("shell32.dll")); + PFNSHChangeNotifyRegister pfnSHChangeNotifyRegister = NULL; + // This isn't always exported by name - but by ordinal 2!! + if (hmod) pfnSHChangeNotifyRegister=(PFNSHChangeNotifyRegister)GetProcAddress(hmod, MAKEINTRESOURCE(2)); + if (pfnSHChangeNotifyRegister==NULL) + return OleSetOleError(E_NOTIMPL); + // The SDK says of the array of entries: + // "This array should always be set to one when calling SHChangeNotifyRegister or + // SHChangeNotifyDeregister will not work properly." + // Therefore, we support just one item in the array - and don't require it + // to be an array! + HWND hwnd; + int sources; + LONG events; + UINT msg; + PyObject *obPIDL; + SHChangeNotifyEntry entry; + if(!PyArg_ParseTuple(args, "iiii(Oi):SHChangeNotifyRegister", + &hwnd, // @pyparm int|hwnd||Handle to the window that receives the change or notification messages. + &sources, // @pyparm int|sources||One or more values that indicate the type of events for which to receive notifications. + &events, // @pyparm int|events||Change notification events for which to receive notification. + &msg, // @pyparm int|msg||Message to be posted to the window procedure. + &obPIDL, + &entry.fRecursive)) + return NULL; + + if (!PyObject_AsPIDL(obPIDL, (ITEMIDLIST **)&entry.pidl, TRUE)) + return NULL; + ULONG rc; + PY_INTERFACE_PRECALL; + rc = (*pfnSHChangeNotifyRegister)(hwnd, sources, events, msg, 1, &entry); + PY_INTERFACE_POSTCALL; + PyObject_FreePIDL(entry.pidl); + return PyInt_FromLong(rc); + } + + // @pymethod |shell|SHChangeNotifyDeregister|Unregisters the client's window process from receiving notification events + static PyObject *PySHChangeNotifyDeregister(PyObject *self, PyObject *args) + { + typedef BOOL (WINAPI * PFNSHChangeNotifyDeregister)(LONG uid); + HMODULE hmod = GetModuleHandle(TEXT("shell32.dll")); + PFNSHChangeNotifyDeregister pfnSHChangeNotifyDeregister = NULL; + // This isn't always exported by name - but by ordinal 4!! + if (hmod) pfnSHChangeNotifyDeregister=(PFNSHChangeNotifyDeregister)GetProcAddress(hmod, MAKEINTRESOURCE(4)); + if (pfnSHChangeNotifyDeregister==NULL) + return OleSetOleError(E_NOTIMPL); + LONG id; + if(!PyArg_ParseTuple(args, "i:SHChangeNotifyDeregister", + &id)) // @pyparm int|id||The registration identifier (ID) returned by <om shell.SHChangeNotifyRegister>. + return NULL; + + BOOL rc; + PY_INTERFACE_PRECALL; + rc = (*pfnSHChangeNotifyDeregister)(id); + PY_INTERFACE_POSTCALL; + if (!rc) + return OleSetOleError(E_FAIL); + Py_INCREF(Py_None); + return Py_None; + } + // @pymethod string/int|shell|DragQueryFile|Notifies the shell that an // image in the system image list has changed. *************** *** 1152,1155 **** --- 1239,1244 ---- { "SHUpdateImage", PySHUpdateImage, 1}, // @pymeth SHUpdateImage|Notifies the shell that an image in the system image list has changed. { "SHChangeNotify", PySHChangeNotify, 1}, // @pymeth SHChangeNotify|Notifies the system of an event that an application has performed. + { "SHChangeNotifyRegister", PySHChangeNotifyRegister, 1}, // @pymeth SHChangeNotifyRegister|Registers a window that receives notifications from the file system or shell. + { "SHChangeNotifyDeregister", PySHChangeNotifyDeregister, 1}, // @pymeth SHChangeNotifyDeregister|Unregisters the client's window process from receiving notification events { "SHGetInstanceExplorer", PySHGetInstanceExplorer, 1}, // @pymeth SHGetInstanceExplorer|Allows components that run in a Web browser (Iexplore.exe) or a nondefault Windows® Explorer (Explorer.exe) process to hold a reference to the process. The components can use the reference to prevent the process from closing prematurely. { "StringAsCIDA", PyStringAsCIDA, 1}, // @pymeth StringAsCIDA|Given a CIDA as a raw string, return pidl_folder, [pidl_children, ...] |