This shows you the differences between two versions of the page.
extracting_20a_20file_27s_20thumbnail [2018/03/31 13:19] 127.0.0.1 external edit |
extracting_20a_20file_27s_20thumbnail [2018/04/13 15:43] (current) richardrussell Added syntax highlighting |
||
---|---|---|---|
Line 1: | Line 1: | ||
=====Extracting a file's thumbnail===== | =====Extracting a file's thumbnail===== | ||
- | //by Richard Russell, July 2007//\\ \\ Several file types can have associated thumbnail images, which are displayed (for example) in Windows Explorer's **Thumbnails** view. Examples of such file types are image files (e.g. BMP, GIF, JPEG), PowerPoint files, Word and Excel files (when the **Save preview picture** option is enabled) and folders.\\ \\ Displaying such thumbnails in your own program, should you want to, is quite tricky, but is made simple using the **FN_thumbnail** function listed in this article. This function returns a //handle// to the thumbnail image, which you can use as you would any other image handle. For example you can use it to display the image in a **static control**, either in a dialogue box or on your main output window.\\ \\ The code below will display, in a static control, the thumbnail for the file **CLOCK.JPG**:\\ \\ | + | //by Richard Russell, July 2007//\\ \\ Several file types can have associated thumbnail images, which are displayed (for example) in Windows Explorer's **Thumbnails** view. Examples of such file types are image files (e.g. BMP, GIF, JPEG), PowerPoint files, Word and Excel files (when the **Save preview picture** option is enabled) and folders.\\ \\ Displaying such thumbnails in your own program, should you want to, is quite tricky, but is made simple using the **FN_thumbnail** function listed in this article. This function returns a //handle// to the thumbnail image, which you can use as you would any other image handle. For example you can use it to display the image in a **static control**, either in a dialogue box or on your main output window.\\ \\ The code below will display, in a static control, the thumbnail for the file **CLOCK.JPG**: |
+ | |||
+ | <code bb4w> | ||
INSTALL @lib$+"WINLIB5" | INSTALL @lib$+"WINLIB5" | ||
Line 17: | Line 19: | ||
hbm% = FN_thumbnail(file$, cx%, cy%) | hbm% = FN_thumbnail(file$, cx%, cy%) | ||
SYS "SendMessage", hsb%, _STM_SETIMAGE, 0, hbm% | SYS "SendMessage", hsb%, _STM_SETIMAGE, 0, hbm% | ||
- | Here **xpos%** and **ypos%** are the position where you want the static control to be displayed (pixels from the top left-hand corner) and **cx%** and **cy%** are the desired width and height in pixels. If you want to display the thumbnail for a folder **don't** include a trailing backslash (**\**) in the pathname you specify.\\ \\ When you have finished with the image you should delete its handle as follows:\\ \\ | + | </code> |
+ | |||
+ | Here **xpos%** and **ypos%** are the position where you want the static control to be displayed (pixels from the top left-hand corner) and **cx%** and **cy%** are the desired width and height in pixels. If you want to display the thumbnail for a folder **don't** include a trailing backslash (**\**) in the pathname you specify.\\ \\ When you have finished with the image you should delete its handle as follows: | ||
+ | |||
+ | <code bb4w> | ||
SYS "DeleteObject", hbm% | SYS "DeleteObject", hbm% | ||
- | Don't do this whilst the image is still displayed, since it will not refresh correctly when uncovered, or when restored after being minimised.\\ \\ The **FN_thumbnail** function is listed below. Its parameters are the file or folder whose thumbnail is wanted and the preferred width and height of the thumbnail in pixels. It returns a handle to the thumbnail image, or zero if the file does not have a thumbnail. An error will result if the file/folder does not exist or the file is an unsuitable type.\\ \\ | + | </code> |
+ | |||
+ | Don't do this whilst the image is still displayed, since it will not refresh correctly when uncovered, or when restored after being minimised.\\ \\ The **FN_thumbnail** function is listed below. Its parameters are the file or folder whose thumbnail is wanted and the preferred width and height of the thumbnail in pixels. It returns a handle to the thumbnail image, or zero if the file does not have a thumbnail. An error will result if the file/folder does not exist or the file is an unsuitable type. | ||
+ | |||
+ | <code bb4w> | ||
DEF FN_thumbnail(file$, cx%, cy%) | DEF FN_thumbnail(file$, cx%, cy%) | ||
LOCAL patha%, pathw%, name%, ole32%, shfroot%, shf%, pidl%, iei%, flags%, hbm% | LOCAL patha%, pathw%, name%, ole32%, shfroot%, shf%, pidl%, iei%, flags%, hbm% | ||
Line 84: | Line 94: | ||
SYS `CoUninitialize` | SYS `CoUninitialize` | ||
= hbm% | = hbm% | ||
+ | </code> |