 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
jaco0646
Joined: 07 Oct 2006 Posts: 553 Location: MN, USA
|
Posted: Thu Dec 27, 2007 4:23 am Post subject: Reference negative icon numbers |
|
|
Icons inside DLLs are often referred to in the registry and other places using negative numbers. Is it possible to have AHK do the same (e.g. for a Picture control or inside a ListView)?
I quickly made this GUI script to show the icons in the shell32.dll file. But it won't accept negative numbers, which nicely demonstrates my problem.
| Code: | #SingleInstance force
#NoTrayIcon
#NoEnv
DLL=%A_WinDir%\System32\shell32.dll
Num=0
Gui, Add, Button, w50 gUp, Up
Gui, Add, Pic, vPic Icon%Num%, %DLL%
Gui, Add, Button, w50 gDown, Down
Gui, Font, s12
Gui, Add, Edit, vNum gEdit w50, %Num%
Gui, Show
return
GuiClose:
ExitApp
Up:
Down:
Edit:
Gui, Submit, NoHide
If A_GuiControl = Up
Num++
Else If A_GuiControl = Down
Num--
GuiControl,,Pic, *Icon%Num% %DLL%
If A_GuiControl != Num
GuiControl,,Num, %Num%
return |
_________________ http://autohotkey.net/~jaco0646/
Last edited by jaco0646 on Fri Dec 28, 2007 3:58 am; edited 1 time in total |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6772 Location: Pacific Northwest, US
|
Posted: Thu Dec 27, 2007 10:02 pm Post subject: |
|
|
please give an example of something needing the negative numbers. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 553 Location: MN, USA
|
Posted: Fri Dec 28, 2007 1:12 am Post subject: |
|
|
Well, the first example I gave was the registry, which denotes many icons using negative numbers. For example, suppose I wanted to find the default icon a computer uses to display MP3 files. I would look up the key:
| Code: | | HKEY_CLASSES_ROOT\mp3file\DefaultIcon |
and on the PC I'm using right now, the answer is:
| Code: | | C:\PROGRA~1\WINDOW~2\wmplayer.exe,-120 |
Now, the icon being used is actually #2, but I need AHK to work with the negative number.
For a second example, the icon for a text file is shown in the registry as: | Code: | | %SystemRoot%\system32\shell32.dll,-152 | ...this is actually icon #71. _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Fri Dec 28, 2007 5:28 am Post subject: |
|
|
The icon indices used by AutoHotkey are zero-based, never negative. The DefaultIcon registry key uses a resource id, which is different to an icon index.
If you search the forums for "LoadImage", you might find some examples of how to load an icon, given a resource id. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 553 Location: MN, USA
|
Posted: Sat Dec 29, 2007 1:16 am Post subject: |
|
|
Thanks for the info. Is the resource ID method significantly more complicated to code for, or would this be worth a "Wish List" post? _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Sat Dec 29, 2007 2:02 am Post subject: |
|
|
| It's fairly simple. Might be worth it. |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 553 Location: MN, USA
|
Posted: Sat Dec 29, 2007 3:15 am Post subject: |
|
|
It seems that the resource IDs are at least sequential, like an index number (at least for shell32.dll). So given the offset for a particular DLL, it's easy to calculate the icon number from the resource ID.
For example, the offset in shell32.dll is 223, the difference between -152 and 71 in my previous example. Resource ID number -151 is icon number 72, and so on. So, given the resource ID of the first icon in a DLL, it's simple to calculate the icon numbers for any other resource, and thus have an easy workaround.
Perhaps it wouldn't be too difficult to code a function that returns the resource ID of icon #0 in a given file. Unfortunately, I know next to nothing about DLLcall, so it's beyond my skills.  _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1125
|
Posted: Sat Dec 29, 2007 3:57 am Post subject: |
|
|
It may be worthwhile for someone (other than me ) to write a script that acquires general information about a selected DLL and displays the info in a GUI. That is unless you can find the specs for the DLL somewhere like MSDN...
... Just a thought. _________________ My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2557 Location: Australia, Qld
|
Posted: Sat Dec 29, 2007 4:54 am Post subject: |
|
|
| jaco0646 wrote: | | It seems that the resource IDs are at least sequential, like an index number (at least for shell32.dll). So given the offset for a particular DLL, it's easy to calculate the icon number from the resource ID. | That is true for shell32.dll, but not necessarily other dlls. If you have a list of all resource ids, you could probably calculate the index. Resource IDs are not necessarily contiguous, but maybe the icon indices are in the same order.
Edit: Icons can be loaded directly by resource ID using LoadImage, but then you need to know how to use the icon handle. Since it depends on what you're using it for, it's probably easier to convert the ID to an index. You may include the following in your script, or use it once to convert a resource ID to an icon index.
| Code: | IndexOfIconResource(Filename, ID)
{
hmod := DllCall("GetModuleHandle", "str", Filename)
; If the DLL isn't already loaded, load it as a data file.
loaded := !hmod
&& hmod := DllCall("LoadLibraryEx", "str", Filename, "uint", 0, "uint", 0x2)
enumproc := RegisterCallback("IndexOfIconResource_EnumIconResources","F")
VarSetCapacity(param,12,0), NumPut(ID,param,0)
; Enumerate the icon group resources. (RT_GROUP_ICON=14)
DllCall("EnumResourceNames", "uint", hmod, "uint", 14, "uint", enumproc, "uint", ¶m)
DllCall("GlobalFree", "uint", enumproc)
; If we loaded the DLL, free it now.
if loaded
DllCall("FreeLibrary", "uint", hmod)
return NumGet(param,8) ? NumGet(param,4) : 0
}
IndexOfIconResource_EnumIconResources(hModule, lpszType, lpszName, lParam)
{
NumPut(NumGet(lParam+4)+1, lParam+4)
if (lpszName = NumGet(lParam+0))
{
NumPut(1, lParam+8)
return false ; break
}
return true
} | The script assumes the order of the icon resources defines the icon indices. It supports only numeric resource IDs, not resource names.
Example usage:
| Code: | | Menu, Tray, Icon, shell32.dll, % IndexOfIconResource("shell32.dll", 324) | On XP and Vista, ID 324 = Icon211 (a blue " "). |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 553 Location: MN, USA
|
|
| Back to top |
|
 |
Mustang
Joined: 17 May 2007 Posts: 375 Location: England
|
Posted: Mon Dec 31, 2007 6:09 am Post subject: |
|
|
Very helpful
Thanks lexikos |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 338
|
Posted: Wed May 21, 2008 12:40 am Post subject: |
|
|
Beautiful!
Thanks Lexikos.
I think that its worth noting that while the negative number signifies that it is an icon resource and not an icon index, the value itself should be passed as a positive. Also, the icon index used in the reg seems to be 0-based and the icon index in ahk is 1-based.
This makes sure it works either way: | Code: | If(iconNum < 0) ;if an icon resource given
{ iconNum := IndexOfIconResource(iconSrc, Abs(iconNum))
}
Else ;icon number given
{ iconNum++ ;convert from 0 to 1 based
}
|
Thanks again! _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|