AutoHotkey Community

It is currently May 27th, 2012, 12:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 111 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next
Author Message
 Post subject:
PostPosted: July 11th, 2010, 9:13 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
WankaUSR wrote:
is it possible to use an image storred in memory from skan's AxC_UnPackToMem??
Here is a starting point:
Code:
IfNotExist, png.axc
 UrlDownloadToFile,http://arian.suresh.googlepages.com/png.axc, png.axc
 
Gui, +LastFound
GUI1:=WinExist(), hDC:=DllCall("GetDC",UInt,Gui1)

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

FileReadEx( IMG, "png.axc", 32016,95488 )
hBitmap := gdiBitmap( IMG, 32016, wxh )
sb1 := "0." . hBitmap  ; add "0." for a bitmap or "1." for an icon

AddGraphicButton("SampleButton1", sb1, "h144 w144 gMyButton")

; Gui, Add, Text, w128 h128 hwndPNG1 0xE
; SendMessage, (STM_SETIMAGE:=0x172), (IMAGE_BITMAP:=0x0), %hBitmap%,, ahk_id %PNG1%
Gui, Show

; stop GDI+  -----------------------------------------------------------------------------
   DllCall( "gdiplus\GdiplusShutdown", UInt,pToken )
   DllCall( NumGet(NumGet(1*pStream)+8 ), UInt,pStream )
; ----------------------------------------------------------------------------------------

Return

GuiClose:
 ExitApp
Return

MyButton:
MsgBox, Graphic button clicked :)
return

gdiBitmap( byref buffer, nsize, byref wxh ) {
; Sean : http://www.autohotkey.com/forum/viewtopic.php?p=147029#147029
  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( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,pBitmap )
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,8 )
  DllCall("gdiplus\GdipGetImageWidth" , "Uint", pBitmap, "UintP", nW)
  DllCall("gdiplus\GdipGetImageHeight", "Uint", pBitmap, "UintP", nH), wxh := nW "x" nH
  DllCall( "gdiplus\GdipDisposeImage", UInt,pBitmap )
return hbitmap
}

FileReadEx( ByRef V,F,B,O ) {
return varsetcapacity(v,b,0)-o+(h:=dllcall("_lopen",str,f,int,0))-h+dllcall("_llseek",uint
 ,h,uint,o,int,0)-dllcall("_lread",uint,h,str,v,int,b)+dllcall("_lclose",uint,h) ? -1 : &v     
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Graphic Buttons
PostPosted: July 12th, 2010, 12:42 pm 
Offline

Joined: June 29th, 2010, 1:01 pm
Posts: 123
corrupt wrote:
Here's a generic function that can be used to add graphic buttons to AutoHotkey GUI scripts that should offer a bit of flexibility. Enjoy :)

Image

Download version 2.2 (sample scripts, functions)
Download custom dll (Includes a function for extracting images in the dll - Use ResHacker to add images - type: RCDATA)

Updated to version 2.2

  • compatible with previous release (2.1)
  • added support for image types: .bmp, .gif, .jpg, .wmf, .emf, .ico when loaded from a custom dll file
  • added a download for the custom dll file that contains a function for retrieving images stored in the dll
  • added option to resize icons using custom dll method
  • added AGB.ahk file - containing optional functions for loading images for use with the AddGraphicButton function
  • added the ability to change images without having to load from source each time (specify image HWND)
  • added a second demo script
version 2.1
  • simplified usage
  • image types currently supported: .bmp, .ico
  • added the ability to change images
  • added image rollover example for SampleButton1 in the demo script
  • sample images will be downloaded by the script if not found in the Working directory

Download previous version (2.1) working sample script (images included)



is download version 2.2 still current or do I have to replace sections with code from this thread?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Graphic Buttons
PostPosted: July 12th, 2010, 12:52 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
jleslie48 wrote:
is download version 2.2 still current or do I have to replace sections with code from this thread?
Version 2.2 is still current but may be updated in the near future :) .


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Graphic Buttons
PostPosted: July 12th, 2010, 1:28 pm 
Offline

Joined: June 29th, 2010, 1:01 pm
Posts: 123
corrupt wrote:
jleslie48 wrote:
is download version 2.2 still current or do I have to replace sections with code from this thread?
Version 2.2 is still current but may be updated in the near future :) .


That's fine. I just wasnt' sure if all the code from the past 7 pages of comments were included in the download.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Graphic Buttons
PostPosted: July 12th, 2010, 2:16 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
jleslie48 wrote:
That's fine. I just wasnt' sure if all the code from the past 7 pages of comments were included in the download.
Not necessarily... but the version in the first post is the current/last version that I have posted ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2010, 2:27 pm 
Offline

Joined: June 29th, 2010, 1:01 pm
Posts: 123
Thanks again.


Ok I'm getting a dumb error when I try and run the package.

I've started a new thread on it as I'm sure its just something stupid I'm doing with dll's and lots of beginners will run into it:

http://www.autohotkey.com/forum/viewtop ... highlight=


the skinny is I get an exception error: Error Call to nonexistent function

when I run. I tried to search for this error and a simple explanation, but I can't find it.

TIA,

Jleslie48


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2010, 2:50 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Asking once is enough

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 1:23 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
jleslie48 wrote:
the skinny is I get an exception error: Error Call to nonexistent function
Thanks for the report. If you get this error when running the test_AGB34.ahk script please add the following line to the end of the test_AGB34.ahk script:
Code:
#Include AGB.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 1:27 am 
Offline

Joined: June 29th, 2010, 1:01 pm
Posts: 123
corrupt wrote:
jleslie48 wrote:
the skinny is I get an exception error: Error Call to nonexistent function
Thanks for the report. If you get this error when running the test_AGB34.ahk script please add the following line to the end of the test_AGB34.ahk script:
Code:
#Include AGB.ahk


Most welcome. And thank you for some very elegant programming and adding to this community. The more I explore AHK, the more I like.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 10:36 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
updated test script in attempt to retain image transparency with png file loaded from AxC
Code:
; --------------------------------------------
; modified version of script posted by SKAN
; http://www.autohotkey.com/forum/viewtopic.php?t=29593&postdays=0&postorder=asc&highlight=axcunpacktomem&start=21
; --------------------------------------------

IfNotExist, png.axc
 UrlDownloadToFile,http://arian.suresh.googlepages.com/png.axc, png.axc
 
Gui, +LastFound
GUI1:=WinExist(), hDC:=DllCall("GetDC",UInt,Gui1)

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

FileReadEx( IMG, "png.axc", 32016,95488 )
hBitmap := AGB_gdiBitmap( IMG, 32016, wxh )
AddGraphicButton("SampleButton1", hBitmap, "h144 w144 gMyButton")
Gui, Show

; stop GDI+  -----------------------------------------------------------------------------
   DllCall( "gdiplus\GdiplusShutdown", UInt,pToken )
   DllCall( NumGet(NumGet(1*pStream)+8 ), UInt,pStream )
; ----------------------------------------------------------------------------------------

Return

GuiClose:
 ExitApp
Return

MyButton:
MsgBox, Graphic button clicked :)
return

AGB_gdiBitmap( byref buffer, nsize, byref wxh ) {
; Sean : http://www.autohotkey.com/forum/viewtopic.php?p=147029#147029
; modified by corrupt - image transparency when using with button controls in AHK
  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( "gdiplus\GdipCreateBitmapFromStream", UInt,pStream, UIntP,pBitmap )
  bkcol := DllCall( "user32\GetSysColor", Unt, (COLOR_BTNFACE := 15))
  AA_FormatInteger=%A_FormatInteger%
  SetFormat Integer, H
  bkcol := bkcol + 0
  SetFormat Integer, %AA_FormatInteger%
  Loop % (8-StrLen(bkcol))
    bkcol:="0x0" . SubStr(bkcol, (StrLen(bkcol)-A_Index-2))
  bkcol := "0xFF" . SubStr(bkcol, 7, 2) . SubStr(bkcol, 5, 2) . SubStr(bkcol, 3, 2)
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt, pBitmap, UIntP, hBitmap, UInt, bkcol)
  DllCall("gdiplus\GdipGetImageWidth" , "Uint", pBitmap, "UintP", nW)
  DllCall("gdiplus\GdipGetImageHeight", "Uint", pBitmap, "UintP", nH), wxh := nW "x" nH
  DllCall( "gdiplus\GdipDisposeImage", UInt,pBitmap )
return "0." . hbitmap
}

FileReadEx( ByRef V,F,B,O ) {
return varsetcapacity(v,b,0)-o+(h:=dllcall("_lopen",str,f,int,0))-h+dllcall("_llseek",uint
 ,h,uint,o,int,0)-dllcall("_lread",uint,h,str,v,int,b)+dllcall("_lclose",uint,h) ? -1 : &v     
}



; *******************************************************************
; AddGraphicButton.ahk
; *******************************************************************
; Version: 2.2 Updated: May 20, 2007
; by corrupt
; *******************************************************************
; VariableName = variable name for the button
; ImgPath = Path to the image to be displayed
; Options = AutoHotkey button options (g label, button size, etc...)
; bHeight = Image height (default = 32)
; bWidth = Image width (default = 32)
; *******************************************************************
; note:
; - calling the function again with the same variable name will
; modify the image on the button
; *******************************************************************
AddGraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32){
Global
Local ImgType, ImgType1, ImgPath0, ImgPath1, ImgPath2, hwndmode
; BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
Static LR_LOADFROMFILE := 16
Static BM_SETIMAGE := 247
Static NULL
SplitPath, ImgPath,,, ImgType1
If ImgPath is float
{
  ImgType1 := (SubStr(ImgPath, 1, 1)  = "0") ? "bmp" : "ico"
  StringSplit, ImgPath, ImgPath,`.
  %VariableName%_img := ImgPath2
  hwndmode := true
}
ImgTYpe := (ImgType1 = "bmp") ? 128 : 64
If (%VariableName%_img != "") AND !(hwndmode)
  DllCall("DeleteObject", "UInt", %VariableName%_img)
If (%VariableName%_hwnd = "")
{
  Gui, Add, Button,  v%VariableName% hwnd%VariableName%_hwnd +%ImgTYpe% %Options%
  bDC := DllCall("user32\GetDC", UInt,%VariableName%_hwnd)
  DllCall( "gdi32\SetBkMode", UInt,bDC, UInt,1)
}
ImgType := (ImgType1 = "bmp") ? 0 : 1
If !(hwndmode)
  %VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", ImgType,  "UInt", %VariableName%_img)
Return %VariableName%_img ; Return the handle to the image
}
Seems to test ok on XP Pro SP3. Any feedback (works/doesn't work) would be appreciated if anyone has a chance to try it out :)

Edit: bug found/fixed - ABGR Hex wasn't padded


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 2:07 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Works just fine for me (Win98SE with updates). 8) Thank you!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 3:05 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear corrupt, :)

The is a typo in the following block of code:

Code:
  bkcol := DllCall( "user32\GetSysColor", UInt, (COLOR_BTNFACE := 15))
  AA_FormatInteger=%A_FormatInteger%
  SetFormat Integer, H
  bkcol := bkcol + 0
  SetFormat Integer, %AA_FormatInteger%
  Loop % (8-StrLen(bkcol))
    bkcol:="0x0" . SubStr(bkcol, (StrLen(bkcol)-A_Index-2))
  bkcol := "0xFF" . SubStr(bkcol, 7, 2) . SubStr(bkcol, 5, 2) . SubStr(bkcol, 3, 2)
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt, pBitmap, UIntP, hBitmap, UInt, bkcol)


and the above can be simplified to:

Code:
  bkcol := DllCall( "user32\GetSysColor", UInt,( COLOR_BTNFACE := 15 ) )
  bkcol := DllCall( "Ws2_32\ntohl", UInt,(bkcol<<8) ) | 0xFF000000
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,bkcol )


or

Code:
  bkcol := DllCall( "user32\GetSysColor", UInt,( COLOR_BTNFACE := 15 ) )
  bkcol := ( (( bkcol & 0xFF) << 16 ) | ( bkcol & 0xFF00 ) | ( ( bkcol & 0xFF0000 ) >> 16 ) )
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,bkcol | 0xFF000000 )



Regards :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2010, 4:07 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
Drugwash wrote:
Works just fine for me (Win98SE with updates). 8) Thank you!
Thanks for testing :) . Do you have a link handy for unofficial Win98SE updates?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2010, 4:14 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
SKAN wrote:
Dear corrupt, :)

The is a typo in the following block of code:
...

SKAN wrote:
and the above can be simplified to:

Code:
  bkcol := DllCall( "user32\GetSysColor", UInt,( COLOR_BTNFACE := 15 ) )
  bkcol := DllCall( "Ws2_32\ntohl", UInt,(bkcol<<8) ) | 0xFF000000
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,bkcol )


or

Code:
  bkcol := DllCall( "user32\GetSysColor", UInt,( COLOR_BTNFACE := 15 ) )
  bkcol := ( (( bkcol & 0xFF) << 16 ) | ( bkcol & 0xFF00 ) | ( ( bkcol & 0xFF0000 ) >> 16 ) )
  DllCall( "gdiplus\GdipCreateHBITMAPFromBitmap", UInt,pBitmap, UIntP,hBitmap, UInt,bkcol | 0xFF000000 )



Regards :)

Thanks for having a look and for the code 8) .


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 15th, 2010, 6:53 am 
Offline

Joined: November 11th, 2005, 3:13 am
Posts: 202
corrupt wrote:
Thanks :) . I haven't been around or updated many scripts lately... It's possible to show tooltips with the current code. Here's an example:
Code:
; ********************************
; Demo Script
; ********************************

; Load an icon instead for SampleButton2
AGB_LoadIconDll(sb1, "shell32.dll", 166)

; Create the buttons
AddGraphicButton("SampleButton1", sb1, "h36 w36 gMyButton")

; Show the window
Gui, Show, , Bitmap Buttons

; Image rollover for SampleButton1
 OnMessage(0x200, "MouseMove")
 OnMessage(0x2A3, "MouseLeave")
 OnMessage(0x202, "MouseLeave") ; Restore image on LBUTTONUP
Return

MouseLeave(wParam, lParam, msg, hwnd)
{
  Global
  If (hwnd = SampleButton1_hwnd)
    ToolTip
  Return
}
MouseMove(wParam, lParam, msg, hwnd)
{
  Global
  Static _LastButtonData1 = true

  If (hwnd = SampleButton1_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Timed ToolTip`nThis will be displayed for 5 seconds.
      SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd

  Return
}

MyButton:
MsgBox, Graphic button clicked :)
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

GuiClose:
ExitApp


; from the library file AGB.ahk (included in the zip file in the download)

; *******************************************************************
; Preload icons from a dll for use with the AddGraphicButton() function
; Version: 2.21 Updated: June 22, 2008
; by corrupt
; *******************************************************************
; VariableName = variable name for the loaded image resource
; dllfile = Path to the dll file that contains the image(s)
; nindex = the index of the icon to load
; *******************************************************************
AGB_LoadIconDll(ByRef VariableName, dllfile, nindex) {
Global
Local spid
spid := DllCall("GetCurrentProcessId")
If (%VariableName%_img != "")
  DllCall("DeleteObject", "UInt", %VariableName%_img)
VariableName := "1." . DllCall("shell32.dll\ExtractIconA", "UInt", spid, "Str", dllfile, "UInt", nindex)
Return ErrorLevel
}


Thanks for the code, it works well.. however for multiple buttons, can you help me to understand a bit? this is the code i'm referring to.

Code:
...
  If (hwnd = SampleButton1_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Timed ToolTip`nThis will be displayed for 5 seconds.
      SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd

  If (hwnd = SampleButton2_hwnd)
    If (_LastButtonData1 != SampleButton1_hwnd)
      ToolTip, Timed ToolTip`nThis will be displayed for 5 seconds.
      SetTimer, RemoveToolTip, 5000
  _LastButtonData1 := hwnd


...


even for SampleButton2, why is the _LastButtonData1 is still SampleButton1_hwnd.

thanks again..


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 111 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, SKAN and 5 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