AutoHotkey Community

It is currently May 26th, 2012, 6:17 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

Would you be interested in the ability to have images embeded in compiled AutoHotkey scripts?
Yes
No
You may select 1 option

View results
Author Message
 Post subject: Re: Can u embed .PNG's
PostPosted: January 13th, 2009, 2:45 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
mb777 wrote:
Can u embed .PNG files like you have shown with bitmaps?
Do I copy the procedure for JPG exactly?


Yes!

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 2:54 am 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
will they lose their transparency?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 3:08 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
If your PNG image shows transparency with
Gui, Add, Picture
then it should be displayed correctly with GDI+

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 13th, 2009, 10:18 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
I have created a dll file using your Rod-Ex program:

http://www.autohotkey.com/forum/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:




Code:
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?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 14th, 2009, 8:36 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
mb777 wrote:
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:

  • To access functions or resources from DLL, The DLL needs to be loaded into memory and an handle to it needs to be obtained.
  • 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.
  • To access the resources of a resource.dll, you need to load the DLL first,
    So we can load it by callling LoadLibrary().
  • 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()
    Code:
    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

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2009, 11:48 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Thanks a lot. It is much clearer now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2009, 10:28 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2009, 10:41 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
mb777 wrote:
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Gay
PostPosted: February 4th, 2009, 5:49 am 
This website is gay you should all go root a dog


Report this post
Top
  
Reply with quote  
PostPosted: February 12th, 2009, 10:47 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Is it possible to Re-Size Embedded Bitmaps (png files)?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2009, 10:57 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
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

Code:
New_hBitmap := DllCall("CopyImage",UInt, Old_hBitmap,UInt,0,Int,640,Int,480, UInt,0)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2009, 12:55 am 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
Thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2009, 4:24 pm 
SKAN wrote:
mb777 wrote:
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 ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 4:42 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
No :(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 8th, 2010, 10:15 pm 
Offline

Joined: January 7th, 2009, 1:08 am
Posts: 66
How would i do this with an Exe???


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 6 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