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
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Can u embed .PNG files like you have shown with bitmaps?
Do I copy the procedure for JPG exactly?


Yes!
kWo4Lk1.png

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
will they lose their transparency?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
If your PNG image shows transparency with
Gui, Add, Picture
then it should be displayed correctly with GDI+
kWo4Lk1.png

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
I have created a dll file using your Rod-Ex program:

http://www.autohotke...topic30228.html

it contains all png files except 9012 which is a jpg

I can not get any of them to display. Here is my code - i created a loop to display all the images so that i knew which was which:




Gui, Margin, 0, 0 
resfile:=A_ScriptDir . "\resource.dll"
rescount:=9000
maxres:=9013
hModule   := DllCall( "GetModuleHandle", Str, resfile ) 
loop
{
	if (rescount>=maxres)
		break
hResource := DllCall("FindResource", UInt,hModule, UInt,rescount, UInt,10)
;msgbox,,, hresource%rescount% : %errorlevel%,.5
nSize     := DllCall("SizeofResource", UInt,hModule, UInt, hResource)
;msgbox,,, nsize : %errorlevel%,.5
hResData  := DllCall("LoadResource", UInt,hModule, UInt,hResource )
;msgbox,,, hresdata : %errorlevel%,.5
Buffer    := DllCall("LockResource", UInt, hResData )
;msgbox,,, buffer : %errorlevel%,.5
; Converting Image data to hBITMAP ; Thanks Sean
; http://www.autohotkey.com/forum/viewtopic.php?t=22999

hData := DllCall("GlobalAlloc", UInt,2, UInt, nSize ) 
;msgbox,,, hdata : %errorlevel%,.5
pData := DllCall("GlobalLock",  UInt,hData ) 
;msgbox,,, pdata : %errorlevel%,.5
DllCall( "RtlMoveMemory", UInt,pData, UInt,Buffer, UInt,nSize ) 
;msgbox,,, rtlmovememory : %errorlevel%,.5
DllCall( "GlobalUnlock", UInt,hData ) 
;msgbox,,, globalunlock : %errorlevel%,.5
DllCall( "ole32\CreateStreamOnHGlobal", UInt,hData, Int,True, UIntP,pStream ) 
;msgbox,,, ole32 : %errorlevel%,.5
DllCall( "LoadLibrary", Str,"gdiplus" )
;msgbox,,, loadlibrary : %errorlevel%,.5
VarSetCapacity(si, 16, 0), si := Chr(1) 
DllCall( "gdiplus\GdiplusStartup", UIntP,pToken, UInt,&si, UInt,0 ) 
;msgbox,,, gdiplusstartup : %errorlevel%,.5

DllCall( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,pBitmap ) 
;msgbox,,, gdipluscreatebitmap : %errorlevel%,.5
DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,0 ) 
;msgbox,,, gdipluscreatebitmapfrombitmap : %errorlevel%,.5
pichandlename:="pic" . rescount
gui,add,text,,%rescount%
Gui, Add, Text, +0xE hWnd%Pichandlename% ; +0xE is SS_BITMAP 
pichandle:=%pichandlename%
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap,, ahk_id %Pichandle% 
msgbox ,,,pichandle:%pichandle%.%pichandlename%.%rescount%,3
rescount++
}
Gui, Show,h600 w1000, SoggyDog
;msgbox pauseing

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

GuiClose:
GuiEscape:
 ExitApp
Return

here is a link to my resource.dll : http://www.mediafire.com/?4zsmv9eyljj

However, when I embed the same images into the exe, they do display, which must mean something is wrong with the dll?

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

However, when I embed the same images into the exe, they do display, which must mean something is wrong with the dll?


Nothing wrong with the DLL!

Replace
hModule := DllCall( "GetModuleHandle", Str, resfile )
with
hModule := DllCall( "LoadLibrary", Str, resfile )

Some info:

[*:37y2psvr]To access functions or resources from DLL, The DLL needs to be loaded into memory and an handle to it needs to be obtained.
[*:37y2psvr]System DLL's like Kernel32.dll are preloaded by Windows and so we need not load the library, just use GetModuleHandle() to obtain a handle to it.
Same goes for Compiled AutoHotkey Script, where you obtain ModuleHandle of the running executable.
[*:37y2psvr]To access the resources of a resource.dll, you need to load the DLL first,
So we can load it by callling LoadLibrary().
[*:37y2psvr]In this particular case of Resource.dll, it does not have a DllMain routine ( which is something like an Auto-Execute section of a DLL ), so we can call LoadLibrary() safely.
But generally speaking, it is best to call LoadLibraryEx() which can load the dll without executing the DllMain()
hModule := DllCall( "LoadLibraryEx", Str,"resource.dll", UInt,0, UInt,0x2 )

On more thing. You are Starting and Shutting down GDI+ on every iteration of loop. Start GDI+ with script and shut-it down on exit.
Refer the following post which shows a better way of handling resource images
Creating a JPEG only DLL and retrieving the images
kWo4Lk1.png

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
Thanks a lot. It is much clearer now.

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
One more thing.

I want to load bitmaps in, but not display them. I want to use them with imagesearch, but would still like them to be in the dll file.

how do I reference them from the dll using image search?

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

I want to load bitmaps in, but not display them....
how do I reference them from the dll using image search?


ImageSearch will not work with GDI bitmap handles..
At the most you can use Icon resources with ImageSearch

Ballzak
  • Guests
  • Last active:
  • Joined: --
This website is gay you should all go root a dog

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
Is it possible to Re-Size Embedded Bitmaps (png files)?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Once you obtain the hbitmap using GDI+, use CopyImage() to copy it to a different size, Delete the old hBitmap, use STM_SETIMAGE with the new hBitmap

New_hBitmap := DllCall("CopyImage",UInt, Old_hBitmap,UInt,0,Int,[color=red]640[/color],Int,[color=red]480[/color], UInt,0)


mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
Thanks

apignard
  • Guests
  • Last active:
  • Joined: --

I want to load bitmaps in, but not display them....
how do I reference them from the dll using image search?


ImageSearch will not work with GDI bitmap handles..
At the most you can use Icon resources with ImageSearch


is there a way to embedded image with imagesearch and compiled version as well ?

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

blondedude092
  • Members
  • 77 posts
  • Last active: Oct 15 2015 04:51 PM
  • Joined: 07 Jan 2009
How would i do this with an Exe???