Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Embed images in compiled AutoHotkey scripts?


  • Please log in to reply
73 replies to this topic

Poll: Would you be interested in the ability to have images embeded in compiled AutoHotkey scripts? (146 member(s) have cast votes)

Would you be interested in the ability to have images embeded in compiled AutoHotkey scripts?

  1. Voted Yes (183 votes [99.46%])

    Percentage of vote: 99.46%

  2. No (1 votes [0.54%])

    Percentage of vote: 0.54%

Vote Guests cannot vote
ParanoidX
  • Members
  • 148 posts
  • Last active: Jan 14 2007 02:00 AM
  • Joined: 16 Dec 2005
ABSOLUTE YES!! Execellent suggestion Corrupt!!!
Posted Image
546F206C69766520
6973204368726973742C0D746F2064696520
6973206761696E2E0D285068696C20313A323129

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004

Why just images? It might even be easier if AutoHotkey had an embedded resource file to store strings, icons, and possibly other files including images.

i second this.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I don't have the expertise to even know if this would be feasible. So unless someone else were to develop it, it probably won't be added anytime soon.

However, I believe you can add resources (such as BMP images) by using ResHacker on the AutoHotkeySC.bin file. Then perhaps DllCall could call functions like LoadImage() to load the resource directly from the script's own file (without having to use FileInstall).

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
I started working on a script to test functionality/limitations but got a bit sidetracked unfortunately :roll: ... Has anyone had a chance to try adding a resource and referencing it from within a script yet?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Has anyone had a chance to try adding a resource and referencing it from within a script yet?


Yes, with success! :D

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006

Yes, with success! :D


Do share, please.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Foreword: Special thanks to Sean.

Although I haven't experimented with it much, I believe you can already add resources of your choice by using ResHacker on the AutoHotkeySC.bin file. Then I think you could use DllCall to call functions like LoadImage() to load the resource.


Dear Friends, :)

You will need my version of AutoHotkeySC.bin - 444KB ( 1.0.47.04 ) which has additional resources that are being referenced in the following example scripts:
Rename the default \AutoHotkey\Compiler\AutoHotkeySC.bin and download the above file into the same folder.

All the examples have to be compiled before execution.
Also you might want to rename UPX.EXE ( to turn off Compression ) if you want to explore the resultant EXE in ResHacker.

Referencing a BITMAP:

Gui, Margin, 0 , 0
hModule  := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) 
hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt,[color=red]560[/color], UInt,(IMAGE_BITMAP:=0x0)
                  , Int,400, Int,300, UInt, (LR_SHARED := 0x8000) ) 

Gui, Add,Text, x0 y0 w0 h0 hwndPic1 +0xE

SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1, , ahk_id %Pic1%
Gui, Show, w400 h300, Gradient Background
Return

GuiClose:
 ExitApp

Referencing a WAVE:

hModule   := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) 
hResource := DllCall("FindResource", UInt,hModule, UInt,[color=red]666[/color], UInt,10 )
nSize     := DllCall("SizeofResource", UInt,hModule, UInt, hResource )

hResData  := DllCall("LoadResource", UInt,0, UInt,hResource )
Buffer    := DllCall("LockResource", "UInt", hResData )

Loop 10 { ; ringout.wav 
 DllCall("winmm.dll\sndPlaySoundA", UInt,Buffer, UINT, ( (SND_MEMORY:=0x4) | (SND_NODEFAULT:=0x2)) )
 Sleep 1000
}

ExitApp

Referencing a JPEG:

Gui, Margin, 0, 0 
Gui, Add, Text, x0 y0 w800 h600 +0xE hWndPic1 ; +0xE is SS_BITMAP 

hModule   := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) 
hResource := DllCall("FindResource", UInt,hModule, UInt,[color=red]555[/color], UInt,10)
nSize     := DllCall("SizeofResource", UInt,hModule, UInt, hResource)

hResData  := DllCall("LoadResource", UInt,hModule, UInt,hResource )
Buffer    := DllCall("LockResource", UInt, hResData )

; Converting Image data to hBITMAP ; Thanks Sean
; http://www.autohotkey.com/forum/viewtopic.php?t=22999

hData := DllCall("GlobalAlloc", UInt,2, UInt, nSize ) 
pData := DllCall("GlobalLock",  UInt,hData ) 
DllCall( "RtlMoveMemory", UInt,pData, UInt,Buffer, UInt,nSize ) 
DllCall( "GlobalUnlock", UInt,hData ) 
DllCall( "ole32\CreateStreamOnHGlobal", UInt,hData, Int,True, UIntP,pStream ) 

DllCall( "LoadLibrary", Str,"gdiplus" )
VarSetCapacity(si, 16, 0), si := Chr(1) 
DllCall( "gdiplus\GdiplusStartup", UIntP,pToken, UInt,&si, UInt,0 ) 

DllCall( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,pBitmap ) 
DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,0 ) 

SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap,, ahk_id %Pic1% 
Gui, Show,, Wallpaper by SoggyDog

DllCall( "gdiplus\GdipDisposeImage", UInt,pBitmap ) 
DllCall( "gdiplus\GdiplusShutdown", UInt,pToken ) 
DllCall( NumGet(NumGet(1*pStream)+8 ), UInt,pStream ) 
Return         

GuiClose:
GuiEscape:
 ExitApp
Return

Referencing a Laszlo LIB: :wink:

; See my post in Laszlo's Bit Wizardry
; http://www.autohotkey.com/forum/viewtopic.php?p=135550#135550

FileGetSize, dataSz , %A_AhkPath% 
FileRead   , bin    , %A_AhkPath% 
VarSetCapacity( hex, dataSz*2+1 ) 

hModule   := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) 
hResource := DllCall("FindResource", UInt,hModule, UInt,[color=red]777[/color], UInt,10 )
hResData  := DllCall("LoadResource", UInt,0, UInt,hResource )
Bin2Hex   := DllCall("LockResource", "UInt", hResData ) 

DllCall(Bin2Hex, "uint",&hex, "uint",&bin, "uint",dataSz, "cdecl" ) 
VarSetCapacity( hex, -1 )
MsgBox, %hex%

Dear Mr.Chris, :)

This is my Wish.

I request a change in behaviour of ahk2exe.exe :
Within Windows Explorer, when I select Compile Script from the context menu, if AutoHotkeySC.bin exists on the same folder as the script, then that version should be used for compilation.

This is to facilitate multiple projects that require seperate internal resources.

Thanks. :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Do share, please.


I always do :shock: .. I was compiling the post.
BTW, I have used your wallpaper to demonstrate JPEG referencing.
Hope you do not mind.

:)

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006

I always do :shock: .. I was compiling the post.

I suspected as much...
I just wanted to be a snot and say something before you had a chance to post it. :lol:

BTW, I have used your wallpaper to demonstrate JPEG referencing.
Hope you do not mind.

Of course not... :wink:

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Did you try it ? :)

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006

Did you try it ? :)

I did. Pretty darned nifty!!!

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Pretty darned nifty!!!


Thanks. It would be nice if someone could give us an AutoHotkey ScreenSaver ( with Sound ).

:)

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
How hard would it be to have the wave reference at 667? Triple 6 is the sign of the Devil!.
:shock:

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
What's the matter with 666? It's only refereed to as that if you are a religious fanatic.
Religion is false. >_>

AGU
  • Guests
  • Last active:
  • Joined: --
:arrow: http://www.aymnetwor... ... vilish-616
_________________
Cheers AGU