AutoHotkey Community

It is currently May 27th, 2012, 1:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: January 27th, 2012, 1:50 pm 
kenn wrote:
I noticed that it's main applications hwnd.
Why don't you use WinGet, ProcessPath, ahk_id %hwnd% and extract the icon from the executable.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 2:44 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Anonymous wrote:
Why don't you use WinGet, ProcessPath, ahk_id %hwnd% and extract the icon from the executable.

Because dictionary icon changes when it's activated, I looked into icons in application, activated icon doesn't exist, it's combination of two icons. So I can't search for states of icon with image search (it has four states).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 3:09 pm 
kenn wrote:
I looked into icons in application,
How?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 3:57 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
With this by changing second parameter in ExtractIcon() function
Code:
hIcon1 := ExtractIcon("C:\Program Files\Lingoes\Translator2\lingoes.exe", 7, 32)
STM_SETICON := 0x0170
Gui, Margin, 20, 20
Gui, Add, Text, w64 h64 hwndmypic1 0x3
SendMessage, STM_SETICON, hIcon1, 0,, Ahk_ID %mypic1%

Gui, Show
Return

GuiClose:
ExitApp
ExtractIcon(Filename, IconNumber, IconSize)
{
   ;most of the code is from Menu Icons v2.21
   ;written by Lexikos http://www.autohotkey.com/forum/topic21991.html
   
    static ExtractIconEx, Ptr, PtrP
   if !Ptr
      Ptr := (A_PtrSize = 8) ? "ptr" : "uint"
   If !PtrP
      PtrP := (A_PtrSize = 8) ? "uptr*" : "uint*"
    ; LoadImage is not used..
    ; ..with exe/dll files because:
    ;   it only works with modules loaded by the current process,
    ;   it needs the resource ordinal (which is not the same as an icon index), and
    ; ..with ico files because:
    ;   it can only load the first icon (of size %IconSize%) from an .ico file.
   
    ; If possible, use PrivateExtractIcons, which supports any size of icon.
    if (IconSize != 16 && IconSize != 32)
        if A_OSVersion in WIN_7,WIN_XP,WIN_VISTA,WIN_2003,WIN_2000
            if DllCall("PrivateExtractIcons", "str", Filename, "int", IconNumber-1, "int", IconSize, "int", IconSize, PtrP, h_icon, "uint*", 0, "uint",1, "uint",0,"int")
                return h_icon
   
    if !ExtractIconEx
      ExtractIconEx := DllCall("GetProcAddress"
                  , ptr, DllCall("GetModuleHandle", str, "shell32", ptr)
                  , A_IsUnicode ? "astr":"str"  ; Always an ANSI string.
                  , "ExtractIconEx" . (A_IsUnicode ? "W":"A"), ptr)   
   
    ; Use ExtractIconEx, which only returns 16x16 or 32x32 icons.
    ; if DllCall(ExtractIconEx, "str", Filename, "int", IconNumber-1, PtrP, h_icon, PtrP, h_icon_small, "uint", 1)
    if DllCall(ExtractIconEx, "str", Filename, "int", IconNumber-1, PtrP, h_icon, PtrP, h_icon_small, "uint", 1)
    {
        SysGet, SmallIconSize, 49
       
        ; Use the best-fit size; delete the other. Defaults to small icon.
        if (IconSize <= SmallIconSize) {
            DllCall("DestroyIcon", ptr, h_icon)
            h_icon := h_icon_small
        } else
            DllCall("DestroyIcon", ptr, h_icon_small)
       
        ; I think PrivateExtractIcons resizes icons automatically,
        ; so resize icons returned by ExtractIconEx for consistency.
        if (h_icon && IconSize)
            h_icon := DllCall("CopyImage", ptr, h_icon, "uint", 1, "int", IconSize, "int", IconSize, "uint", 4|8, ptr)
    }

    return h_icon ? h_icon : 0
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 4:09 pm 
Offline
User avatar

Joined: February 28th, 2011, 7:28 pm
Posts: 625
Location: Germany
I saw that thread too. Please post your request in Ask For Help, it's not really connected to this thread. I might be able to help you there.

A mod may split this.

_________________
RECOMMENDED: AutoHotkey_L
Image
github - ImportTypeLib
Win7 HP SP1 32bit | AHK_L U 32bit


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 5:49 pm 
kenn wrote:
With this by changing second parameter in ExtractIcon() function
You missed my point. I asked how you tried to find which icon has which number.

@maul.esel Sorry, indeed this should be split.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 6:24 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
Edit: Solved


Last edited by kenn on January 30th, 2012, 8:02 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 8:12 pm 
kenn, I suggest to open the executable with ResourceHacker and you'll find the icon numbers you need, then retrieve the application path from hwnd. After that, use the ExtractIcon() function with the icon number.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, sks and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group