[pywin32-checkins] /hgrepo/p/py/pywin32/pywin32: Add SHOpenFolderAndSelectItems (fe...
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2011-08-25 18:50:24
|
changeset 1452829d69ec in /hgrepo/p/py/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgrepo/p/py/pywin32/pywin32?cmd=changeset;node=1452829d69ec summary: Add SHOpenFolderAndSelectItems (feature req# 3396444) diffstat: com/win32comext/shell/src/shell.cpp | 49 ++++++++++++++++++++++++++++++++++-- 1 files changed, 46 insertions(+), 3 deletions(-) diffs (94 lines): diff -r 0cde6078b159 -r 1452829d69ec com/win32comext/shell/src/shell.cpp --- a/com/win32comext/shell/src/shell.cpp Sat Aug 13 11:05:08 2011 +1000 +++ b/com/win32comext/shell/src/shell.cpp Thu Aug 25 14:48:47 2011 -0400 @@ -159,6 +159,8 @@ typedef HRESULT (WINAPI *PFNSHCreateShellItem)(PCIDLIST_ABSOLUTE, IShellFolder *, PCUITEMID_CHILD, IShellItem **); static PFNSHCreateShellItem pfnSHCreateShellItem = NULL; +typedef HRESULT (WINAPI *PFNSHOpenFolderAndSelectItems)(PCIDLIST_ABSOLUTE,UINT,PCUITEMID_CHILD_ARRAY,DWORD); +static PFNSHOpenFolderAndSelectItems pfnSHOpenFolderAndSelectItems = NULL; void PyShell_FreeMem(void *p) { @@ -323,6 +325,7 @@ PyErr_NoMemory(); return FALSE; } + ZeroMemory(ppidl, n * sizeof(ITEMIDLIST *)); for (int i=0;i<n;i++) { PyObject *ob = PySequence_GetItem(obSeq, i); if (!ob || !PyObject_AsPIDL(ob, (ITEMIDLIST **)&ppidl[i], FALSE )) { @@ -3186,9 +3189,6 @@ return ret; } - - - // @pymethod <o PyIShellItem>|shell|SHCreateShellItem|Creates an IShellItem interface from a PIDL static PyObject *PySHCreateShellItem(PyObject *self, PyObject *args) { @@ -3240,6 +3240,47 @@ return ret; } +// @pymethod |shell|SHOpenFolderAndSelectItems|Displays a shell folder with items pre-selected +static PyObject *PySHOpenFolderAndSelectItems(PyObject *self, PyObject *args, PyObject *kwargs) +{ + // @comm This function is only available on XP and later. + // COM exception with E_NOTIMPL will be thrown if the function can't be located. + if (pfnSHOpenFolderAndSelectItems==NULL) + return PyCom_BuildPyException(E_NOTIMPL); + static char *keywords[] = {"Folder", "Items", "Flags", NULL}; + DWORD flags; + PyObject *obfolder, *obitems, *ret=NULL; + // @pyparm <o PyIDL>|Folder||An absolute item id list identifying a shell folder + // @pyparm (<o PyIDL>,...)|Items||A sequence of relative item ids identifying items in the folder + // @pyparm int|Flags|0|Combination of OFASI_* flags (not used on XP) + + if(!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|k:SHOpenFolderAndSelectItems", keywords, + &obfolder, &obitems, &flags)) + return NULL; + ITEMIDLIST *folder = NULL; + const ITEMIDLIST **items = NULL; + UINT item_cnt; + HRESULT hr; + if (PyObject_AsPIDL(obfolder, &folder, FALSE) + &&PyObject_AsPIDLArray(obitems, &item_cnt, &items)){ + PY_INTERFACE_PRECALL; + hr = (*pfnSHOpenFolderAndSelectItems)(folder, item_cnt, items, flags); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) + PyCom_BuildPyException(hr); + else{ + Py_INCREF(Py_None); + ret=Py_None; + } + } + + if (folder) + PyObject_FreePIDL(folder); + if (items) + PyObject_FreePIDLArray(item_cnt, items); + return ret; +} + /* List of module functions */ // @module shell|A module wrapping Windows Shell functions and interfaces @@ -3298,6 +3339,7 @@ { "SHGetViewStatePropertyBag", PySHGetViewStatePropertyBag, METH_VARARGS}, // @pymeth SHGetViewStatePropertyBag|Retrieves an interface for a folder's view state { "SHILCreateFromPath", PySHILCreateFromPath, METH_VARARGS}, // @pymeth SHILCreateFromPath|Returns the PIDL and attributes of a path { "SHCreateShellItem", PySHCreateShellItem, METH_VARARGS}, // @pymeth SHCreateShellItem|Creates an IShellItem interface from a PIDL + { "SHOpenFolderAndSelectItems", (PyCFunction)PySHOpenFolderAndSelectItems, METH_VARARGS|METH_KEYWORDS}, // @pymeth SHOpenFolderAndSelectItems|Displays a shell folder with items pre-selected { NULL, NULL }, }; @@ -3431,6 +3473,7 @@ pfnSHCreateItemWithParent =(PFNSHCreateItemWithParent)GetProcAddress(shell32, "SHCreateItemWithParent"); pfnSHGetIDListFromObject =(PFNSHGetIDListFromObject)GetProcAddress(shell32, "SHGetIDListFromObject"); pfnSHCreateShellItem =(PFNSHCreateShellItem)GetProcAddress(shell32, "SHCreateShellItem"); + pfnSHOpenFolderAndSelectItems = (PFNSHOpenFolderAndSelectItems)GetProcAddress(shell32, "SHOpenFolderAndSelectItems"); } // SHGetFolderPath comes from shfolder.dll on older systems if (pfnSHGetFolderPath==NULL){ |