[pywin32-checkins] /hgroot/pywin32/pywin32: 3 new changesets
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-09-20 18:39:55
|
changeset c4d977bc3ee9 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=c4d977bc3ee9 summary: Add Get/SetCurrentProcessExplicitAppUserModelID changeset da480ad27dbc in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=da480ad27dbc summary: Autoduck fixes changeset 9648d478ad21 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=9648d478ad21 summary: Correct size of buffer passed to GetCommandString diffstat: com/win32comext/shell/src/PyIContextMenu.cpp | 11 +++-- com/win32comext/shell/src/PyIShellLink.cpp | 48 ++++++++++++----------- com/win32comext/shell/src/shell.cpp | 54 ++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 27 deletions(-) diffs (278 lines): diff -r 977f4f21ae8b -r 9648d478ad21 com/win32comext/shell/src/PyIContextMenu.cpp --- a/com/win32comext/shell/src/PyIContextMenu.cpp Mon Sep 10 17:23:43 2012 -0400 +++ b/com/win32comext/shell/src/PyIContextMenu.cpp Thu Sep 20 14:15:56 2012 -0400 @@ -97,13 +97,16 @@ UINT cchMax = 2048; if ( !PyArg_ParseTuple(args, "OI|I:GetCommandString", &obCmd, &uType, &cchMax) ) return NULL; - if (uType & GCS_UNICODE) - cchMax *= sizeof(WCHAR); // buffer size is in characters + UINT_PTR idCmd; if (!PyWinLong_AsULONG_PTR(obCmd, (ULONG_PTR *)&idCmd)) return NULL; - - char *buf = (char *)malloc(cchMax); + // buffer size is in characters + char *buf; + if (uType & GCS_UNICODE) + buf = (char *)malloc(cchMax * sizeof(WCHAR)); + else + buf = (char *)malloc(cchMax); if (!buf) return PyErr_NoMemory(); HRESULT hr; diff -r 977f4f21ae8b -r 9648d478ad21 com/win32comext/shell/src/PyIShellLink.cpp --- a/com/win32comext/shell/src/PyIShellLink.cpp Mon Sep 10 17:23:43 2012 -0400 +++ b/com/win32comext/shell/src/PyIShellLink.cpp Thu Sep 20 14:15:56 2012 -0400 @@ -27,7 +27,7 @@ return (IShellLink *)PyIUnknown::GetI(self); } -// @pymethod name, <o WIN32_FIND_DATA>|PyIShellLink|GetPath|Retrieves the path and file name of a shell link object +// @pymethod str, <o WIN32_FIND_DATA>|PyIShellLink|GetPath|Retrieves the target path and file name of a shell link object // @comm The AlternateFileName (8.3) member of WIN32_FIND_DATA does not return information PyObject *PyIShellLink::GetPath(PyObject *self, PyObject *args) { @@ -40,7 +40,7 @@ // @flag SLGP_SHORTPATH|Retrieves the standard short (8.3 format) file name. // @flag SLGP_UNCPRIORITY|Retrieves the Universal Naming Convention (UNC) path name of the file. // @flag SLGP_RAWPATH|Retrieves the raw path name. A raw path is something that might not exist and may include environment variables that need to be expanded. - // @pyparm int|cchMaxPath|_MAX_PATH|Description for cchMaxPath + // @pyparm int|cchMaxPath|_MAX_PATH|Number of characters to allocate for returned filename int cchMaxPath = _MAX_PATH; DWORD fFlags; if ( !PyArg_ParseTuple(args, "l|i:GetPath", &fFlags, &cchMaxPath) ) @@ -67,7 +67,7 @@ return ret; } -// @pymethod string|PyIShellLink|GetIDList|Retrieves the list of item identifiers for a shell link object. +// @pymethod <o PyIDL>|PyIShellLink|GetIDList|Retrieves the item id list that identifies the target of the shell link. PyObject *PyIShellLink::GetIDList(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); @@ -86,7 +86,7 @@ return PyObject_FromPIDL(pidl, TRUE); } -// @pymethod |PyIShellLink|SetIDList|Sets the list of item identifiers for a shell link object. +// @pymethod |PyIShellLink|SetIDList|Sets the target of the link using an item id list PyObject *PyIShellLink::SetIDList(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); @@ -94,11 +94,11 @@ return NULL; LPITEMIDLIST pidl; PyObject *obpidl; + // @pyparm <o PyIDL>|pidl||Absolute item id list that identifies the target if ( !PyArg_ParseTuple(args, "O:SetIDList", &obpidl) ) return NULL; - BOOL bPythonIsHappy = TRUE; - if (bPythonIsHappy && !PyObject_AsPIDL( obpidl, &pidl )) bPythonIsHappy = FALSE; - if (!bPythonIsHappy) return NULL; + if (!PyObject_AsPIDL( obpidl, &pidl )) + return NULL; HRESULT hr; PY_INTERFACE_PRECALL; hr = pISL->SetIDList( pidl ); @@ -112,13 +112,13 @@ return Py_None; } -// @pymethod |PyIShellLink|GetDescription|Description of GetDescription. +// @pymethod str|PyIShellLink|GetDescription|Retrieves the description of the link (displays as Comment in the UI) PyObject *PyIShellLink::GetDescription(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; - // @pyparm int|cchMaxName|1024|Description for cchMaxName + // @pyparm int|cchMaxName|1024|Number of character to allocate for the retrieved text int cchMaxName = 1024; if ( !PyArg_ParseTuple(args, "|i:GetDescription", &cchMaxName) ) return NULL; @@ -141,13 +141,14 @@ return ret; } -// @pymethod |PyIShellLink|SetDescription|Description of SetDescription. +// @pymethod |PyIShellLink|SetDescription|Sets the description of the link (displays as Comment in the UI) PyObject *PyIShellLink::SetDescription(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; PyObject *obName; + // @pyparm str|Name||The description for the link if ( !PyArg_ParseTuple(args, "O:SetDescription", &obName) ) return NULL; TCHAR *pszName; @@ -165,13 +166,13 @@ return Py_None; } -// @pymethod |PyIShellLink|GetWorkingDirectory|Description of GetWorkingDirectory. +// @pymethod str|PyIShellLink|GetWorkingDirectory|Retrieves the working directory for the link PyObject *PyIShellLink::GetWorkingDirectory(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; - // @pyparm int|cchMaxName|1024|Description for cchMaxName + // @pyparm int|cchMaxName|1024|Number of characters to allocate for returned text int cchMaxName = 1024; if ( !PyArg_ParseTuple(args, "|i:GetWorkingDirectory", &cchMaxName) ) return NULL; @@ -194,13 +195,14 @@ return ret; } -// @pymethod |PyIShellLink|SetWorkingDirectory|Description of SetWorkingDirectory. +// @pymethod |PyIShellLink|SetWorkingDirectory|Sets the working directory for the link. PyObject *PyIShellLink::SetWorkingDirectory(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); if ( pISL == NULL ) return NULL; PyObject *obName; + // @pyparm str|Dir||The working directory for the link if ( !PyArg_ParseTuple(args, "O:SetWorkingDirectory", &obName) ) return NULL; TCHAR *pszName; @@ -219,7 +221,7 @@ } -// @pymethod string|PyIShellLink|GetArguments|Retrieves the command-line arguments associated with a shell link object. +// @pymethod str|PyIShellLink|GetArguments|Retrieves the command-line arguments associated with a shell link object. PyObject *PyIShellLink::GetArguments(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); @@ -255,7 +257,7 @@ if ( pISL == NULL ) return NULL; PyObject *obArgs; - // @pyparm string|args||The new arguments. + // @pyparm str|args||The new arguments. if ( !PyArg_ParseTuple(args, "O:SetArguments", &obArgs) ) return NULL; TCHAR *pszArgs; @@ -358,7 +360,7 @@ } -// @pymethod string|PyIShellLink|GetIconLocation|Retrieves the location (path and index) of the icon for a shell link object. +// @pymethod str|PyIShellLink|GetIconLocation|Retrieves the location (path and index) of the icon for a shell link object. PyObject *PyIShellLink::GetIconLocation(PyObject *self, PyObject *args) { IShellLink *pISL = GetI(self); @@ -516,16 +518,16 @@ return Py_None; } -// @object PyIShellLink|Description of the interface +// @object PyIShellLink|Interface used to access the properties of a shell link file (*.lnk) static struct PyMethodDef PyIShellLink_methods[] = { { "GetPath", PyIShellLink::GetPath, 1 }, // @pymeth GetPath|Retrieves the path and file name of a shell link object. - { "GetIDList", PyIShellLink::GetIDList, 1 }, // @pymeth GetIDList|Retrieves the list of item identifiers for a shell link object. - { "SetIDList", PyIShellLink::SetIDList, 1 }, // @pymeth SetIDList|Sets the list of item identifiers for a shell link object. - { "GetDescription", PyIShellLink::GetDescription, 1 }, // @pymeth GetDescription|Description of GetDescription - { "SetDescription", PyIShellLink::SetDescription, 1 }, // @pymeth SetDescription|Description of SetDescription - { "GetWorkingDirectory", PyIShellLink::GetWorkingDirectory, 1 }, // @pymeth GetWorkingDirectory|Description of GetWorkingDirectory - { "SetWorkingDirectory", PyIShellLink::SetWorkingDirectory, 1 }, // @pymeth SetWorkingDirectory|Description of SetWorkingDirectory + { "GetIDList", PyIShellLink::GetIDList, 1 }, // @pymeth GetIDList|Retrieves the item id list that identifies the target of the shell link. + { "SetIDList", PyIShellLink::SetIDList, 1 }, // @pymeth SetIDList|Sets the target of the link using an item id list + { "GetDescription", PyIShellLink::GetDescription, 1 }, // @pymeth GetDescription|Retrieves the description of the link (displays as Comment in the UI) + { "SetDescription", PyIShellLink::SetDescription, 1 }, // @pymeth SetDescription|Sets the description of the link (displays as Comment in the UI) + { "GetWorkingDirectory", PyIShellLink::GetWorkingDirectory, 1 }, // @pymeth GetWorkingDirectory|Retrieves the working directory for the link + { "SetWorkingDirectory", PyIShellLink::SetWorkingDirectory, 1 }, // @pymeth SetWorkingDirectory|Sets the working directory for the link { "GetArguments", PyIShellLink::GetArguments, 1 }, // @pymeth GetArguments|Retrieves the command-line arguments associated with a shell link object. { "SetArguments", PyIShellLink::SetArguments, 1 }, // @pymeth SetArguments|Sets the command-line arguments associated with a shell link object. { "GetHotkey", PyIShellLink::GetHotkey, 1 }, // @pymeth GetHotkey|Retrieves the hot key for a shell link object. diff -r 977f4f21ae8b -r 9648d478ad21 com/win32comext/shell/src/shell.cpp --- a/com/win32comext/shell/src/shell.cpp Mon Sep 10 17:23:43 2012 -0400 +++ b/com/win32comext/shell/src/shell.cpp Thu Sep 20 14:15:56 2012 -0400 @@ -168,6 +168,12 @@ typedef HRESULT (WINAPI *PFNSHCreateStreamOnFileEx)(LPCWSTR, DWORD, DWORD, BOOL, IStream *, IStream **); static PFNSHCreateStreamOnFileEx pfnSHCreateStreamOnFileEx = NULL; +typedef HRESULT (WINAPI *PFNSetCurrentProcessExplicitAppUserModelID)(WCHAR *); +static PFNSetCurrentProcessExplicitAppUserModelID pfnSetCurrentProcessExplicitAppUserModelID; + +typedef HRESULT (WINAPI *PFNGetCurrentProcessExplicitAppUserModelID)(WCHAR **); +static PFNGetCurrentProcessExplicitAppUserModelID pfnGetCurrentProcessExplicitAppUserModelID; + // Some magic hackery macros :-) #define _ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb)) #define _ILNext(pidl) _ILSkip(pidl, (pidl)->mkid.cb) @@ -3271,6 +3277,50 @@ return PyCom_PyObjectFromIUnknown(ret, IID_IStream, FALSE); } +// @pymethod |shell|SetCurrentProcessExplicitAppUserModelID|Sets the taskbar identifier +static PyObject *PySetCurrentProcessExplicitAppUserModelID(PyObject *self, PyObject *args) +{ + // @comm Should be used early in process startup before creating any windows + // @comm Requires Windows 7 or later + // @pyparm str|AppID||The Application User Model ID used to group taskbar buttons + if (pfnSetCurrentProcessExplicitAppUserModelID==NULL) + return PyCom_BuildPyException(E_NOTIMPL); + TmpWCHAR appid; + PyObject *obappid; + if(!PyArg_ParseTuple(args, "O:SetCurrentProcessExplicitAppUserModelID", &obappid)) + return NULL; + if (!PyWinObject_AsWCHAR(obappid, &appid, FALSE)) + return NULL; + + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = (*pfnSetCurrentProcessExplicitAppUserModelID)(appid); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) + return PyCom_BuildPyException(hr); + Py_INCREF(Py_None); + return Py_None; +} + +// @pymethod str|shell|GetCurrentProcessExplicitAppUserModelID|Retrieves the current taskbar identifier +// @comm Will only retrieve an identifier if set by the application, not a system-assigned default. +// @comm Requires Windows 7 or later +static PyObject *PyGetCurrentProcessExplicitAppUserModelID(PyObject *self, PyObject *args) +{ + if (pfnGetCurrentProcessExplicitAppUserModelID==NULL) + return PyCom_BuildPyException(E_NOTIMPL); + WCHAR* appid; + HRESULT hr; + PY_INTERFACE_PRECALL; + hr = (*pfnGetCurrentProcessExplicitAppUserModelID)(&appid); + PY_INTERFACE_POSTCALL; + if (FAILED(hr)) + return PyCom_BuildPyException(hr); + PyObject *ret = PyWinObject_FromWCHAR(appid); + CoTaskMemFree(appid); + return ret; +} + /* List of module functions */ // @module shell|A module wrapping Windows Shell functions and interfaces @@ -3331,6 +3381,8 @@ { "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 { "SHCreateStreamOnFileEx", (PyCFunction)PySHCreateStreamOnFileEx, METH_VARARGS|METH_KEYWORDS}, // @pymeth SHCreateStreamOnFileEx|Creates a <o PyIStream> that reads and writes to a file + { "SetCurrentProcessExplicitAppUserModelID", PySetCurrentProcessExplicitAppUserModelID, METH_VARARGS}, // @pymeth SetCurrentProcessExplicitAppUserModelID|Sets the taskbar identifier + { "GetCurrentProcessExplicitAppUserModelID", PyGetCurrentProcessExplicitAppUserModelID, METH_NOARGS}, // @pymeth GetCurrentProcessExplicitAppUserModelID|Retrieves the current taskbar identifier { NULL, NULL }, }; @@ -3470,6 +3522,8 @@ pfnSHGetIDListFromObject =(PFNSHGetIDListFromObject)GetProcAddress(shell32, "SHGetIDListFromObject"); pfnSHCreateShellItem =(PFNSHCreateShellItem)GetProcAddress(shell32, "SHCreateShellItem"); pfnSHOpenFolderAndSelectItems = (PFNSHOpenFolderAndSelectItems)GetProcAddress(shell32, "SHOpenFolderAndSelectItems"); + pfnSetCurrentProcessExplicitAppUserModelID = (PFNSetCurrentProcessExplicitAppUserModelID)GetProcAddress(shell32, "SetCurrentProcessExplicitAppUserModelID"); + pfnGetCurrentProcessExplicitAppUserModelID = (PFNGetCurrentProcessExplicitAppUserModelID)GetProcAddress(shell32, "GetCurrentProcessExplicitAppUserModelID"); } // SHGetFolderPath comes from shfolder.dll on older systems if (pfnSHGetFolderPath==NULL){ |