AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Load Images from .dll

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Obi-Wahn



Joined: 20 Apr 2006
Posts: 29
Location: Vienna

PostPosted: Thu Jan 10, 2008 1:49 pm    Post subject: Load Images from .dll Reply with quote

Hi!

I've searched the Forum, but found only an old THREAD

So, same question, different Guy: Is there a possibillity to load Images from a .dll? I know to load Icons from .dll's and I know to create dll's with images and icons, and I tried to Call the image with the LoadBitmap-Function, but came nowhere...

2nd Question: What about AHK? Are there any plans to add the feature of calling Images from .dll's to use in the GUI's?

Thanks
O-W
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Thu Jan 10, 2008 4:51 pm    Post subject: Reply with quote


Code:
;http://www.autohotkey.com/forum/viewtopic.php?p=148231#148231
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


http://www.autohotkey.com/forum/viewtopic.php?p=148231#148231
The topic should answer your second question.

Smile
Back to top
View user's profile Send private message
Obi-Wahn



Joined: 20 Apr 2006
Posts: 29
Location: Vienna

PostPosted: Fri Jan 11, 2008 9:30 am    Post subject: Reply with quote

Thanks SKAN!
Seems like my search wasn't good enough Embarassed

After I read the Code, I've tried to execute the code with my own images, and after some failure, I got good result.

BUT: The Code looks a little weired and complicated cause of the dllcalls. So I tried to pack it into a Function, but after that, no images were loaded.

This is kinda weired, because I've tried to replace the Values with Variables, and that works.

So while this works:
Code:
X = 0
Y = 0
W = 300
H = 90
Dll = shell32.dll
ID = 14351

;http://www.autohotkey.com/forum/viewtopic.php?p=148231#148231
Gui, -Caption +AlwaysOnTop -Border -ToolWindow
Gui, Margin, 0, 0

Gui, Add, Picture, x%X% y%Y% w%W% h%H% +0xE vMyPic1 hWndPic1 ; +0xE is SS_BITMAP    CHECK
hModule  := DllCall( "LoadLibrary", Str, Dll)    ; CHECK
hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt, ID, UInt
               ,(IMAGE_BITMAP:=0x0), Int,0, Int,0, UInt, (LR_SHARED := 0x8000))      ; CHECK
SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1,, ahk_id %Pic1%
Gui, Show
Return

GuiClose:
GuiEscape:
 ExitApp
Return


This doesn't:
Code:
GAPFromDll(GuiID, X, Y, W, H, Dll, DllID, V, G) {
   global
   Gui, %GuiID%:Add, Picture, x%X% y%Y% w%W% h%H% +0xE v%V% g%G% hWndPic1
   hModule  := DllCall("LoadLibary", Str, Dll)
   hBitmap1 := DllCall( "LoadImageA", UInt,hModule, UInt, ID, UInt
               ,(IMAGE_BITMAP:=0x0), Int,0, Int,0, UInt, (LR_SHARED := 0x8000))      ; CHECK
   SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), hBitmap1, , ahk_id %Pic1%
   Return, "1"
   }

Gui, Margin, 0, 0
Result := GAPFromDll("1", "0", "0", "300", "90", "shell32.dll", "14351", "Test", "")
Gui, Show
Return


And I have no clue why.

So did I mads some mistake, or isn't it possible to store this Commands into a Function?
Or may something have to be changed into the Sendmessage (I've no idea how sendmessage/postmessage works)

Thanks
Obi-Wahn
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Fri Jan 11, 2008 10:54 am    Post subject: Reply with quote

The following is a better way of doing it:

Code:
X = 0
Y = 0
W = 640
H = 480
Dll = shell32.dll
ID = 14351

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

Gui, Add, Picture, x%X% y%Y% w%W% h%H% +0xE vMyPic1 hWndPic1
STM_SetImage( Pic1, LoadImage( ID, DLL, W, H ) )
Gui, Show
Return

LoadImage( Res, DllFile, bmpw=0, bmph=0 ) {
 hModule := DllCall( "LoadLibrary", Str, DllFile )
 hBitmap := DllCall( "LoadImageA", UInt,hModule, UInt, Res, UInt,(IMAGE_BITMAP:=0x0)
                   , UInt,bmpw, UInt,bmph, UInt,(LR_SHARED := 0x8000))
Return hBitmap                 


STM_SetImage( hWnd, hBitmap, flags=0x0 ) {
 SendMessage, 0x172, flags, hBitmap,, ahk_id %hWnd%
Return errorlevel


GuiEscape:
 ExitApp


If you find the nested call - STM_SetImage( Pic1, LoadImage( ID, DLL, W, H ) ) cryptic, you may simplify it:

Code:
hBitmap1 := LoadImage( ID, DLL, W, H )
STM_SetImage( Pic1, hBitmap1 )


Smile
Back to top
View user's profile Send private message
Obi-Wahn



Joined: 20 Apr 2006
Posts: 29
Location: Vienna

PostPosted: Fri Jan 11, 2008 11:42 am    Post subject: Reply with quote

SKAN, I thank you so much. Very Happy Very Happy Very Happy

After watching the Code, I started refining the Code.
FINALLY, I was successful. (My Target was to get only 1 codeline in the gui)

Thank you....


Code:
/*
MANPAGE:
Function: Load Bitmap from DLL
Name: GAPFromDll --> Gui Add Picture From Dll
USAGE: GAPFromDll(<GUIID>, <X>, <Y>, <Width>, <Height>, <DllFile>, <BitmapID>, <Variable>, <G-Label>)
   
   GUIID   ...   For Multiple GUI's, For GUI1: "1", for GUI2: "2", ...
   X      ...   Specify the X-Position in the GUI
   Y      ... Specify the Y-Position in the GUI
   Width   ...   Specify the Width of the Image. The Image will be resized
   Height   ...   Specify the Height of the Image. The Image will be resized
   DllFile   ...   Specify the .dll-File where the Bitmaps are included
   BitmapID...   Specify the ID of the Bitmap you want to show
   Variable...   Specify the Variable-Name for the Image
   G-Label   ... Specify the G-Label-Name for the Image

Special Thanks to SKAN from www.autohotkey.com
http://www.autohotkey.com/forum/viewtopic.php?t=27410
*/

Gui, -Caption +AlwaysOnTop -Border -ToolWindow
Gui, Margin, 0, 0
GAPFromDll("1", "0", "0", "500", "90", "images.dll", "1", "Test", "RunCMD")
GAPFromDll("1", "0", "100", "500", "90", "images.dll", "5", "Test2", "")
Gui, Show
Return

RunCMD:
Run, %comspec%, C:\
Return

GAPFromDll(GuiID, X, Y, W, H, DllFile, DllID, V, G, flags=0x0) {
   global
   Gui, %GuiID%:Add, Picture, x%X% y%Y% w%W% h%H% +0xE v%V% g%G% hWndPic1
   hModule := DllCall( "LoadLibrary", Str, DllFile )
   hBitmap := DllCall( "LoadImageA", UInt, hModule, UInt, DllID, UInt, (IMAGE_BITMAP:=0x0)
                  , UInt, W, UInt, H, UInt, (LR_SHARED := 0x8000))
   SendMessage, 0x172, flags, hBitmap, , ahk_id %Pic1%
   DllCall("FreeLibrary", "UInt", hModule)
   Return, %Errorlevel%
   }

GuiEscape:
GuiClose:
ExitApp
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group