Code: Select all
;@A.DEGARDIN 2018, TagIE.ahk : simplify IE Automation functions
;https://github.com/adegard/TagIE.ahk
;References:
;Simple editor:https://autohotkey.com/board/topic/81302-text-editor-example-from-docs/
;Some mods by burque505 - 11/28/2018 (element highlighting, click anywhere on line
;before entering next tag. SEE NOTE BELOW WITH CAVEATS FOR "tnavc" tag entry!
;*****************************************************
#SingleInstance, Force
#NoEnv
CurrentVersion := "1.1.04"
;Update(CurrentVersion)
Menu, tray, icon, %A_WinDir%\system32\SHELL32.dll, 138
; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, &New (Ctrl+N), FileNew
Menu, FileMenu, Add, &Open (Ctrl+O), FileOpen
Menu, FileMenu, Add, &Save (Ctrl+S), FileSave
Menu, FileMenu, Add, Save &As, FileSaveAs
Menu, FileMenu, Add ; Separator line.
Menu, FileMenu, Add, E&xit, FileExit
Menu, HelpMenu, Add, &About, HelpAbout
Menu, HelpMenu, Add, &Check Updates, Update
Menu, ToolsMenu, Add, &IE_Selector, Selector
Menu, ToolsMenu, Add, &IE_Selector_x64, Selector64
Menu, ToolsMenu, Add, &IE_iWB2_Learner, IWB2
Menu, ToolsMenu, Add, &Web Scraping Writer by Joe Glines, WriterJG
Menu, ToolsMenu, Add, &Scheduler, Schedule
;Menu, ToolsMenu, Add, &Ini Parameters Creator, INI_creator
Menu, ProStepsMenu, Add, &LoopForItems, LoopForItems
Menu, ProStepsMenu, Add, &Parsing HTML, HTMLparsing
Menu, ProStepsMenu, Add, &File Database, FileDB
Menu, ProStepsMenu, Add, &Send Yourself Telegram, TelegramMsg
Menu, ProStepsMenu, Add, &Extract table to CSV, table2csv
Menu, ShareMenu, Add, &Find TagIE Gist, FindGist
Menu, ShareMenu, Add, &Share your Scripts (mention TagIE), PostGist
Menu, ShareMenu, Add, &News Subscribe (RSS feed), Subscribe
; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &ProSteps, :ProStepsMenu
Menu, MyMenuBar, Add, &Tools, :ToolsMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu
Menu, MyMenuBar, Add, &TagIE Scripts Online, :ShareMenu
; Attach the menu bar to the window:
Gui, Menu, MyMenuBar
; Create the main Edit control and display the window:
Gui, +Resize ; Make the window resizable.
;----------Start of GroupBox one----------;
Gui Add, GroupBox, x8 y0 w105 h185, IE Browsing
;Gui Font, s20, Symbola
Gui Add, Button, vtnav x16 y16 w42 h36 section gtnav hwndtnav
GuiButtonIcon(tnav, "shell32.dll", 243, "s32 a4")
Gui Add, Button, vtclick xs w42 h36 gtclick hwndtclick
GuiButtonIcon(tclick, "shell32.dll", 100, "s32 a4")
Gui Add, Button, vtsnap xs w42 h36 gtsnap hwndtsnap
GuiButtonIcon(tsnap, "shell32.dll", 118, "s32 a4")
Gui Add, Button, vtscroll xs w42 h36 gtscroll hwndtscroll
GuiButtonIcon(tscroll, "shell32.dll", 249, "s32 a4")
Gui Add, Button, vtecho ys w42 h36 gtecho hwndtecho
GuiButtonIcon(techo, "shell32.dll", 173, "s32 a4")
Gui Add, Button, vtread w42 h36 gtread hwndtread
GuiButtonIcon(tread, "shell32.dll", 29, "s32 a4")
Gui Add, Button, vtenter w42 h36 gtenter hwndtenter
GuiButtonIcon(tenter, "shell32.dll", 134, "s32 a4")
Gui Add, Button, vtselect w42 h36 gtselect hwndtselect
GuiButtonIcon(tselect, "shell32.dll", 248, "s32 a4")
;----------End of GroupBox one----------;
Gui Add, GroupBox, x8 w105, Visual Click
Gui Add, Button, vfindclick x16 y205 w42 h36 gfindclick hwndfindclick
GuiButtonIcon(findclick, "shell32.dll", 98, "s32 a4")
;----------End of GroupBox two----------;
Gui Add, GroupBox, x8 r4 w105, Chrome Browsing
;-------------------------------------------------------; LOOK HERE!
;Gui Add, Button, vtnavc x16 y270 w42 h36 section r2 gtnavc, G
;Above works, if you screw up.
;GuiButtonIcon(tnavc, "G.ico", 1,"s32 a4")
;Gui Add, Button, vtnavc x16 y270 w42 h36 section r2 gtnavc
AddGraphicButton("tnavc", "icons\Chrome.ico", "x16 y270 h36 w42 gtnavc section", 42, 36)
;PICTURE
Gui Add, Button, vchromeclick x64 ys w42 h36 gchromeclick hwndchromeclick
GuiButtonIcon(chromeclick, "shell32.dll", 101, "s32 a4")
Gui Add, Button, vchromewait xs w42 h36 gchromewait hwndchromewait
GuiButtonIcon(chromewait, "shell32.dll", 21, "s32 a4")
;----------End of GroupBox three----------;
;Add a group box just below with y+10
Gui Add, GroupBox, x8 r4 w105, Tags/Image Finder
Gui Add, Button, vieselector x16 y370 w42 h36 section gSelector hwndieselector
GuiButtonIcon(ieselector, "shell32.dll", 56, "s32 a4")
; "ys" to start a new column in the section defined above
Gui Add, Button, vcropimage x64 ys w42 h36 gcropimage hwndcropimage
GuiButtonIcon(cropimage, "shell32.dll", 116, "s32 a4")
; Put the last button down on the left last here so next
; group box won't be misplaced
AddGraphicButton("iWB2", "icons\iWB2.ico", "xs h36 w42 gIWB2", 42, 36)
;Gui Add, Button, viwb2 xs w42 h36 gIWB2 hwndIWB2
;GuiButtonIcon(IWB2, "shell32.dll", 210, "s32 a4")
;----------End of GroupBox four----------;
Gui Add, GroupBox, x8 w105 h58, Run Now/Later
Gui Add, Button, vExecute x16 y475 w42 h36 section gExecute hwndExecute
GuiButtonIcon(Execute, "shell32.dll", 138, "s32 a4")
Gui Add, Button, vSchedule x64 ys w42 h36 gSchedule hwndSchedule
GuiButtonIcon(Schedule, "shell32.dll", 240, "s32 a4")
tnav_TT := "tnav: Navigate to a webpage"
techo_TT := "techo: return message, variable in log"
tclick_TT := "tclick: Click on Tag / Selector / Text"
tread_TT := "tread: fetch/read element text to variable"
tsnap_TT := "tsnap: take snapshot and save it in jpg "
tenter_TT := "tenter: Enter value in Tag field"
tscroll_TT := "tscroll: Scroll page to element"
tselect_TT := "tselect: SelectDropdown value"
ieselector_TT := "IE_selector: Selector finder (IE x32)"
iwb2_TT := "iWB2: Tags finder (IE)"
Execute_TT := "Execute (F9) (save before executing)"
Schedule_TT := "Schedule for later (save before scheduling)"
cropimage_TT := "Create image for FindClick"
findclick_TT := "FindClick: Choose an image file to click (saved beforehand)"
chromeclick_TT := "ChromeClick: Search & Click on text (only for Chrome)"
chromewait_TT := "ChromeWait: Search a text, wait and click...(only for Chrome)"
tnavc_TT := "tnavc: Open a Chrome webpage.`nCaution! Move cursor to end of block` or out of block`nbefore entering new tag!"
;Edit pannel
Gui, Add, Edit, vMainEdit WantTab x120 y8 w428 h515 +Multi ;W600 R20
GuiControl,, MainEdit, #include TagIE.ahk `
Gui, Show,, Untitled
WinGetPos,,, Width, Height, Untitled
WinMove, Untitled,, (A_ScreenWidth)-(Width) ;, (A_ScreenHeight)-(Height)
OnMessage(0x200, "WM_MOUSEMOVE")
CurrentFileName = ; Indicate that there is no current file.
return
64Bit() {
Return (FileExist("C:\Program Files (x86)")) ? 1 : 0
}
WM_MOUSEMOVE()
{
static CurrControl, PrevControl, _TT ; _TT is kept blank for use by the ToolTip command below.
CurrControl := A_GuiControl
if (CurrControl <> PrevControl and not InStr(CurrControl, " "))
{
ToolTip ; Turn off any previous tooltip.
SetTimer, DisplayToolTip, 100
PrevControl := CurrControl
}
return
DisplayToolTip:
SetTimer, DisplayToolTip, Off
ToolTip % %CurrControl%_TT ; The leading percent sign tell it to use an expression.
SetTimer, RemoveToolTip, 3000
return
RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return
}
LoopForItems:
;Store:=ClipboardAll ;****Store clipboard ****
Func=
( Join`r`n
; result page where the script clicks on items one by one ; text change
tnav("https://www.kijiji.it/offerte-di-lavoro/offerta/badante/?entryPoint=sb","")
loop, 3 ;how many items
{
/*extract selector and replace by A_Index number to increment:*/
;in this Example :
;item1: body > div:nth-of-type(4) > div:nth-of-type(2) > div:nth-of-type(1) > ul > li:nth-of-type(1) > div > h3 > a
;item2: body > div:nth-of-type(4) > div:nth-of-type(2) > div:nth-of-type(1) > ul > li:nth-of-type(2) > div > h3 > a
;WARNING: change '§' into 'Percent symbol' in the following line before use:
selector = body > div:nth-of-type(4) > div:nth-of-type(2) > div:nth-of-type(1) > ul > li:nth-of-type(§A_Index§) > div > h3 > a
tclick(selector)
tsnap()
sleep, 1000
;return on result page
tnav("https://www.kijiji.it/offerte-di-lavoro/offerta/badante/?entryPoint=sb","")
}
)
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n%Func%
return
PostGist:
GuiControlGet, clipboard,, MainEdit
run, https://gist.github.com/
return
FindGist:
;GuiControlGet, sCurrentText,, MainEdit
run, %A_ScriptDir%\examples\Gist\Gist_script_box.ahk ;https://gist.github.com/search?q=TagIE
return
Subscribe:
;GuiControlGet, sCurrentText,, MainEdit
run, https://feedburner.google.com/fb/a/mailverify?uri=LastTagIEScripts&loc=en_US
return
Update:
Update(CurrentVersion)
return
Update(CurrentVersion)
{
/*
FileDelete, version.txt
UrlDownloadToFile,https://raw.githubusercontent.com/adegard/TagIE.ahk/master/version.txt, version.txt
FileRead, version, version.txt
*/
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://raw.githubusercontent.com/adegard/TagIE.ahk/master/version.txt", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
version := whr.ResponseText
if (version=CurrentVersion)
{
MsgBox,, TagIE version %version%, You have the latest version ; changed 'last' to 'latest
}
else
{
MsgBox,, TagIE %CurrentVersion%, A newer version is available: %version% at https://github.com/adegard/TagIE.ahk
; Added colon
;run, https://github.com/adegard/TagIE.ahk
}
}
f9::
goto Execute
cropimage:
run, %A_ScriptDir%\tools\FindClick_creator.ahk
return
Execute:
run, %CurrentFileName%
return
Selector64:
run, %A_ScriptDir%\tools\IE_selector_x64.exe
return
Selector:
if (64Bit()=1)
{
run, %A_ScriptDir%\tools\IE_selector_x64.exe
}
else
{
run, %A_ScriptDir%\tools\IE_selector.exe
}
return
IWB2:
run, %A_ScriptDir%\tools\iWB2_Learner.exe
;run, %A_ScriptDir%\tools\iWB2_Learner_Zoom3.2_b505_4.ahk
return
WriterJG:
run, %A_ScriptDir%\tools\Web-Scraping-AutoHotkey-Writer1.05.ahk
MsgBox, Use Ctrl+Left Click to open Menu
return
INI_creator:
run, %A_ScriptDir%\tools\INI_creator.ahk
return
Schedule:
run, %A_ScriptDir%\tools\AHK-Tasks-scheduler-v1.ahk
return
findclick:
FileSelectFile, SelectedFileName, 3,, Open File ;, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n;Choose an image file to click `nFindClick("%SelectedFileName%")
return
chromeclick:
GuiControlGet, sCurrentText,, MainEdit
;GuiControl,, MainEdit, %sCurrentText% `n;Search text & Click on it `nChromeClick("text to click")
ControlFocus, Edit1
Send, {End}`n; Search for text & Click on it `nChromeClick("text to click"){Left 15}{Shift Down}{Right 13}{Shift Up}
return
chromewait:
GuiControlGet, sCurrentText,, MainEdit
;GuiControl,, MainEdit, %sCurrentText% `n;Search text, Wait & Click `nChromeWait("Wait for this text")
ControlFocus, Edit1
Send, {End}`n; Search for text, Wait & Click `nChromeWait("Wait for this text"){Left 20}{Shift Down}{Right 18}{Shift Up}
return
tnav:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntnav("https://www.google.com/",""){Left 20}{Shift Down}{Right 14}{Shift Up}
return
tnavc:
;NOTE: After you enter this tag,
;you'll have to move the cursor
;either to the last line of the block
;or somewhere outside it.
Func=
( Join`r`n
Run, chrome.exe https://www.google.com, , Max
#IfWinActive ahk_class Chrome_WidgetWin_1
StatusBarWait, Done, , , ;%this_title%
Gui Show, minimize, Log
)
GuiControlGet, sCurrentText,, MainEdit
;GuiControl,, MainEdit, %sCurrentText% `n%Func%
ControlFocus, Edit1
Send, {End}{Text}`n%Func%
Send, {Up 3}{End}{Left 21}{Shift Down}{Right 14}{Shift Up}
return
table2csv:
Func=
( Join`r`n
url := ""
tnav(url,"")
tscroll("table")
table2csv("testcsv-tagIE.csv")
)
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n%Func%
return
techo:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntecho("text"){Left 6}{Shift Down}{Right 4}{Shift Up}
return
tclick:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntclick("ele"){Left 5}{Shift Down}{Right 3}{Shift Up}
return
tread:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntread("ele"){Left 5}{Shift Down}{Right 3}{Shift Up}
return
tsnap:
GuiControlGet, sCurrentText,, MainEdit
;GuiControl,, MainEdit, %sCurrentText% `ntsnap()
ControlFocus, Edit1
Send, {End}`ntsnap()
return
tenter:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntenter("ele"){Left 5}{Shift Down}{Right 3}{Shift Up}
return
tscroll:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntscroll("ele"){Left 5}{Shift Down}{Right 3}{Shift Up}
return
tselect:
GuiControlGet, sCurrentText,, MainEdit
ControlFocus, Edit1
Send, {End}`ntselect("ele", "value"){Left 14}{Shift Down}{Right 3}{Shift Up}
return
TelegramMsg:
Func=
( Join`r`n
Telegram_MsgBox(0,a,"text","your_TelegramBotToken","your_TelegramBotChatID")
;NOTE: first time use, you need to retrive Token&ID. Invoke this:
;Telegram_MsgBox(0,a,"this is a test","","")
;see options by Spur: https://autohotkey.com/boards/viewtopic.php?f=6&t=24919
)
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n%Func%
return
HTMLparsing:
Func=
( Join`r`n
UrlDownloadToFile, http://feeds.feedburner.com/LastTagIEScripts, ahkrss.xml
FileRead, xml, ahkrss.xml
While Item := StrX( xml , "<item>" ,N,0, "</item>" ,1,0, N )
{
Title := StrX( Item, "<title>",1,7, "</title>",1,8 )
Link := StrX( Item, "<link>" ,1,6, "</link>" ,1,7 )
List .= A_Index ") `t" Title "`t" Link "`n"
}
/*
StrX(Source Text, BeginStr,BeginOffset,BeginTrim, EndStr,EndOffset,EndTrim, NextOffset )
See: https://autohotkey.com/board/topic/47368-strx-auto-parser-for-xml-html/
*/
)
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n%func%
return
FileDB:
Func=
( Join`r`n
;use this script to check if you already append stuff in a local file. And if not, append it.
;WARNIG: Substitute $ by Percentual symbol and Substitute ' by backticks symbol
dbFileName= mylocalDB.txt
;check if Database fie exist ok, if not, create it
ifnotexist,%dbFileName%
{
TestString := "This is item list.'r'n"
Fileappend,$TestString$'r'n,$dbFileName$
}
***DOING STUFF YOU WANT TO STORE***
stuff=test
FileRead, OutputVar, $dbFileName$
IfInString, OutputVar , $stuff$
{
;This stuff already exist in database
}
else
{
FileAppend, $stuff$'n, $dbFileName$
}
)
GuiControlGet, sCurrentText,, MainEdit
GuiControl,, MainEdit, %sCurrentText% `n%func%
return
FileNew:
GuiControl,, MainEdit ; Clear the Edit control.
Gui, Show,, Untitled
CurrentFileName = ; Indicate that there is no current file.
GuiControl,, MainEdit, #include TagIE.ahk
return
FileOpen:
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File ;, Text Documents (*.txt)
if SelectedFileName = ; No file selected.
return
Gosub FileRead
return
FileRead: ; Caller has set the variable SelectedFileName for us.
FileRead, MainEdit, %SelectedFileName% ; Read the file's contents into the variable.
if ErrorLevel
{
MsgBox Could not open "%SelectedFileName%".
return
}
GuiControl,, MainEdit, %MainEdit% ; Put the text into the control.
CurrentFileName = %SelectedFileName%
Gui, Show,, %CurrentFileName% ; Show file name in title bar.
return
^N::
Goto FileNew
return
^O::
Goto FileOpen
return
^S::
Goto FileSave
return
FileSave:
if CurrentFileName = ; No filename selected yet, so do Save-As instead.
Goto FileSaveAs
Gosub SaveCurrentFile
return
FileSaveAs:
Gui +OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16,, Save File ;, Text Documents (*.txt)
;FileSelectFile, SelectedFileName, 1,, Save File, AutoHotkey Scripts (*.ahk)
if SelectedFileName = ; No file selected.
return
CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return
SaveCurrentFile: ; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
FileDelete %CurrentFileName%
if ErrorLevel
{
MsgBox The attempt to overwrite "%CurrentFileName%" failed.
return
}
}
GuiControlGet, MainEdit ; Retrieve the contents of the Edit control.
FileAppend, %MainEdit%, %CurrentFileName% ;, AutoHotkey Scripts (*.ahk) ; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
Gui, Show,, %CurrentFileName%
return
HelpAbout:
run, https://github.com/adegard/TagIE.ahk
/*
Gui, 2:+owner1 ; Make the main window (Gui #1) the owner of the "about box" (Gui #2).
Gui +Disabled ; Disable main window.
Gui, 2:Add, Text,, Text for about box.
Gui, 2:Add, Button, Default, OK
Gui, 2:Show
*/
return
2ButtonOK: ; This section is used by the "about box" above.
2GuiClose:
2GuiEscape:
Gui, 1:-Disabled ; Re-enable the main window (must be done prior to the next step).
Gui Destroy ; Destroy the about box.
return
GuiDropFiles: ; Support drag & drop.
Loop, parse, A_GuiEvent, `n
{
SelectedFileName = %A_LoopField% ; Get the first file only (in case there's more than one).
break
}
Gosub FileRead
return
GuiSize:
if ErrorLevel = 1 ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
NewWidth := A_GuiWidth - 120
NewHeight := A_GuiHeight - 20
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return
FileExit: ; User chose "Exit" from the File menu.
GuiClose: ; User closed the window.
ExitApp
GuiButtonIcon(Handle, File, Index := 1, Options := "")
{
RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 :
RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 :
RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S :
RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 :
RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 :
RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 :
RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 :
RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 :
Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr"
VarSetCapacity( button_il, 20 + Psz, 0 )
NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height
NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin
NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin
NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin
NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin
NumPut( A, button_il, 16 + Psz, DW ) ; Alignment
SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle%
return IL_Add( normal_il, File, Index )
}
;{ GuiButtonIcon
; Fanatic Guru : https://autohotkey.com/boards/viewtopic.php?t=1985
; 2014 05 31
; Version 2.0
;
; FUNCTION to Assign an Icon to a Gui Button
;
;------------------------------------------------
;
; Method:
; GuiButtonIcon(Handle, File, Options)
;
; Parameters:
; 1) {Handle} HWND handle of Gui button
; 2) {File} File containing icon image
; 3) {Index} Index of icon in file
; Optional: Default = 1
; 4) {Options} Single letter flag followed by a number with multiple options delimited by a space
; W = Width of Icon (default = 16)
; H = Height of Icon (default = 16)
; S = Size of Icon, Makes Width and Height both equal to Size
; L = Left Margin
; T = Top Margin
; R = Right Margin
; B = Botton Margin
; A = Alignment (0 = left, 1 = right, 2 = top, 3 = bottom, 4 = center; default = 4)
;
; Return:
; 1 = icon found, 0 = icon not found
;
; Example:
; Gui, Add, Button, w70 h38 hwndIcon, Save
; GuiButtonIcon(Icon, "shell32.dll", 259, "s30 a1 r2")
; Gui, Show
;
Escape::ExitApp
; *******************************************************************
; AddGraphicButton.ahk - see https://autohotkey.com/board/topic/3816-graphic-buttons/
; *******************************************************************
; 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%
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
}