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
ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

What's the matter with 666? It's only refereed to as that if you are a religious fanatic.

:roll:
You gotta lot of growing up to do there slick.

Considering Skan is from India, (and may or may not be aware) I was merely giving him a little bit of information. I am by no means a "religious fanatic". Being a preacher is a business venture just like any other.

It does not bother me personally at all, but I know that Skan spends a considerable amount of time making sure that his posts are not offensive to anyone, and that they are clear and concise. I would not have even noticed had 666 not been they only red colored part of that line.

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
Perhaps he did that just to annoy someone :?:
Lol, j/k but..How is it that I have a lot of growing up to do? I thought I saw in one of your posts that you were also 13 :roll:
Religion is false. >_>

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Nice work Skan :D . Thanks :D

A couple suggestions:[*:opur7q46]It might be a good idea to use if statements or ternary between the GetModuleHandle, FindResource, LoadResource, LockResource, etc... calls in case one of the calls fails[*:opur7q46]After using loading and locking a resource it might be a good idea to call UnlockResource then FreeResource after.

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

I thought I saw in one of your posts that you were also 13

Negative.

geeneeyes
  • Members
  • 66 posts
  • Last active: Jan 26 2012 01:02 PM
  • Joined: 24 May 2006
thanks suresh for this amazing stuff
would love to implement this...

can u explain me the code for including bitmaps.. line by the line :D

comments help me understand.. i would love some...
and please instruct how to include... more bitmaps... any helpful links to dllcall, hmodule, getmodulehandle stuff?
hModule  := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) ; what does this do  :oops: 
hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt,007, UInt,(IMAGE_BITMAP:=0x0), Int,250, Int,250, UInt, (LR_SHARED := 0x8000) )  ; same again and image dimensions have to be hardcoded ??

Gui, Add,Text, x0 y0 w0 h0 hwndPic1 +0xE  ; text or image?? why hwndPic1 ? which style number is this?

SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1,, ahk_id %Pic1%
; mumbo jumbo.. :oops:??[/code]
irc://irc.freenode.net/ahk
Opera: SpeedDial, Email, Extensions, Widgets, Unite, UserJS, Notes, Contacts, IRC, BitTorrent, Download Manager, Tab Stacking, Thumbnails, Sessions, VoiceControl, Mouse Gestures, Content/Flash Blocker, Opera Link, Turbo mode

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
** I was not in town for past two days and hence the late reply **

Considering Skan is from India, (and may or may not be aware) I was merely giving him a little bit of information.


I am well aware of 6 6 6 ( fan of movie Omen - Part 1 thru 3 ), except it did not strike me when I used it. :( I will be sure to avoid it in future.

A couple suggestions:[*:3o654ekl]It might be a good idea to use if statements or ternary between the GetModuleHandle, FindResource, LoadResource, LockResource, etc... calls in case one of the calls fails[*:3o654ekl]After using loading and locking a resource it might be a good idea to call UnlockResource then FreeResource after.


Thanks corrupt. This was a quick and crude attempt. I will try to post a neater one in S&F soon.

can u explain me the code for including bitmaps.. line by the line


Sure .. Allow me sometime. I will post again.

Regards to all. :)

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

can u explain me the code for including bitmaps.. line by the line :D comments help me understand.. i would love some...
and please instruct how to include... more bitmaps... any helpful links to dllcall, hmodule, getmodulehandle stuff?


hModule  := DllCall( "GetModuleHandle", Str, A_ScriptFullPath ) ; what does this do  :oops:


A_ScriptFullpath is the executing file and is already loaded in memory. We need a handle to it so that we can refer the resources stored in it.

In case we need to refer a Bitmap stored in a Dll, we can get a handle to it with a DllCall to LoadLibrary. ( example will follow )

hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt,007, UInt,(IMAGE_BITMAP:=0x0), Int,250, Int,250, UInt, (LR_SHARED := 0x8000) )  ; same again and image dimensions have to be hardcoded ??

If you specify 0 & 0 for X & Y, the original size would be loaded. Most of the time the user would be knowing the dimensions already unless he is writing a Resource Hacker in AHK ( which is possible! )

Gui, Add,Text, x0 y0 w0 h0 hwndPic1 +0xE  ; text or image?? why hwndPic1 ? which style number is this?

Text and Picture both are Static controls except a AHK picture control has the SS_Bitmap ( 0xE ) style. If we wanted to call a picture control we have to specify the picture file name as the third parameter or else the STM_SETIMAGE would not work. Therefore you either provide a dummy picture file as the third parameter or use SS_Bitmap in options of the picture control. I chose to use Text control with SS_Bitmap so that it is prominent enough to be noticed by the users. ( This means you may choose to add an empty picture control with SS_Bitmap in options. )

SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1,, ahk_id %Pic1% ; mumbo jumbo.. :oops:??

Every standard windows control can be controlled with SendMessages and this is one example.
From AHK when you call something like GuiControl,, MyPic, C:\MyPic.BMP to change the contents of a picture control, AHK will be internally using such messages to achieve the task.
These are the message that can be used on a Static Control

.. and here is an example code that calls a bitmap resource from Shell32.dll

:arrow: No need to compile it :

Gui, -Caption +AlwaysOnTop +Border +ToolWindow
Gui, Margin, 0, 0

Gui, Add, Picture, x0 y0 w0 h0 +0xE vMyPic1 hWndPic1 ; +0xE is SS_BITMAP

hModule  := DllCall( "LoadLibrary", Str,"Shell32.dll" )
hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt,14351, UInt,(IMAGE_BITMAP:=0x0)
                    , Int,0, Int,0, UInt, (LR_SHARED := 0x8000) )

SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1,, ahk_id %Pic1%
GuiControlGet, MyPic1, Pos
Gui, Show, w%MyPic1W% h%MyPic1H%
Return

GuiClose:
GuiEscape:
 ExitApp
Return

Shell32.dll loads into the memory when Windows boots-up and yet I call LoadLibrary() only for the sake of a module handle.
I have not hardcoded the dimensions but have to ascertain the picture control's size to fit the GUI.

Any more? :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
@GeeNeeYes: Sorry Pramod!. I just saw your scrap in Orkut. I was bugged with a stupid prank by a sick kid and could not access it. You have my email! Do not you? Please e-mail / PM when urgent.

Regards, :)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
I just glanced the post, but I am wondering why so much talk about it, and what is the wish here ?

Any resoure can be added to any exe file (so, even your compiled script) with resoruce editors, after API resource functions can be used to load them in the memory.

This has nothing to do with AHK itself, nor requires changes in its code to support it.

There is even dll component on ASM forum for resource manipulation so you could create script that adds your resources into the compiled script after compilation.
Posted Image

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

what is the wish here ?


To have built-in commands to refer built-in resources.

:)

Mustang
  • Members
  • 421 posts
  • Last active: Dec 26 2010 10:08 PM
  • Joined: 17 May 2007
Very useful Skan
Any chance of an example that references an embedded executable
e.g. Normally I'd use RunWait but is there a way to include it as a resource?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Technically any binary content can be stored as a resource, but I am yet to try in with a Win32 PE.

See : Laszlo's Machine code functions: Bit Wizardry

:)

Mustang
  • Members
  • 421 posts
  • Last active: Dec 26 2010 10:08 PM
  • Joined: 17 May 2007
Say for example say I would like to embed notepad.exe
Then from my script call this executable with a filename passed as a parameter for it to open

e.g.
Normal AHK code would be:
Run, notepad.exe somefile.txt

I'm a little stuck how this might be achieved

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
I think that cannot be done. :roll:

mb777
  • Members
  • 42 posts
  • Last active: Feb 25 2009 07:06 PM
  • Joined: 08 Jan 2009
Can u embed .PNG files like you have shown with bitmaps?
Do I copy the procedure for JPG exactly?

I have some button images 32x32. I tried converting them to icons, then adding to resource, but they lost their transparency gradient on the shadow.

I also tried as bitmaps .bmp, but they lost the transparency again.

Will they keep transparency this way?
If not, is there any other way?