def get_known_folder_id_list(folder_id, htoken=None): pidl = ctypes.c_void_p() _shell32.SHGetKnownFolderIDList(ctypes.byref(folder_id), 0, htoken, ctypes.byref(pidl)) folder_id_list = shell.AddressAsPIDL(pidl.value) _ole32.CoTaskMemFree(pidl) return folder_id_list
def BrowseCallbackProc(hwnd, msg, lp, data): if msg == shellcon.BFFM_INITIALIZED: win32gui.SendMessage(hwnd, shellcon.BFFM_SETSELECTION, 1, data) elif msg == shellcon.BFFM_SELCHANGED: # Set the status text of the # For this message, 'lp' is the address of the PIDL. pidl = shell.AddressAsPIDL(lp) try: path = shell.SHGetPathFromIDList(pidl) win32gui.SendMessage(hwnd, shellcon.BFFM_SETSTATUSTEXT, 0, path) except shell.error: # No path for this PIDL pass
def get_known_folder_id_list(folder_id, htoken=None): if isinstance(folder_id, pywintypes.IIDType): folder_id = bytes(folder_id) pidl = ctypes.c_void_p() try: _shell32.SHGetKnownFolderIDList(folder_id, 0, htoken, ctypes.byref(pidl)) return shell.AddressAsPIDL(pidl.value) except WindowsError as e: if e.winerror & 0x80070000 == 0x80070000: # It's a WinAPI error, so re-raise it, letting Python # raise a specific exception such as FileNotFoundError. raise ctypes.WinError(e.winerror & 0x0000FFFF) raise finally: if pidl: _ole32.CoTaskMemFree(pidl)
def BrowseCallbackProc(hwnd, msg, lp, data): from win32com.shell import shell, shellcon if msg== shellcon.BFFM_INITIALIZED: win32gui.SendMessage(hwnd, shellcon.BFFM_SETSELECTION, 1, data) win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0) elif msg == shellcon.BFFM_SELCHANGED: # Set the status text of the # For this message, 'lp' is the address of the PIDL. pidl = shell.AddressAsPIDL(lp) try: path = shell.SHGetPathFromIDList(pidl) if os.path.isdir(path): win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0) else: ext = path.split('.')[-1] if ext not in ['gif', 'bmp', 'jpg', 'tif', 'ico']: win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0) else: win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 1) except shell.error: # No path for this PIDL pass