I've modified the original code to fit my likings
Changes:
-Script generates the icon
-Added header to the list
-Moved all files to one directory
-Added Launchy integration
I've also created 2 scripts that add and delete items from the list via
Launchyadd.ahkCode:
#NoTrayIcon
IniRead, ToDoList_File, %A_ScriptDir%\ToDoList.ini, Settings, ToDoList_File
Loop, %0%
task := A_Index = 1 ? task := %A_Index% : task " " %A_Index%
FileAppend, -%task%`n, %ToDoList_File%
Run, %A_ScriptDir%\ToDoList.ahk
del.ahkCode:
#NoTrayIcon
IniRead, FileSelected, %A_ScriptDir%\ToDoList.ini, Settings, ToDoList_File
FileRead, FileData, %FileSelected%
Loop, %0%
task := A_Index = 1 ? task := %A_Index% : task " " %A_Index%
StringReplace, FileData, FileData, -%task%
Loop, Parse, FileData, `r`n
Data .= (RegExMatch(A_LoopField,"[\S]+?")) ? A_LoopField "`n" :
FileDelete, %FileSelected%
FileAppend, %Data%, %FileSelected%
Run, %A_ScriptDir%\ToDoList.ahk
Directions for setting up Launchy:1. Options -> Catelog -> add *.ahk to file types.

2. Rescan Catelog
3. To add item to list, just type "add + tab" -> TODO list item

4. To delete an item, just type "del + tab" -> TODO list item
ToDoList.ahkCode:
/*
Author: Lars Shirey (aka TotalBalance)
Alpha v.0.50 DT_TDL_alpha.ahk
http://www.autohotkey.com/forum/viewtopic.php?t=34123
Modified by: Voltron43
*/
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
#Persistent
SetBatchLines -1
DetectHiddenWindows, On
icon = %A_Temp%\tick.ico
IfNotExist, %icon%
{
GoSub, DefinePicture
WriteFile(icon,Decompress(tick))
}
FileSelected = %A_Scriptdir%\ToDoLists.txt
IfNotExist, %FileSelected%
FileAppend,TODO`n--------------------`n, %FileSelected%
; eeCreate, read/write ini file
IfNotExist, %A_Scriptdir%\ToDoList.ini
{
IniWrite, Center, %A_Scriptdir%\ToDoList.ini, Settings, xPos
IniWrite, Center, %A_Scriptdir%\ToDoList.ini, Settings, yPos
IniWrite, Verdana, %A_Scriptdir%\ToDoList.ini, Settings, Font_Type
IniWrite, S16 Bold, %A_Scriptdir%\ToDoList.ini, Settings, Font_Style
IniWrite, Black, %A_Scriptdir%\ToDoList.ini, Settings, Font_Color
IniWrite, On, %A_Scriptdir%\ToDoList.ini, Settings, Transparent
IniWrite, Red, %A_Scriptdir%\ToDoList.ini, Settings, Background_Color
IniWrite, On, %A_Scriptdir%\ToDoList.ini, Settings, Always_On_Top
IniWrite, %FileSelected%, %A_Scriptdir%\ToDoList.ini, Settings, ToDoList_File
}
IfExist, %A_Scriptdir%\ToDoList.ini
{
IniRead, xPos, %A_Scriptdir%\ToDoList.ini, Settings, xPos
IniRead, yPos, %A_Scriptdir%\ToDoList.ini, Settings, yPos
IniRead, Font_Type, %A_Scriptdir%\ToDoList.ini, Settings, Font_Type
IniRead, Font_Style, %A_Scriptdir%\ToDoList.ini, Settings, Font_Style
IniRead, Font_Color, %A_Scriptdir%\ToDoList.ini, Settings, Font_Color
IniRead, Background_Color, %A_Scriptdir%\ToDoList.ini, Settings, Background_Color
IniRead, Transparent, %A_Scriptdir%\ToDoList.ini, Settings, Transparent
IniRead, Always_On_Top, %A_Scriptdir%\ToDoList.ini, Settings, Always_On_Top
IniRead, FileSelected, %A_Scriptdir%\ToDoList.ini, Settings, ToDoList_File
}
Aff_Full_Path = %FileSelected%
SplitPath, Aff_Full_Path, Aff_File_Name
Gosub, TrayMenu
; ---Functions to adjust GUI based on user preferences
Menu, Transparent, Check, %Transparent%
Menu, Always_On_Top, Check, %Always_On_Top%
If Always_On_Top = On
AlwaysOnTop = +AlwaysOnTop
If Always_On_Top = Off
AlwaysOnTop =
; ---Handle upto Font size 20 - need to autosize GUI to fit text
GuiHeight = 320
GuiWidth = 240
; ---Gui display and transparency options
Gui, +LastFound
Gui, Color, %Background_Color%
Gui, Font, %Font_Style% C%Font_Color%, %Font_Type%
If Transparent = Off
{
Gui, +ToolWindow -Caption -Border %AlwaysOnTop%
Gui, Add, Text, w%GuiWidth% h%GuiHeight% GuiMove vToDoList
}
If Transparent = On
{
Gui, -Caption +ToolWindow %AlwaysOnTop%
Gui, Add, Text, w%GuiWidth% h%GuiHeight% BackgroundTrans GuiMove vToDoList
WinSet, TransColor, %Background_Color% 150
}
Gui, Show, x%xPos% y%yPos% NoActivate, ToDoList
GoSub, TDL_Read
Return
; ------------------------------------------------------------------------------
; GUI
; ------------------------------------------------------------------------------
^!q::GoSub AddTask
^!\::GoSub DeleteTask
DeleteTask:
Gui, 3:Destroy
Gui 3:+AlwaysOnTop -SysMenu
Gui, 3:Add, Text,w100, Task
Gui, 3:Add, Edit, w275 x60 vDTask ym
Gui, 3:Add, Button, w60 x100 +y40 default, OK
Gui, 3:Add, Button, w60 x190 y40, Cancel
Gui, 3:Show,, Delete Task
Return
3ButtonOK:
Gui, 3:Submit
FileRead, FileData, %FileSelected%
StringReplace, FileData, FileData, -%DTask%
Loop, Parse, FileData, `r`n
Data .= (RegExMatch(A_LoopField,"[\S]+?")) ? A_LoopField "`n" :
FileDelete, %FileSelected%
FileAppend, %Data%, %FileSelected%
Reload
Return
3ButtonCancel:
3GuiEscape:
3GuiClose:
Gui, 3:Destroy
Return
AddTask:
Gui, 2:Destroy
Gui 2:+AlwaysOnTop -SysMenu
Gui, 2:Add, Text,w100, Task
Gui, 2:Add, Edit, w275 x60 vTask ym
Gui, 2:Add, Button, w60 x100 +y40 default, OK
Gui, 2:Add, Button, w60 x190 y40, Cancel
Gui, 2:Show,, New Task
Return
2ButtonOK:
Gui, 2:Submit
FileAppend, -%Task%`n, %FileSelected%
Reload
Return
2ButtonCancel:
2GuiEscape:
2GuiClose:
Gui, 2:Destroy
Return
uiMove:
PostMessage, 0xA1, 2,,, A
; after moving GUI, save new positions to ini file
WinGetPos, xPos, yPos, Width, Height, ToDoList
IniWrite, %xPos%, %A_Scriptdir%\ToDoList.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\ToDoList.ini, Settings, yPos
Return
TDL_Read:
FileRead, TDL, %FileSelected%
GuiControl,, ToDoList, %TDL%
Return
; User Preferences Tray
TrayMenu:
Menu, Tray, Icon , %A_Temp%\tick.ico
Menu, Tray, Tip, ToDoList`n%Aff_File_Name%
Menu, Tray, MainWindow
Menu, Tray, NoStandard
Menu, Tray, Add, ToDoList, ToDoList
Menu, Tray, Add
Menu, Tray, Add, Select File, ToDoListFile
Menu, Tray, Add
Menu, Tray, Add, Font Selection, Font_Select
Menu, Colors, Add, TextColor
Menu, Colors, Add, BackgroundColor
Menu, Tray, Add, Choose Colors, :Colors
Menu, Transparent, Add, On
Menu, Transparent, Add, Off
Menu, Tray, Add, Transparent, :Transparent
Menu, Always_On_Top, Add, On
Menu, Always_On_Top, Add, Off
Menu, Tray, Add, Always on Top, :Always_On_Top
Menu, Tray, Add, Hide, Hide
Menu, Tray, Add, Show, Show
Menu, Tray, Add
Menu, Tray, Add, Help, Help
Menu, Tray, Add, About, About
Menu, Tray, Add
Menu, Tray, Add, Exit, Exit
Menu, Tray, Disable, Show
Menu, Tray, Default, ToDoList
Return
ToDoList:
Gui, Show, , ToDoList
Return
;Allow user to pick ToDoList text file from Windows Explorer
ToDoListFile:
Gui +OwnDialogs
FileSelectedBak := FileSelected
FileSelectFile, FileSelected
If ErrorLevel
FileSelected := FileSelectedBak
IniWrite, %FileSelected%, %A_Scriptdir%\ToDoList.ini, Settings, ToDoList_File
GoSub, Menu_Change
Return
; Font Preferences
Font_Select:
if !CmnDlg_ChooseFont(Font_Type, Font_Style, Font_Color)
return
IniWrite, %Font_Type%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Type
IniWrite, %Font_Style%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Style
IniWrite, %Font_Color%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Color
Gosub, Menu_Change
Return
; Color Preferences, update ini file
TextColor:
if !CmnDlg_ChooseColor(Font_Color)
return
IniWrite, %Font_Color%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Color
Gosub, Menu_Change
Return
BackgroundColor:
if !CmnDlg_ChooseColor(Background_Color)
return
IniWrite, %Background_Color%, %A_Scriptdir%\ToDoList.ini, Settings, Background_Color
Gosub, Menu_Change
Return
;Misc. Preference settings
On:
If A_ThisMenu = Transparent
IniWrite, On, %A_Scriptdir%\ToDoList.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, On, %A_Scriptdir%\ToDoList.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Off:
If A_ThisMenu = Transparent
IniWrite, Off, %A_Scriptdir%\ToDoList.ini, Settings, Transparent
If A_ThisMenu = Always_On_Top
IniWrite, Off, %A_Scriptdir%\ToDoList.ini, Settings, Always_On_Top
Gosub, Menu_Change
Return
Show:
Gui, Show, , ToDoList
Menu, Tray, ToggleEnable, Show
Menu, Tray, ToggleEnable, Hide
Return
Hide:
Gui, Submit, ToDoList
Menu, Tray, ToggleEnable, Hide
Menu, Tray, ToggleEnable, Show
Return
; On any icon tray preferences change, reload script to reflect changes.
Menu_Change:
Reload
Return
; Just holding places for Help & About screens
Help:
MsgBox, 64, ToDoList - Help, To Be Completed Later`n
Return
About:
MsgBox, 64, ToDoList - About, To Be Completed Later`n
Return
; on exit, make sure everything is saved to ini file
Exit:
GuiEscape:
GuiClose:
IniWrite, %FileSelected%, %A_Scriptdir%\ToDoList.ini, Settings, ToDoList_File
IniWrite, %Font_Type%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Type
IniWrite, %Font_Style%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Style
IniWrite, %Font_Color%, %A_Scriptdir%\ToDoList.ini, Settings, Font_Color
IniWrite, %Background_Color%, %A_Scriptdir%\ToDoList.ini, Settings, Background_Color
IniWrite, %Transparent%, %A_Scriptdir%\ToDoList.ini, Settings, Transparent
IniWrite, %Always_On_Top%, %A_Scriptdir%\ToDoList.ini, Settings, Always_On_Top
IniWrite, %FileSelected%, %A_Scriptdir%\ToDoList.ini, Settings, ToDoList_File
WinGetPos, xPos, yPos, Width, Height, ToDoList
IniWrite, %xPos%, %A_Scriptdir%\ToDoList.ini, Settings, xPos
IniWrite, %yPos%, %A_Scriptdir%\ToDoList.ini, Settings, yPos
ExitApp
; ------------------------------------------------------------------------------
WriteFile(file,data)
{
Handle := DllCall("CreateFile","str",file,"Uint",0x40000000
,"Uint",0,"UInt",0,"UInt",4,"Uint",0,"UInt",0)
Loop
{
if strlen(data) = 0
break
StringLeft, Hex, data, 2
StringTrimLeft, data, data, 2
Hex = 0x%Hex%
DllCall("WriteFile","UInt", Handle,"UChar *", Hex
,"UInt",1,"UInt *",UnusedVariable,"UInt",0)
}
DllCall("CloseHandle", "Uint", Handle)
return
}
;Decompress
Decompress(o) {
Loop Parse, o, | ; DECOMPRESS
{
If (A_Index & 1) { ; Odd index...
t = %t%%A_LoopField% ; Copy block to output
Continue
} ; Even index...
StringRight r, t, 2 ; Get last byte
Loop %A_LoopField% ; Duplicate as needed
t = %t%%r%
}
Return,t
}
DefinePicture:
tick =
( join
00|1|0100010020|1|00|1|01002000a81000|1|1600|2|2800|2|2000|2|4000|2|01002000|316
|0102010301030105010201050102010401|2|0200|107|010301050205020a02040209010301070
102010400|99|01020103010302050f2411451d4420851b411e83193e1c810d200f430102010401|
2|0200|91|010302050205030a1d44208537833dff347d3afd2f7835fb193e1c8101030107010201
0400|83|010201030203020512271445214a2585346e38c246934dff438f4afe3f8c46fd2c6632c0
1a401d830e210f440102010401|2|0200|75|020302050306030a224a2585408e47ff4a9952ff54a
35cff52a15aff4f9f57ff418e48ff327c38fe1a401d83010402080102010400|67|0102010302030
205142a164526502a853a7740c24e9d56ff5aaa63ff66b76fff64b56dff62b46bff52a15aff428e4
9ff2d6833c11a411e830e2210440102010401|2|0200|59|020302050306030a26502a85499a51ff
52a35bff5bac64ff69bb73ff77ca82ff76c980ff74c87eff63b46cff51a059ff428f49ff337d39fe
1a411e83010402080102010400|51|0102010302040205162d19452a562f85407e47c256a85fff62
b36bff6dbd77ff73c47eff79cb85ff78ca82ff75c980ff6dbf77ff64b56dff53a35cff43904aff2f
6833c11b411e830e2210440102010401|2|0200|43|020402050307040a2a572f8551a65aff5aae6
4ff63b56dff71c27bff7ece89ff7dcd88ff7bcc87ff79cb84ff76ca81ff76ca81ff76c981ff64b66
eff52a25aff43904aff347e3afe1b411e83020402080102010400|39|0203020518301b452e5c348
546874ec25eb268ff69bb74ff74c47fff78c883ff7ccc87ff75c680ff6ebf79ff6ebf78ff6dbf77f
f72c57dff77c982ff6ec079ff65b76eff55a45dff44914bff306835c11b411e830e2210440102010
401|2|0200|31|030604092e5b348459b063ff62b76dff6bbd76ff78c883ff84d290ff7fce8bff7a
c985ff6dbe78ff60b26aff62b36cff63b46dff6ebf78ff78c983ff78ca83ff78cb82ff66b76fff53
a35cff44904bfe347d3afd1b411e83020402080102010400|31|0f1d11283263388d54a95ff264b7
6ef972c37eff7bca87ff82d08fff74c47fff65b66ffe529a5cdb417b48b744814bbe46854cc558a0
61e26abb75ff72c47dff7acc84ff71c27bff66b771ff56a55eff44904cfe306835c11b411e820e22
10430102010401|2|0200|23|1a331d46366b3c9550a25ae465b571f279c986ff7dcc8aff80ce8df
f68b873fe4fa359fc38743fb62246256f254e297d28542c8b428049c55cad67ff6cbd77ff7ccc86f
f7bcc86ff79cb85ff67b871ff54a45dff44904cfe337e39fc1b411e82020402080102010400|23|0
d1a0f232141255a34673a904d8e56c266b770f36ebe7af977c783ff58a062db3b7841b6264e2a771
12313381327153f142b16462c57318743834bc858a161e46dbd77ff75c580ff7bcc87ff72c37dff6
8b972ff57a560ff45914dfe316935c01c421f820f2210430102010401|2|0200|19|0b160d1e162c
193c35673b9153a35be65fb16bf36dc079ff488550b7254b296f1326153800|11|152d18492a592f
9143844bc85eae68ff6ebe79ff7dcd89ff7dcd88ff7ccd87ff69b973ff56a55fff46914dfe347e3a
fc1c421f82020402080102010400|19|060b070f0b160d1e2141255a366b3c95407847a4498451b2
2e553375132615380a130b1c00|11|0b170c25152d18492d59328944844bc859a262e46ebe79ff76
c681ff7ece89ff74c47fff6aba74ff59a661ff46924efe326b37c01c421f820f2210430102010401
|2|0200|19|0d190e2219311c431f3d2354244829651224153300|27|162d18492b5a2f9144854bc
85faf69ff6fbf7aff7fce8aff7fce8aff7ece89ff6bba75ff57a660ff47924efe357f3bfc1c421f8
2020402080102010400|19|070d07110d190e22101f122a1224153309120b1a00|27|0b170c25162
d18492e59328944854dc85aa263e470bf7aff78c783ff80cf8bff76c581ff6bbb76ff5aa762ff479
34ffe336b37c11e452184102411440102010401|2|0200|67|162d18492b5a309146854dc860b06a
ff71c07cff81cf8dff80cf8cff7fcf8bff6cbb76ff58a761ff499651ff398540ff1e452184020402
080102010400|67|0b170c25162d18492e5a338946854dc85ba464e472c17dff79c985ff81d08dff
75c480ff69b873ff59a762ff489650ff2c5c30a10f2210420811082100|75|162e18492b5b309147
874ec862b26cff72c27eff82d18fff7ecd8aff7ac885ff69b773ff57a660ff38733ebd1b401e7b0e
200f3e00|75|0b170c25162e18492f5b348947874ec85da567e473c27eff70bf7bff6dbc77ff5498
5cde3b7642bc254b297d0e200f3e0710081f00|83|162e19492c5c319147884ec863b36dff61b16b
ff5faf69ff3f7a45bc1f4523791023123d00|91|0b170d25162e19492f5b348947884ec844834bc4
427f49bf29512e7e1023123d0812091f00|99|162e19492c5c319129552d88254e297f1327154000
|107|0b170d25162e1949152b1744132715400a140b2000|399|ff|16|c7ff|2|83ff|2|01ff|1|f
e00ff|1|fc007ffff8003ffff0001fffe0000fffc00007ff800003ff800001ff803000ffc078007f
e0fc003ff1fe001fff|1|000fff|1|8007ff|1|c003ff|1|e003ff|1|f003ff|1|f807ff|1|fc0ff
f|1|fe1fff|2|3fff|15|
)
Return
; ------------------------------------------------------------------------------
; Title: CmnDlg
; *Common Operating System dialogs*
; ------------------------------------------------------------------------------
;
; Function: ChooseColor
; Display standard color dialog
;
; Parameters:
; pColor - Initial color and output in RGB format,
; hGui - Optional handle to parents HWND
;
; Returns:
; False if user canceled the dialog or if error occurred
;
; ------------------------------------------------------------------------------
CmnDlg_ChooseColor(ByRef pColor, hGui=0)
{
;covert from rgb
clr := ((pColor & 0xFF) << 16) + (pColor & 0xFF00) + ((pColor >> 16) & 0xFF)
VarSetCapacity(sCHOOSECOLOR, 0x24, 0)
VarSetCapacity(aChooseColor, 64, 0)
NumPut(0x24, sCHOOSECOLOR, 0) ; DWORD lStructSize
NumPut(hGui, sCHOOSECOLOR, 4) ; HWND hwndOwner (makes dialog "modal").
NumPut(clr, sCHOOSECOLOR, 12) ; clr.rgbResult
NumPut(&aChooseColor,sCHOOSECOLOR, 16) ; COLORREF *lpCustColors
NumPut(0x00000103, sCHOOSECOLOR, 20) ; Flag: CC_ANYCOLOR || CC_RGBINIT
nRC := DllCall("comdlg32\ChooseColorA", str, sCHOOSECOLOR) ; Display the dialog.
if (errorlevel <> 0) || (nRC = 0)
return false
clr := NumGet(sCHOOSECOLOR, 12)
oldFormat := A_FormatInteger
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
;convert to rgb
pColor := (clr & 0xff00) + ((clr & 0xff0000) >> 16) + ((clr & 0xff) << 16)
StringTrimLeft, pColor, pColor, 2
loop, % 6-strlen(pColor)
pColor=0%pColor%
pColor=0x%pColor%
SetFormat, integer, %oldFormat%
return true
}
;----------------------------------------------------------------------------------------------
; Function: ChooseFont
; Display standard font dialog
;
; Parameters:
; pFace - Initial font, output
; pStyle - Initial style, output
; pColor - Initial text color, output
; pEffects - Set to false to disable effects (strikeout, underline, color)
; hGui - Parent's handle, affects position
;
; Returns:
; False if user canceled the dialog or if error occurred
;
CmnDlg_ChooseFont(ByRef pFace, ByRef pStyle, ByRef pColor, pEffects=true, hGui=0) {
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
VarSetCapacity(SLogFont, 128, 0)
pEffects := pEffects ? 0x100 : 0
;set initial name
DllCall("RtlMoveMemory", "uint", &SLogFont+28, "Uint", &pFace, "Uint", 32)
;convert from rgb
clr := ((pColor & 0xFF) << 16) + (pColor & 0xFF00) + ((pColor >> 16) & 0xFF)
;set intial data
if InStr(pStyle, "bold")
NumPut(700, SLogFont, 16)
if InStr(pStyle, "italic")
NumPut(255, SLogFont, 20, 1 )
if InStr(pStyle, "underline")
NumPut(1, SLogFont, 21, 1)
if InStr(pStyle, "strikeout")
NumPut(1, SLogFont, 22, 1)
if RegExMatch( pStyle, "s[1-9][0-9]*", s){
StringTrimLeft, s, s, 1
s := -DllCall("MulDiv", "int", s, "int", LogPixels, "int", 72)
NumPut(s, SLogFont, 0) ; set size
}
else NumPut(16, SLogFont, 0) ; set default size
VarSetCapacity(SChooseFont, 60, 0)
NumPut(60, SChooseFont, 0) ; DWORD lStructSize
NumPut(hGui, SChooseFont, 4) ; HWND hwndOwner (makes dialog "modal").
NumPut(&SLogFont, SChooseFont, 12) ; LPLOGFONT lpLogFont
NumPut(0x041 + pEffects, SChooseFont, 20) ; CF_EFFECTS = 0x100, CF_SCREENFONTS = 1, CF_INITTOLOGFONTSTRUCT = 0x40
NumPut(clr, SChooseFont, 24) ; rgbColors
r := DllCall("comdlg32\ChooseFontA", "uint", &SChooseFont) ; Display the dialog.
if !r
return false
;font name
VarSetCapacity(pFace, 32)
DllCall("RtlMoveMemory", "str", pFace, "Uint", &SLogFont + 28, "Uint", 32)
pStyle := "s" NumGet(SChooseFont, 16) // 10
;color
old := A_FormatInteger
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
pColor := NumGet(SChooseFont, 24)
SetFormat, integer, %old%
;styles
pStyle =
VarSetCapacity(s, 3)
DllCall("RtlMoveMemory", "str", s, "Uint", &SLogFont + 20, "Uint", 3)
if NumGet(SLogFont, 16) >= 700
pStyle .= "bold "
if NumGet(SLogFont, 20, "UChar")
pStyle .= "italic "
if NumGet(SLogFont, 21, "UChar")
pStyle .= "underline "
if NumGet(SLogFont, 22, "UChar")
pStyle .= "strikeout "
s := NumGet(sLogFont, 0)
pStyle .= "s" Abs(DllCall("MulDiv", "int", abs(s), "int", 72, "int", LogPixels))
;convert to rgb
oldFormat := A_FormatInteger
SetFormat, integer, hex ; Show RGB color extracted below in hex format.
pColor := (pColor & 0xff00) + ((pColor & 0xff0000) >> 16) + ((pColor & 0xff) << 16)
StringTrimLeft, pColor, pColor, 2
loop, % 6-strlen(pColor)
pColor=0%pColor%
pColor=0x%pColor%
SetFormat, integer, %oldFormat%
return 1
}
;-----------------------------------------------------------------------------------------------
; Function: ChooseIcon
; Display standard icon dialog
;
; Parameters:
; sIcon - Default icon resource, output
; idx - Default index within resource, output
; hGui - Optional handle of the parent GUI.
;
; Returns:
; False if user canceled the dialog or if error occurred
;
; See also:
; <ChooseIconEx>
;
CmnDlg_ChooseIcon(ByRef sIcon, ByRef idx, hGui=0)
{
global
VarSetCapacity(wIcon, 1025, 0)
If sIcon
{
R := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "Str", sIcon, "Int", StrLen(sIcon), "UInt", &wIcon, "Int", 1025)
If !R
Return False
}
idx--
R := DllCall(DllCall("GetProcAddress", "Uint", DllCall("LoadLibrary", "str", "shell32.dll"), "Uint", 62), "uint", hGui, "uint", &wIcon, "uint", 1025, "intp", idx)
idx++
If !R
Return False
Len := DllCall("lstrlenW", "UInt", &wIcon)
VarSetCapacity(sIcon, len, 0)
R := DllCall("WideCharToMultiByte" , "UInt", 0, "UInt", 0, "UInt", &wIcon, "Int", len, "Str", sIcon, "Int", len, "UInt", 0, "UInt", 0)
If !R
Return False
Return True
}
;----------------------------------------------------------------------------------------------
; Function: Find / Replace
; Display standard Find and Replace dialog boxes.
;
; Parameters:
; hGui - Handle to parents HWND
; lbl - Label used for communication with dialog. CmnDlg_Event, CmnDlg_FindWhat and CmnDlg_Flags hold the dialog data
; flags - Creation flags, see below.
; deff - Default text to be displayed at the start of the dialog box in find edit box
; defr - Default text to be displayed at the start of the dialog box in replace edit box
;
; Flags:
; String containing list of creation flags. You can use "-" prefix to hide that GUI field.
;
; d - down radio button selected in Find dialog
; w - whole word selected
; c - match case selected
;
; Globals:
; Dialog box is not modal, so it communicates with the script using 4 global variables:
;
; Event - "close", "find", "replace", "replace_all"
; Flags - string contaning flags about user selection; each letter means user has selected that particular GUI element.
; FindWhat - user find text
; ReplaceWith - user replace text
;
; Returns:
; Handle of the dialog or 0 if dialog can't be created. Can also return "Invalid Label" if lbl is not valid.
;
CmnDlg_Find( hGui, lbl, flags="d", deff="") {
static FINDMSGSTRING = "commdlg_FindReplace"
static FR_DOWN=1, FR_MATCHCASE=4, FR_WHOLEWORD=2, FR_HIDEMATCHCASE=0x8000, FR_HIDEWHOLEWORD=0x10000, FR_HIDEUPDOWN=0x4000
static buf, FR, len := 256
if !Islabel(lbl)
return "Invalid Label"
f := 0
f |= InStr(flags, "d") ? FR_DOWN : 0
f |= InStr(flags, "c") ? FR_MATCHCASE : 0
f |= InStr(flags, "w") ? FR_WHOLEWORD : 0
f |= InStr(flags, "-d") ? FR_HIDEUPDOWN : 0
f |= InStr(flags, "-w") ? FR_HIDEWHOLEWORD :0
f |= InStr(flags, "-c") ? FR_HIDEMATCHCASE :0
if FR =
VarSetCapacity(FR, 40, 0), VarSetCapacity(buf, len)
if deff !=
buf := deff
NumPut( 40, FR, 0) ;size
NumPut( hGui, FR, 4) ;hwndOwner
NumPut( f, FR, 12) ;Flags
NumPut( &buf, FR, 16) ;lpstrFindWhat
NumPut( len, FR, 24) ;wFindWhatLen
CmnDlg_callback(lbl,"","","")
OnMessage( DllCall("RegisterWindowMessage", "str", FINDMSGSTRING), "CmnDlg_callback" )
return DllCall("comdlg32\FindTextA", "str", FR)
}
CmnDlg_Replace( hGui, lbl, flags="", deff="", defr="") {
static FINDMSGSTRING = "commdlg_FindReplace"
static FR_MATCHCASE=4, FR_WHOLEWORD=2, FR_HIDEMATCHCASE=0x8000, FR_HIDEWHOLEWORD=0x10000, FR_HIDEUPDOWN=0x4000
static buf_s, buf_r, FR, len := 256
if !Islabel(lbl)
return "Invalid Label"
f := 0
f |= InStr(flags, "c") ? FR_MATCHCASE : 0
f |= InStr(flags, "w") ? FR_WHOLEWORD : 0
f |= InStr(flags, "-w") ? FR_HIDEWHOLEWORD :0
f |= InStr(flags, "-c") ? FR_HIDEMATCHCASE :0
if FR =
VarSetCapacity(FR, 40, 0), VarSetCapacity(buf_s, len), VarSetCapacity(buf_r, len)
if deff !=
buf_s := deff
if defr !=
buf_r := defr
NumPut( 40, FR, 0) ;size
NumPut( hGui, FR, 4) ;hwndOwner
NumPut( f, FR, 12) ;Flags
NumPut( &buf_s, FR, 16) ;lpstrFindWhat
NumPut( &buf_r, FR, 20) ;lpstrReplaceWith
NumPut( len, FR, 24) ;wFindWhatLen
NumPut( len, FR, 26) ;wReplaceWithLen
CmnDlg_callback(lbl,"","","")
OnMessage( DllCall("RegisterWindowMessage", "str", FINDMSGSTRING), "CmnDlg_callback" )
return DllCall("comdlg32\ReplaceTextA", "str", FR)
}
;private function
CmnDlg_callback(wparam, lparam, msg, hwnd) {
global CmnDlg_Event, CmnDlg_Flags, CmnDlg_FindWhat, CmnDlg_ReplaceWith
static FR_DIALOGTERM = 0x40, FR_DOWN=1, FR_MATCHCASE=4, FR_WHOLEWORD=2, FR_HIDEMATCHCASE=0x8000, FR_HIDEWHOLEWORD=0x10000, FR_HIDEUPDOWN=0x4000, FR_REPLACE=0x10, FR_REPLACEALL=0x20, FR_FINDNEXT=8
static fun
if (hwnd = "")
return fun := wparam
flags := NumGet(lparam+0, 12), CmnDlg_Flags := ""
if (flags & FR_DIALOGTERM) {
CmnDlg_Event := "close"
gosub %fun%
return
}
CmnDlg_Flags .= (Flags & FR_MATCHCASE) && !(Flags & FR_HIDEMATCHCASE)? "c" :
CmnDlg_Flags .= (Flags & FR_WHOLEWORD) && !(Flags & FR_HIDEWHOLEWORD) ? "w" :
CmnDlg_FindWhat := DllCall("MulDiv", "Int", NumGet(lparam+0, 16), "Int",1, "Int",1, "str")
if (flags & FR_FINDNEXT) {
CmnDlg_Event := "find"
CmnDlg_Flags .= (Flags & FR_DOWN) && !(Flags & FR_HIDEUPDOWN) ? "d" :
gosub %fun%
return
}
if (flags & FR_REPLACE) or (flags & FR_REPLACEALL) {
CmnDlg_Event := (flags & FR_REPLACEALL) ? "replace_all" : "replace"
CmnDlg_ReplaceWith := DllCall("MulDiv", "Int", NumGet(lparam+0, 20), "Int",1, "Int",1, "str")
gosub %fun%
return
}
}
;----------------------------------------------------------------------------------------------
; Function: Open / Save
; Display standard Open / Save dialog
;
; Parameters:
; hGui - Parent's handle, positive number by default 0 (influences dialog position)
; Title - Dialog title
; Filter - Specify filter as with FileSelectFile. Seperate multiple filters with "|"
; DefultFilter - Index of default filter, by default 1
; Root - Specifies startup directory and initial content of "File Name" edit.
; Directory must have trailing "\".
; DefaulltExt - Extension to append when none given
; Flags - White space separated list of flags, by default "FILEMUSTEXIST HIDEREADONLY"
;
; Flags:
; ALLOWMULTISELECT - Specifies that the File Name list box allows multiple selections
; CREATEPROMPT - If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file
; DONTADDTORECENT - Prevents the system from adding a link to the selected file in the file system directory that contains the user's most recently used documents.
; EXTENSIONDIFFERENT - Specifies that the user typed a file name extension that differs from the extension specified by defaulltExt
; FILEMUSTEXIST - Specifies that the user can type only names of existing files in the File Name entry field
; FORCESHOWHIDDEN - Forces the showing of system and hidden files, thus overriding the user setting to show or not show hidden files. However, a file that is marked both system and hidden is not shown.
; HIDEREADONLY - Hides the Read Only check box.
; NOCHANGEDIR - Restores the current directory to its original value if the user changed the directory while searching for files.
; NODEREFERENCELINKS - Directs the dialog box to return the path and file name of the selected shortcut (.LNK) file. If this value is not specified, the dialog box returns the path and file name of the file referenced by the shortcut.
; NOVALIDATE - Specifies that the common dialog boxes allow invalid characters in the returned file name
; OVERWRITEPROMPT - Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file.
; PATHMUSTEXIST - Specifies that the user can type only valid paths and file names.
; READONLY - Causes the Read Only check box to be selected initially when the dialog box is created
; SHOWHELP - Causes the dialog box to display the Help button. The hGui receives the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.
; NOREADONLYRETURN - Specifies that the returned file does not have the Read Only check box selected and is not in a write-protected directory.
; NOTESTFILECREATE - Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network share.
;
; Returns:
; Selected FileName or Emtpy when cancelled. If more then one file is selected they are separated by new line character.
;
CmnDlg_Open( hGui=0, Title="", Filter="", defaultFilter="", Root="", defaultExt="", flags="FILEMUSTEXIST HIDEREADONLY" ) {
static OFN_ALLOWMULTISELECT:=0x200, OFN_CREATEPROMPT:=0x2000, OFN_DONTADDTORECENT:=0x2000000, OFN_EXTENSIONDIFFERENT:=0x400, OFN_FILEMUSTEXIST:=0x1000, OFN_FORCESHOWHIDDEN:=0x10000000, OFN_HIDEREADONLY:=0x4, OFN_NOCHANGEDIR:=0x8, OFN_NODEREFERENCELINKS:=0x100000, OFN_NOVALIDATE:=0x100, OFN_OVERWRITEPROMPT:=0x2, OFN_PATHMUSTEXIST:=0x800, OFN_READONLY:=0x1, OFN_SHOWHELP:=0x10, OFN_NOREADONLYRETURN:=0x8000, OFN_NOTESTFILECREATE:=0x10000
IfEqual, Filter, ,SetEnv, Filter, All Files (*.*)
SplitPath, Root, RootFile, RootDir
hFlags := 0x80000 ;OFN_ENABLEXPLORER always set
loop, parse, flags,%A_TAB%%A_SPACE%,%A_TAB%%A_SPACE%
if A_LoopField !=
hFlags |= OFN_%A_LoopField%
VarSetCapacity( FN, 0xffff )
VarSetCapacity( lpstrFilter, 2*StrLen(filter))
VarSetCapacity( OFN ,90, 0)
if RootFile !=
DllCall("lstrcpyn", "uint", &FN, "uint", &RootFile, "int", StrLen(RootFile)+1)
; Contruct FilterText seperate by \0
delta := 0 ;Used by Loop as Offset
loop, Parse, Filter, |
{
desc := A_LoopField, ext := SubStr(A_LoopField, InStr( A_LoopField,"(" )+1, -1)
lenD := StrLen(A_LoopField)+1, lenE := StrLen(ext)+1 ;including /0
DllCall("lstrcpyn", "uint", &lpstrFilter + delta, "uint", &desc, "int", lenD)
DllCall("lstrcpyn", "uint", &lpstrFilter + delta + lenD, "uint", &ext, "int", lenE)
delta += lenD + lenE
}
NumPut(0, lpstrFilter, delta, "UChar" ) ; Double Zero Termination
; Contruct OPENFILENAME Structure
NumPut( 76, OFN, 0, "UInt" ) ; Length of Structure
NumPut( hGui, OFN, 4, "UInt" ) ; HWND
NumPut( &lpstrFilter, OFN, 12, "UInt" ) ; Pointer to FilterStruc
NumPut( 0, OFN, 16, "UInt" ) ; Pointer to CustomFilter
NumPut( 0, OFN, 20, "UInt" ) ; MaxChars for CustomFilter
NumPut( defaultFilter, OFN, 24, "UInt" ) ; DefaultFilter Pair
NumPut( &FN, OFN, 28, "UInt" ) ; lpstrFile / InitialisationFileName
NumPut( 0xffff, OFN, 32, "UInt" ) ; MaxFile / lpstrFile length
NumPut( 0, OFN, 36, "UInt" ) ; lpstrFileTitle
NumPut( 0, OFN, 40, "UInt" ) ; maxFileTitle
NumPut( &RootDir, OFN, 44, "UInt" ) ; StartDir
NumPut( &Title, OFN, 48, "UInt" ) ; DlgTitle
NumPut( hFlags, OFN, 52, "UInt" ) ; Flags
NumPut( &defaultExt, OFN, 60, "UInt" ) ; DefaultExt
res := (*&hGui = 45) ? DllCall("comdlg32\GetSaveFileNameA", "Uint", &OFN ) : DllCall("comdlg32\GetOpenFileNameA", "Uint", &OFN )
IfEqual, res, 0, return
adr := &FN, f := d := DllCall("MulDiv", "Int", adr, "Int",1, "Int",1, "str"), res := ""
if StrLen(d) != 3 ;windows adds \ when in root of the drive and doesn't do that otherwise
d.="\"
if ms := InStr(flags, "ALLOWMULTISELECT")
loop
if f := DllCall("MulDiv", "Int", adr += StrLen(f)+1, "Int",1, "Int",1, "str")
res .= d f "`n"
else {
IfEqual, A_Index, 1, SetEnv, res, %d%`n ;if user selects only 1 file with multiselect flag, windows ignores this flag....
break
}
return ms ? SubStr(res, 1, -1) : d
}
CmnDlg_Save( hGui=0, Title="", Filter="", defaultFilter="", Root="", defaultExt="", flags="" ) {
return CmnDlg_Open( "-" hGui, Title, Filter, defaultFilter, Root, defaultExt, flags )
}
;
;Group: Examples
;
;Example1:
;
;> ;basic usage
;>
;> if CmnDlg_ChooseIcon(icon, idx := 4)
;> msgbox Icon: %icon%`nIndex: %idx%
;>
;> if CmnDlg_ChooseColor( color := 0xFF00AA )
;> msgbox Color: %color%
;>
;> if CmnDlg_ChooseFont( font := "Courier New", style := "s16 bold underline italic", color:=0x80)
;> msgbox Font: %font%`nStyle: %style%`nColor: %color%
;>
;> res := CmnDlg_Open("", "Select several files", "", "", "c:\Windows\", "", "ALLOWMULTISELECT FILEMUSTEXIST HIDEREADONLY")
;> IfNotEqual, res, , MsgBox, %res%
;>return
;
;Example2:
;> ;create gui and set text color
;>
;> CmnDlg_ChooseFont( font := "Courier New", style := "s16 bold italic", color:=0xFF)
;>
;> Gui Font, %Style% c%Color%, %Font%
;> Gui, Add, Text, ,Hello world..... :roll:
;> Gui, Show, Autosize
;>return
;
;Group: About
; o Ver 4.0 by majkinetor. See http://www.autohotkey.com/forum/topic17230.html
; o Licenced under Creative Commons Attribution-Noncommercial <http://creativecommons.org/licenses/by-nc/3.0/>.