Beta_3, 20 August 2019 -
- Fix 'Set FileVersion' and 'Set ProductVersion'.
- Implement 'Save Script Settings as' on File menu.
- Implement new directives 'Bin', 'ExeName' and 'Obey'.
- Handle unloading and reloading for the generated .exe.
Code: Select all
;@Ahk2Exe-Set Comments, These are comments for the current executable
;@Ahk2Exe-Cont and they are too long for a single line
;@Ahk2Exe-Cont so we break them into little parts easily readable.
Code: Select all
; just a demo, not complete code
LastUseMPRESS := -1, BinNames := "Default|ANSI 32-bit|Unicode 32-bit|Unicode 64-bit", BinFileId := 1
;===============================>
nu := LastUseMPRESS < 0 ? 0 : 1
CompressDescr := {-1:" U&PX", 0:"your mind &power :-)", 1:" M&PRESS"}
RegRead, upx, HKCU, Software\AutoHotkey\Ahk2Exe, LastCompression
upx+=1
h := 22 ; common height for controls, easily adjustable if/when needed
bw := 53 ; common width for buttons
h1 := 21 ; height for compression row
gh1 := h+33, gh2 := 3*h+h1+15+28, h2 := gh1+5, h3 := gh2+8
Gui, +LastFound
GuiHwnd := WinExist("")
Gui, Margin, 10, 3
Gui, Add, Link, x287 y20,
(
©2004-2009 Chris Mallet
©2008-2011 Steve Gray (Lexikos)
©2011-2016 fincs
©2017-2019 Steve Gray, TAC109
<a href="https://www.autohotkey.com">https://www.autohotkey.com</a>
)
Gui, Add, Text, xm y+15 w570 h2 +0x1007
Gui, Add, GroupBox, xm y+7 w570 h%gh1% Section cBlue, Required Parameter
Gui, Add, Text, xm+6 ys+20 h%h% +0x200, &Source (script file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vAhkFile, %AhkFile%
Gui, Add, Button, x+5 yp w%bw% hp gBrowseAhk, &Browse
Gui, Add, GroupBox, xm ys+%h2% w570 h%gh2% Section cBlue, Optional Parameters
Gui, Add, Text, xm+6 ys+20 h%h% +0x200, &Destination (.exe file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vExeFile, %Exefile%
Gui, Add, Button, x459 yp w%bw% hp gBrowseExe, B&rowse
Gui, Add, Button, x+5 yp w%bw% hp gDefaultExe, De&fault
Gui, Add, Text, xm+6 y+5 h%h% +0x200, Custom &Icon (.ico file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vIcoFile, %IcoFile%
Gui, Add, Button, x459 yp w%bw% hp gBrowseIco, Br&owse
Gui, Add, Button, x+5 yp w%bw% hp gDefaultIco, D&efault
Gui, Add, Text, xm+6 y+5 h%h% +0x200, Base File (.bin)
Gui, Add, DDL, x137 yp w315 h50 R10 AltSubmit vBinFileId Choose%BinFileId%, %BinNames%
Gui, Add, Text, xm+6 y+5 h%h1% +0x200, Compress exe with
Gui, Add, CheckBox, x137 yp w120 hp Check3 vUseMpress gcompress Checked%LastUseMPRESS%
, % CompressDescr[LastUseMPRESS]
Gui, Add, DDL, x258 yp w75 h50 R6 E0x402000 Hidden%nu% vupx Choose%upx%
, Lowest|Low|Normal|High|Highest
Gui, Add, Text, x+2 yp hp +0x200 Hidden%nu% vupxlevel, compression level
Gui, Add, Text, x258 yp w195 hp +0x200 Hidden Disabled vmissing,
Gui, Add, Button, x258 ys+%h3% w75 h28 Default gConvert, > &Convert <
Gui, Add, Text, xm yp-5 w245 Disabled,
(LTrim
NOTE: In-script compiler directives, if any, will
override their correspondent optional parameters
set above, except for compression.
)
Gui, Add, Text, x+90 yp w235 Disabled,
(LTrim
NOTE 2: Compiling can NOT and does NOT
`t guarantee source code protection.
)
Gui, Add, StatusBar,, Ready
;@Ahk2Exe-IgnoreBegin
Gui, Add, Pic, x29 y16 w240 h78, %A_ScriptDir%\logo.png
;@Ahk2Exe-IgnoreEnd
/*@Ahk2Exe-Keep
gosub AddPicture
*/
GuiControl, Focus, Button1
Gui, Show, AutoSize, Ahk2Exe for AutoHotkey v%A_AhkVersion% -- Script to EXE Converter
compress:
Gui, Submit, NoHide
compressor := UseMpress < 0 ? "upx.exe" : UseMpress > 0 ? "mpress.exe" : "your trust"
if m := (!UseMpress OR FileExist(A_ScriptDir "\" compressor)) ? "" : " [missing]"
{
GuiControl Text, missing, * Put %compressor% in compiler's folder
SetTimer, chkComp, 1500
}
GuiControl Text, UseMpress, % CompressDescr[UseMPRESS] m
GuiControl, % (UseMpress && m ? "Show" : "Hide"), missing
GuiControl, % (UseMpress=-1 && !m ? "Show" : "Hide"), upx
GuiControl, % (UseMpress=-1 && !m ? "Show" : "Hide"), upxlevel
return
GuiClose:
Gui, Submit
gosub SaveSettings
ExitApp
DefaultExe:
ExeFile := ""
GuiControl,, ExeFile, %ExeFile%
return
chkComp:
if !FileExist(A_ScriptDir "\" compressor)
return
SetTimer,, Off
goto compress
Convert:
SetTimer, chkComp, Off
; upx--
;if UseMpress=-1
; RegWrite, DWORD, HKCU, Software\AutoHotkey\Ahk2Exe, LastCompression, %upx%
;... all the rest
;============ DUMMY LABELS ============<
BrowseAhk:
BrowseExe:
BrowseIco:
DefaultIco:
AddPicture:
SaveSettings:
return
Code: Select all
; just a demo, not complete code
; to do: disable fields that are overridden by directives
LastUseMPRESS := -1, BinNames := "Default|ANSI 32-bit|Unicode 32-bit|Unicode 64-bit"
BinFileId := 1
;===============================>
nu := LastUseMPRESS < 0 ? 0 : 1, AW := A_IsUnicode ? "W" : "A"
CompressDescr := {-1:" U&PX", 0:"your mind &power :-)", 1:" M&PRESS"}
RegRead, upx, HKCU, Software\AutoHotkey\Ahk2Exe, LastUPXlevel
upx+=1
RegRead, cp, HKCU, Software\AutoHotkey\Ahk2Exe, LastUseCodepage
cp+=0, ncp := !cp
RegRead, cpnum, HKCU, Software\AutoHotkey\Ahk2Exe, LastCodepage
cpnum+=0
gosub listCP
h := 20 ; common height for controls, easily adjustable if/when needed
bw := 53 ; common width for buttons
h1 := h+5 ; height for binary, codepage, compression rows plus spacing
gh1 := h+33, gh2 := 5*h+20+28, h2 := gh1+5, h3 := gh2+8
Gui, +LastFound
GuiHwnd := WinExist("")
Gui, Margin, 10, 3
;Gui, Color, White, White
Gui, Add, Link, x287 y20,
(
©2004-2009 Chris Mallet
©2008-2011 Steve Gray (Lexikos)
©2011-2016 fincs
©2017-2019 Steve Gray, TAC109
<a href="https://www.autohotkey.com">https://www.autohotkey.com</a>
)
Gui, Add, Text, xm y+15 w570 h2 +0x1007
Gui, Add, GroupBox, xm y+7 w570 h%gh1% Section cBlue, Required Parameter
Gui, Add, Text, xm+6 ys+20 h%h% +0x200, &Source (script file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vAhkFile, %AhkFile%
Gui, Add, Button, x+5 yp w%bw% hp gBrowseAhk, &Browse
Gui, Add, GroupBox, xm ys+%h2% w570 h%gh2% Section cBlue, Optional Parameters
Gui, Add, Text, xm+6 ys+20 h%h% +0x200, &Destination (.exe file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vExeFile, %Exefile%
Gui, Add, Button, x459 yp w%bw% hp gBrowseExe, B&rowse
Gui, Add, Button, x+5 yp w%bw% hp gDefaultExe, De&fault
Gui, Add, Text, xm+6 y+5 h%h% +0x200, Custom &Icon (.ico file)
Gui, Add, Edit, x137 yp w315 hp +Disabled vIcoFile, %IcoFile%
Gui, Add, Button, x459 yp w%bw% hp gBrowseIco, Br&owse
Gui, Add, Button, x+5 yp w%bw% hp gDefaultIco, D&efault
Gui, Add, Text, xm+6 y+5 h%h% +0x200, Base File (.bin)
Gui, Add, DDL, x137 yp w315 h50 R10 AltSubmit vBinFileId Choose%BinFileId% hwndhDDL1
, %BinNames%
SendMessage, 0x153, -1, h-5,, ahk_id %hDDL1%
Gui, Add, CheckBox, xm+6 yp+%h1% w120 h%h% vcp gsetcp Checked%cp%, Codepage: %cpnum%
Gui, Add, DDL, x137 yp w315 h50 R20 vcodepage gchoosecp Choose%curCP% hwndhDDL2
, %cpSlist%
SendMessage, 0x153, -1, h-5,, ahk_id %hDDL2%
Gui, Add, Text, xm+6 yp+%h1% h%h% +0x200, Compress exe with
Gui, Add, CheckBox, x137 yp w120 hp Check3 vUseMpress gcompress Checked%LastUseMPRESS%
, % CompressDescr[LastUseMPRESS]
Gui, Add, DDL, x258 yp w75 h50 R6 E0x402000 Hidden%nu% vupx Choose%upx% hwndhDDL3
, Lowest|Low|Normal|High|Highest
SendMessage, 0x153, -1, h-5,, ahk_id %hDDL3%
Gui, Add, Text, x+2 yp h%h% +0x200 Hidden%nu% vupxlevel, compression level
Gui, Add, Text, x258 yp w195 hp +0x200 Hidden Disabled vmissing,
Gui, Add, Button, x258 ys+%h3% w75 h28 Default gConvert, > &Convert <
Gui, Add, Text, xm yp-5 w245 Disabled,
(LTrim
NOTE: In-script compiler directives, if any, will
override their correspondent optional parameters
set above, except for compression.
)
Gui, Add, Text, x+90 yp w235 Disabled,
(LTrim
NOTE 2: Compiling can NOT and does NOT
`t guarantee source code protection.
)
Gui, Add, StatusBar,, Ready
;@Ahk2Exe-IgnoreBegin
;Gui, Add, Pic, x29 y16 w240 h78, %A_ScriptDir%\logo.png
Gui, Add, Picture, x29 y16 w240 h78 -AltSubmit -BackgroundTrans +0xE, %A_ScriptDir%\logo.bmp
;@Ahk2Exe-IgnoreEnd
/*@Ahk2Exe-Keep
gosub AddPicture
*/
GuiControl, Focus, Button1
Gui, Show, AutoSize, Ahk2Exe for AutoHotkey v%A_AhkVersion% -- Script to EXE Converter
compress:
Gui, Submit, NoHide
compressor := UseMpress < 0 ? "upx.exe" : UseMpress > 0 ? "mpress.exe" : "your trust"
if m := (!UseMpress OR FileExist(A_ScriptDir "\" compressor)) ? "" : " [missing]"
{
GuiControl Text, missing, * Put %compressor% in compiler's folder
SetTimer, chkComp, 1500
}
GuiControl Text, UseMpress, % CompressDescr[UseMPRESS] m
GuiControl, % (UseMpress && m ? "Show" : "Hide"), missing
GuiControl, % (UseMpress=-1 && !m ? "Show" : "Hide"), upx
GuiControl, % (UseMpress=-1 && !m ? "Show" : "Hide"), upxlevel
return
GuiClose:
Gui, Submit
gosub SaveSettings
ExitApp
DefaultExe:
ExeFile := ""
GuiControl,, ExeFile, %ExeFile%
return
chkComp:
if !FileExist(A_ScriptDir "\" compressor)
return
SetTimer,, Off
goto compress
Convert:
SetTimer, chkComp, Off
Gui, Submit, NoHide
; upx--
;if UseMpress=-1
; RegWrite, DWORD, HKCU, Software\AutoHotkey\Ahk2Exe, LastUPXlevel, %upx%
;RegWrite, DWORD, HKCU, Software\AutoHotkey\Ahk2Exe, LastUseCodepage, %cp%
;if cp
; RegWrite, DWORD, HKCU, Software\AutoHotkey\Ahk2Exe, LastCodepage, %cpnum%
;... all the rest
return
setcp:
Gui, Submit, NoHide
GuiControl, % (cp ? "Show" : "Hide"), codepage
;return
chooseCP:
Gui, Submit, NoHide
GuiControl,, cpnum, % cpnum := cpS[codepage]
GuiControl,, cp, % "Codepage: " (cp ? cpnum : "default")
return
listCP:
codepage := GetCPName(cpnum), defACP := GetCPName(0), curCP := 1, cpS := {}
DllCall("EnumSystemCodePages" AW
, "Ptr", ECP := RegisterCallback("EnumCodePagesProc", "F", 1, 0)
, "UInt", 2) ; 1=Installed, 2=Supported
cpS["<default Windows ANSI>"] := 0, cpS["UTF-8"] := 65001, cpS["UTF-16"] := 1200
For k, v in cpS
cpSlist .= k "|"
StringTrimRight, cpSlist, cpSlist, 1
Sort, cpSlist, U CL D| F SortN
For k, v in cpSlist
if (v=cpnum)
{
curCP := A_Index
break
}
return
EnumCodePagesProc(in)
{
Global cpS
if cp := in ? StrGet(in) : 0
cpS[GetCPName(cp)] := cp
return !!cp
}
GetCPName(cp)
{
Global AW
Static CPIX, sz := 24+260*(A_IsUnicode ? 2 : 1)
VarSetCapacity(CPIX, sz, 0) ; CPINFOEXA/W struct
if DllCall("GetCPInfoEx" AW, "UInt", cp+0, "UInt", 0, "Ptr", &CPIX)
return StrGet(&CPIX+24)
}
SortN(s1, s2)
{
if !A_IsUnicode
Loop, 2
MB2WC(s%A_Index%)
return DllCall("shlwapi\StrCmpLogicalW", "Str", s1, "Str", s2, "Int")
}
MB2WC(ByRef strg)
{
in := strg, sz := 0
Loop, 2
{
VarSetCapacity(strg, sz*2)
sz := DllCall("MultiByteToWideChar"
, "UInt", 65001
, "UInt", 0
, "Ptr", &in
, "Int", -1
, "Ptr", &strg
, "UInt", sz)
}
}
;============ DUMMY LABELS ============<
BrowseAhk:
BrowseExe:
BrowseIco:
DefaultIco:
AddPicture:
SaveSettings:
return
Not sure. My thoughts were to keep as close as possible to the original layout that people got accustomed to already. We may need other opinions on that. But personally I don't mind swapping field places if needed.
Not at all; problems may arise for UTF-8 without BOM, depending on the file editor. I'm used to Metapad but that one has an unfinished UTF-8 implementation (still uses an ANSI RichEdit control) and displays UTF-8 characters decomposed. Could be a feature, hinting me to check if the file is indeed saved with BOM or not. I also noticed those © symbols but fixed the issue promptly.
Could be useful. Just please be careful not to confuse the user. Everything must be as intuitive as possible.
Code: Select all
;@Ahk2Exe-Set Comments, These are comments for the current executable
;@Ahk2Exe-Cont and they are too long for a single line
;@Ahk2Exe-Cont so we break them into little parts easily readable.
Return to “Scripts and Functions (v1)”
Users browsing this forum: ntepa and 147 guests