Since I often start new projects with AHK, I began to work out a certain structure to keep my code organized.
So I've created a template that contains the basic structure for a new project as well as a few standard routines.
I'm not sure if anyone can make use of this (as everyone's got his own style, oviously*), but it provides me with an opportunity to test my new
AutoHotkey.net account...
Anyways, here we go:
Code:
/*
[program name] v[#].[#]
by [author name]
[short description]
*/
/*
To Do:
¯¯¯¯¯¯
- [...]
*/
/*
Revision History
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# v[#].[#] ([yyyy]-[mm]-[dd])
* initial release
*/
/*
********** Settings, Variable Declarations **********
*/
#SingleInstance Force
#NoEnv
OnExit, quit
programName = [program name] ; DEBUG: to do
programVersion = [#].[#] ; DEBUG: to do
programFullName = %programName% v%programVersion%
programAuthor = [author name] ; DEBUG: to do
/*
********** Auto-Execute Section **********
*/
; backup clipboard contents -- DEBUG: optional
clipboardBak := ClipboardAll
; process command line parameters -- DEBUG: optional
GoSub, getParams
; construct tray menu -- DEBUG: optional
GoSub, trayMenu
; end of auto-execute section
Return
/*
********** Hotkeys **********
*/
; DEBUG - note: hotkeys make the script persistent!
; [ALT]+[ESC]: terminate script
!ESC::
Suspend ; exempt from suspension -- DEBUG: optional
GoSub, quit
Return
/*
********** Subroutines **********
*/
; process command line parameters -- DEBUG: optional (see above)
getParams:
If 0 > 0
{
Loop, %0% ; for each parameter
{
param := %A_Index%
; check for switches
StringLeft, paramType, param, 1
If paramType = - ; switch indicator
{
; determine type of switch
StringMid, switch, param, 2, 1
; switch
If switch = x ; DEBUG: template (replace "x")
{
; access value (= next parameter)
param = % A_Index + 1
var_x := %param% ; DEBUG: template (replace "var_x")
}
}
}
}
Return
; construct tray menu -- DEBUG: optional
trayMenu:
; set tray tip
Menu, Tray, Tip, %programFullName%
; disable standard menu items
Menu, Tray, NoStandard
; show info message
Menu, Tray, Add, &About, about
; separator
Menu, Tray, Add
; terminate script
Menu, Tray, Add, &Quit, quit
Return
; show info message -- DEBUG: to do, optional
about:
MsgBox, 64, %programFullName%,
( LTrim
%programFullName%
%A_Space%by %programAuthor%
[short description]
Use [ALT]+[ESC] to terminate the program.
)
Return
; terminate script
quit:
; restore clipboard contents -- DEBUG: optional (see above)
Clipboard := clipboardBak
; terminate script
ExitApp
Return
/*
********** Functions **********
*/
(I'd suggest you make the file read only so you can easily start new projects off of it)
* ... and likely a much better one than my own, since I'm not a very experienced coder at all
UPDATE: (17:00 GMT)
Slightly altered the way command line parameters are processed.
UPDATE: (21:30 GMT)
Added subroutine for processing command line parameters (see
this thread).
UPDATE: (2006-12-01)
Posted the latest version and replaced the link to the file with the actual code.
UPDATE: (2007-07-19)
Another update.
UPDATE: (2007-07-20)
Removed "Join" from
about: routine's
MsgBox (thanks engunneer); fixed typo.