erix Posted May 1, 2010 Share Posted May 1, 2010 Hi, Is there anyway to get a thumbnail of a file similar to the way explorer does. I'm looking for put the thumbnail of a file in a GUI. Files are not JPG or BMP or image but PDF or DWG. Thanks Link to comment Share on other sites More sharing options...
erix Posted May 11, 2010 Author Share Posted May 11, 2010 No idea ? Link to comment Share on other sites More sharing options...
Yashied Posted May 11, 2010 Share Posted May 11, 2010 expandcollapse popup#Include <GDIPlus.au3> #Include <GUIConstantsEx.au3> #Include <GUIImageList.au3> #Include <GUIListView.au3> #Include <File.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> Global Const $Path = @WindowsDir & '\Web\Wallpaper' _GDIPlus_Startup() $hForm = GUICreate('MyGUI', 800, 600, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $WS_EX_COMPOSITED) $hListView = _GUICtrlListView_Create($hForm, 'Item', 0, 0, 800, 600, BitOR($LVS_AUTOARRANGE, $LVS_ICON)) _GUICtrlListView_SetTextBkColor($hListView, $CLR_NONE) _GUICtrlListView_SetBkColor($hListView, 0xD9FFEB) $hImageList = _GUIImageList_Create(64, 64, 5, 1) _GUICtrlListView_SetImageList($hListView, $hImageList) $FileList = _FileListToArray($Path, '*', 1) If IsArray($FileList) Then For $i = 1 To $FileList[0] _GUICtrlListView_InsertItem($hListView, $FileList[$i], $i - 1) If StringRegExpReplace($FileList[$i], '^.*\.', '') = 'ico' Then _GUICtrlListView_SetItemIconEx($hListView, $i - 1, $hImageList, $Path & '\' & $FileList[$i]) Else _GUICtrlListView_SetItemImageEx($hListView, $i - 1, $hImageList, $Path & '\' & $FileList[$i]) EndIf Next EndIf GUIRegisterMsg($WM_SIZE, 'WM_SIZE') GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd _GDIPlus_Shutdown() Func _GUICtrlListView_SetItemIconEx($hWnd, $iIndex, ByRef $hImageList, $sFile, $iIcon = 0) Local $Size = _GUIImageList_GetIconSize($hImageList) If (Not $Size[0]) Or (Not $Size[1]) Then Return 0 EndIf Local $hIcon = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sFile, 'int', $iIcon, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0) If (@error) Or (Not $hIcon[0]) Or (Not $hIcon[5]) Then Return 0 EndIf _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon[5]) _GUICtrlListView_SetItemImage($hWnd, $iIndex, _GUIImageList_GetImageCount($hImageList) - 1) _WinAPI_DestroyIcon($hIcon[5]) EndFunc ;==>_GUICtrlListView_SetItemIconEx Func _GUICtrlListView_SetItemImageEx($hWnd, $iIndex, ByRef $hImageList, $sFile) Local $Size = _GUIImageList_GetIconSize($hImageList) If (Not $Size[0]) Or (Not $Size[1]) Then Return 0 EndIf Local $W, $H, $hGraphic, $hPic, $hImage, $hIcon _GDIPlus_Startup() $hPic = _GDIPlus_ImageLoadFromFile($sFile) $W = _GDIPlus_ImageGetWidth($hPic) $H = _GDIPlus_ImageGetHeight($hPic) If ($W < 0) Or ($H < 0) Then _GDIPlus_Shutdown() Return 0 EndIf If $W < $H Then $W = $Size[0] * $W / $H $H = $Size[1] Else $H = $Size[1] * $H / $W $W = $Size[0] EndIf $hImage = DllCall($ghGDIPDll, 'int', 'GdipGetImageThumbnail', 'ptr', $hPic, 'int', $Size[0], 'int', $Size[1], 'ptr*', 0, 'ptr', 0, 'ptr', 0) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage[4]) _GDIPlus_GraphicsClear($hGraphic, 0) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hPic, ($Size[0] - $W) / 2, ($Size[1] - $H) / 2, $W, $H) $hIcon = DllCall($ghGDIPDll, 'int', 'GdipCreateHICONFromBitmap', 'ptr', $hImage[4], 'ptr*', 0) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage[4]) _GDIPlus_ImageDispose($hPic) _GDIPlus_Shutdown() If Not $hIcon[2] Then Return 0 EndIf _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon[2]) _GUICtrlListView_SetItemImage($hWnd, $iIndex, _GUIImageList_GetImageCount($hImageList) - 1) _WinAPI_DestroyIcon($hIcon[2]) Return 1 EndFunc ;==>_GUICtrlListView_SetItemImageEx Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) Local $Pos Switch $hWnd Case $hForm $Pos = WinGetClientSize($hForm) WinMove($hListView, '', 0, 0, $Pos[0], $Pos[1]) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
erix Posted May 11, 2010 Author Share Posted May 11, 2010 Thank you Yashied. Your script works for image files but not for PDF, ODT, DWG... Link to comment Share on other sites More sharing options...
erix Posted May 12, 2010 Author Share Posted May 12, 2010 I found this method who works on Windows XP but not on Windows 7 : http://www.autoitscript.com/forum/index.php?showtopic=39120 Link to comment Share on other sites More sharing options...
KaFu Posted May 12, 2010 Share Posted May 12, 2010 (edited) I'm curious myself... after some research I came up with this MSDN article: http://msdn.microsoft.com/en-us/library/aa969353.aspx IExtractImage or IExtractImage2 are backward compatible to XP, but if you're running Vista or Win7 I guess the IThumbnailProvider interface provides an overall better functionality. Edit: Here's a sample for IExtractImage: http://www.codeproject.com/KB/shell/thumbextract.aspx Something to tinker on for the COM experts Edited May 12, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
erix Posted May 12, 2010 Author Share Posted May 12, 2010 Thank you KaFu. But how do your translate this in Autoit langage ? Link to comment Share on other sites More sharing options...
KaFu Posted May 12, 2010 Share Posted May 12, 2010 Well... I can't (at least in reasonable time). But that seems to be the way Windows does it. Maybe someone with an extensive knowledge about the COM interface (which I don't have) becomes curious too and will take a look... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
erix Posted May 12, 2010 Author Share Posted May 12, 2010 Or perhaps a new function for the next version of Autoit Link to comment Share on other sites More sharing options...
erix Posted June 7, 2010 Author Share Posted June 7, 2010 Hello No other idea ? Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now