Jump to content

transfer to autoit


 Share

Recommended Posts

using System;
using System.IO;
using System.Threading;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Icon_extractor
{
    class Program
    {
        static void Main(string[] args)
        {
            Icon myIcon = Getpicture('file to extract the icon from'), 'big or small true/false'));
            Bitmap bmp = myIcon.ToBitmap();
            using (FileStream fs = new FileStream('filename to save') + ".bmp", FileMode.Create)) bmp.Save(fs, System.Drawing.Imaging.ImageFormat.Bmp);
        }

        static Icon Getpicture(string fName, Boolean smallicon)
        {
            Shfileinfo shinfo = new Shfileinfo();
            //Use this to get the small Icon
            if (smallicon)
            {
                IntPtr hImgSmall = Win32.SHGetFileInfo(fName, 0, ref shinfo,
                                                       (uint)Marshal.SizeOf(shinfo),
                                                       Win32.ShgfiIcon |
                                                       Win32.ShgfiSmallicon);
            }
            else
            {
                //Use this to get the large Icon
                IntPtr hImgLarge = Win32.SHGetFileInfo(fName, 0,
                                                       ref shinfo, (uint)Marshal.SizeOf(shinfo),
                                                       Win32.ShgfiIcon | Win32.ShgfiLargeicon);
            }
            //The icon is returned in the hIcon member of the shinfo
            //struct
            return Icon.FromHandle(shinfo.hIcon);
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct Shfileinfo
    {
        public IntPtr hIcon;
        public IntPtr iIcon;
        public uint dwAttributes;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szDisplayName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
        public string szTypeName;
    };

    class Win32
    {
        public const uint ShgfiIcon = 0x100;
        public const uint ShgfiLargeicon = 0x0;    // 'Large icon
        public const uint ShgfiSmallicon = 0x1;    // 'Small icon

        [DllImport("shell32.dll")]
        public static extern IntPtr SHGetFileInfo(string pszPath,
                                    uint dwFileAttributes,
                                    ref Shfileinfo psfi,
                                    uint cbSizeFileInfo,
                                    uint uFlags);
    }
}

I like to have this at autoit code but i don't now anything about create dll call's.

I have searched for examples and tried but it just will not work

Can some one help for this?

Thanks

Link to comment
Share on other sites

Search the help file for "*icon* *extract*" and you will find plenty of examples.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Found your exampels at help file.

And i search this all before and just try to find a solution again

But they all don't work on txt,vbs,au3,bat ....

on exe and dll i can get it to work

thats why i used those c# code you can extract icon from almost any file just by calling that file only

Jfish i now that function but i don't now how to create all that from the c# code

is there realy no way ?

Link to comment
Share on other sites

Found your exampels at help file.

And i search this all before and just try to find a solution again

But they all don't work on txt,vbs,au3,bat ....

If I understand you correctly, you're trying to extract icons from those file types? None of those file types have icons in them, so you're not going to be able to extract something that isn't there. You need to search the registry for the icons associated with those file types and find where they're located (in what dll or exe they might be in), because you're not going to get them directly from a txt file for example.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Take a look at _WinAPI_ShellGetFileInfo in the help file, it's a wrapper for the SHGetFileInfo function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Take a look at _WinAPI_ShellGetFileInfo in the help file, it's a wrapper for the SHGetFileInfo function.

going nowhere with this

$tSHFILEINFO $tagSHFILEINFO structure to receive the file information. This structure must be created before function call.

how please?

Edited by Spider001
Link to comment
Share on other sites

No offence, but if you don't know how to create the structure are you sure you should be attempting this in the first place? This appears to be above your ability and you're just looking for someone to write this for you rather than doing the background needed to get this accomplished by yourself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include <WinAPIShellEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>

$file = 'D:\data\scripts\eigen\bat to exe\test folder\test.bat'
$testpic = 'D:\data\dirsync_start\laptop\start collector client\iconsprog\7-Zip File Manager.lnk.bmp'

Global Const $etagSHFILEINFO = 'ptr hIcon;int iIcon;dword Attributes;wchar DisplayName[260];wchar TypeName[80]'
Local $tSHFILEINFO = DllStructCreate($etagSHFILEINFO)

GUICreate("ImageList Create", 400, 300)
_WinAPI_ShellGetFileInfo($file,BitOR($SHGFI_ICON,$SHGFI_SMALLICON,$SHGFI_ATTRIBUTES,$SHGFI_DISPLAYNAME,$SHGFI_TYPENAME),0,$tSHFILEINFO)
ConsoleWrite($tSHFILEINFO.hIcon & @CRLF)
ConsoleWrite($tSHFILEINFO.iIcon & @CRLF)
ConsoleWrite($tSHFILEINFO.Attributes & @CRLF)
ConsoleWrite($tSHFILEINFO.DisplayName & @CRLF)
ConsoleWrite($tSHFILEINFO.TypeName & @CRLF)
$test = GUICtrlCreateButton($tSHFILEINFO.DisplayName, 20, 20, 200, 200, $BS_MULTILINE)
                $hImagebtn3 = _GUIImageList_Create(64, 64, 5)
                _GUIImageList_AddBitmap($hImagebtn3, DllStructGetData($tSHFILEINFO, 'hIcon'))
                _GUICtrlButton_SetImageList($test, $hImagebtn3)
GUISetState(@SW_SHOW)

Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

but the icon is not show

Edited by Spider001
Link to comment
Share on other sites

It appears as though you don't understand some computer basics.

There are files, that are purely data, and then there are files that are applications and application extensions.

There is more than that of course, but sticking to basics, that is all you need to know right now.

Data files (doc, txt, etc) do not have icons embedded in them, unless they are something like an ico file or an icon library file.

Not all application files (exe, bat, etc) have icons, but many do ... sometimes several.

The same applies for application extension files (dll, etc).

Many data type files, get there icon from the program file that opens them (Notepad, Word, Excel, etc).

These icons don't exist in the data file, but have something akin to a shortcut file associated with them, so that you see the assigned icon.

Bat files, in my recollection, never have icons embedded in them.

The icon you see displayed for a bat file, exists in a system file (exe, dll, etc) - C:\Windows\System32\shell32.dll

AutoIt used to come with a fair Icon Browser program in Examples. It may still do ... I don't have a recent install on this machine, so cannot check. If I remember correctly, I have an expanded version of it, in my Toolbox (see my signature below).

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

So i can understand on all the post that are made now and before on that mather.

No one now,s how to do it at autoit like the c# code i changed,worked and posted here.

No offence, but with no help and (bla,bla, you don't now this and that,..) we oly turn in circels.

The c# code don't care if the icon is stored at the file or not.

I don't ask what or not i now from script knowledge , i just ask to point me on the right direction.

the autoit code that i posted i created from a awnser from a other post even nothing to do with icons but it helped me.

I can extract everything else just that icon that's all.

i now some are stored at the file and some not and that's not my problem the c# code don't care

Link to comment
Share on other sites

I guess, that the simple answer to that, is we are giving you the correct approach to getting icons, rather than converting your C# code. Conversions rarely work as well, as the correct approach from scratch in the language you are using.

As has been said, there are plenty of examples of using DllCall, both in the Help file, and here in various sections of the Forum. You just need to fine tune your search method. Don't forget the Examples section, where you will find oodles.

Most of us are not into converting code from other languages, though we will help you if you try to do it yourself, in stages. We are more into teaching than giving presents.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

again with that c# code i can get the one's that are stored and not stored.

with no calling to shell32.dll,...

if windows shows the icon that not is stored windows pass it so no need to check all the rest then the original file.

it's not only exe files it's all file types

example test.lnk

- no stored icon on that file

- with C# you get that icon

next example autoit created exe with icon

- stored icon on a file

- with C# you get that icon

and all with that c# code

if you now this way to extract why don't just me give the link to that code or the link at help that will help.

Google and the help file is working late hours for me to find a awnser.

"Most of us are not into converting code from other languages, though we will help you if you try to do it yourself, in stages. We are more into teaching than giving presents" = deleted all the include files and example files then you can all find it at the help.

i don't ask for presents

i don't ask to write the whole prog for me it's one thing to help

what do you think i do, i'am trying from 27 September 2014

"Look at the "C" code that you posted.  You will see that it is finding icons using the Win32 API "SHGetFileInfo".  BrewmanNH gave you the answer in post #7."

i don't get it so we are still turning circels and look at the autoit code i posted there you have your SHGetFileInfo

Edited by Spider001
Link to comment
Share on other sites

@Spider001 - What we are saying in short, is write your own version of what the C# code is doing. If you have any trouble, we will help you, but you need to make a start. We will help you to help yourself. A good starting point, is that Icon Browser program I mentioned ... build on that.

Basically, you are looking at a file to see if it has an icon.

If not, then you look at the file to see what program it is associated with.

Usually that program, will have two or more icons embedded in it, one for itself, and at least one for the file type(s) it opens.

Those embedded icons will each have a unique number, which is the one you need to determine.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Thank you for the post kylomas this helpted me a lot

this one was a help to

so i used the 2 i whas playing around and find one more thing but i'am finaly getting there.

#include <WinAPIShellEx.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiToolbar.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Opt( "MustDeclareVars", 1 )

; Icon sizes
Global Const $SHIL_LARGE      = 0x0 ; 32x32 pixels
Global Const $SHIL_SMALL      = 0x1 ; 16x16 pixels
Global Const $SHIL_EXTRALARGE = 0x2 ; 48x48 pixels
Global Const $SHIL_SYSSMALL   = 0x3 ; GetSystemMetrics for SM_CXSMICON and SM_CYSMICON
Global Const $SHIL_JUMBO      = 0x4 ; 256x256 pixels, Vista+

MainFunc()

Func MainFunc()
   Global $file4 = 'D:\data\scripts\eigen\bat to exe\bat_to_exe.exe'
   Global $file3 = 'D:\data\scripts\eigen\netwerk drives\settings.ini'
   Global $file2 = 'D:\data\scripts\eigen\netwerk drives\netwerklinks.exe'
   Global $file = 'D:\data\scripts\eigen\netwerk drives\Network ID.ico'
   Global $file1 = 'D:\data\scripts\eigen\bat to exe\test folder\test.exe'
   Global $testpic = 'D:\data\dirsync_start\laptop\start collector client\iconsprog\7-Zip File Manager.lnk.bmp'
  ; Create GUI
  Local $hGui = GUICreate( "Drop files or folders (one at a time) on the listview to show icons", 550, 500, 300, 200)

  ; System image list
  Local $hImlLarge = GetSystemImageList( False, $SHIL_EXTRALARGE )

      ; Create ListView
      Local $idLV = GUICtrlCreateListView( "", 50, 50, 150, 150 )
      GUICtrlSetStyle( $idLV, $LVS_ICON )
      _GUICtrlListView_SetImageList( $idLV, $hImlLarge, 0 )
        Local $iImage = GetIconIndex( $file )
        Local $sText = StringRight( $file, StringLen( $file ) - StringInStr( $file, "\", 0, -1 ) )
      ;_GUICtrlListView_AddItem( $idLV, '' , $iImage)

      ;toolbar
      Local $hToolbar = _GUICtrlToolbar_Create( $hGui, $TBSTYLE_FLAT + $TBSTYLE_LIST )
      _GUICtrlToolbar_SetImageList( $hToolbar, $hImlLarge )
      Local $iImage = GetIconIndex( $file1 )
      _GUICtrlToolbar_AddButton( $hToolbar, 1, $iImage, 0,  $BTNS_AUTOSIZE)
      _GUICtrlToolbar_SetButtonText( $hToolbar, 1, "Icons" )
      Local $iImage = GetIconIndex( $file2 )
      _GUICtrlToolbar_AddButton( $hToolbar, 2, $iImage, 0,$BTNS_AUTOSIZE)
      _GUICtrlToolbar_SetButtonText( $hToolbar, 2, "2de" )
      Local $iImage = GetIconIndex( $file3 )
       _GUICtrlToolbar_AddButton( $hToolbar, 3, $iImage, 0,$BTNS_AUTOSIZE)
      _GUICtrlToolbar_SetButtonText( $hToolbar, 3, "test" )

      ;show all icons at listview
          Local $n = _GUIImageList_GetImageCount( $hImlLarge )
    For $i = 0 To $n - 1
        _GUICtrlListView_AddItem( $idLV, $i, $i )
     Next

     ;icon on button
Local $iImage = GetIconIndex( $file4 )
   Local $test = GUICtrlCreateButton('test fd fdf dfdf dff df dfd f df', 200, 200, 150, 150,$BS_MULTILINE)
                  Local $hImagebtn3 = _GUIImageList_Create()
                 $hImagebtn3 = _GUIImageList_Duplicate($hImlLarge)
                   _GUIImageList_Swap($hImagebtn3,$iImage,0)
                _GUICtrlButton_SetImageList($test, $hImagebtn3)

      ;show info
    Local  $tInfo = _GUIImageList_GetImageInfoEx($hImagebtn3, 0)
    ConsoleWrite("Image handle .: 0x" & Hex(DllStructGetData($tInfo, "hBitmap")) & @CRLF)
    ConsoleWrite("Mask handle ..: " & DllStructGetData($tInfo, "hMask") & @CRLF)
    ConsoleWrite("Image Left ...: " & DllStructGetData($tInfo, "Left") & @CRLF)
    ConsoleWrite("Image Top ....: " & DllStructGetData($tInfo, "Top") & @CRLF)
    ConsoleWrite("Image Right ..: " & DllStructGetData($tInfo, "Right") & @CRLF)
    ConsoleWrite("Image Bottom .: " & DllStructGetData($tInfo, "Bottom") & @CRLF)



  ; Show GUI
  GUISetState( @SW_SHOW )

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
  GUIDelete( $hGui )
  Exit
EndFunc

Func GetSystemImageList( $bLargeIcons = False , $icostumicons = $SHIL_SMALL)
  Local $tSHFILEINFO = DllStructCreate( $tagSHFILEINFO )
  Local $dwFlags = BitOR( $SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX )
  If Not $bLargeIcons Then $dwFlags = BitOR( $dwFlags, $icostumicons )
  Local $hIml = _WinAPI_ShellGetFileInfo( ".txt", $dwFlags, $FILE_ATTRIBUTE_NORMAL, $tSHFILEINFO )
  If @error Then Return SetError( @error, 0, 0 )
  Return $hIml
EndFunc

Func GetIconIndex( $sFileName )
  Local $pPIDL = _WinAPI_ShellILCreateFromPath( $sFileName )
  Local $tSHFILEINFO = DllStructCreate( $tagSHFILEINFO )
  Local $iFlags = BitOr( $SHGFI_PIDL, $SHGFI_SYSICONINDEX )
  ShellGetFileInfo( $pPIDL, $iFlags, 0, $tSHFILEINFO )
  Local $iIcon = DllStructGetData( $tSHFILEINFO, "iIcon" )
  _WinAPI_CoTaskMemFree( $pPIDL )
  Return $iIcon
EndFunc

Func ShellGetFileInfo($pPIDL, $iFlags, $iAttributes, ByRef $tSHFILEINFO)
  Local $aRet = DllCall('shell32.dll', 'dword_ptr', 'SHGetFileInfoW', 'ptr', $pPIDL, 'dword', $iAttributes, 'struct*', $tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)
  If @error Then Return SetError(@error, @extended, 0)
  Return $aRet[0]
EndFunc
Edited by Spider001
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...