AutoHotkey Community

It is currently May 25th, 2012, 11:52 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: January 23rd, 2006, 4:53 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
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.


Last edited by Ace_NoOne on August 3rd, 2007, 10:35 pm, edited 8 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2006, 8:37 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Thank you for sharing. It is always good practice to have a template. I hope new users will accept this help and learn from it.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2006, 9:13 pm 
Offline

Joined: March 11th, 2006, 12:44 pm
Posts: 341
Location: Munich, Germany
hi, the post is quite old, but the idea of using a template to start an ahk script instead of scratch is good.
i would also add a section for configuration, as i realize its quite important to have user-configuration when you compile your script and the user cannot change the config easily in sourcecode.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 19th, 2007, 7:58 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
I have (again) updated the original template and edited the initial posting accordingly.

holomind wrote:
hi, the post is quite old, but the idea of using a template to start an ahk script instead of scratch is good.
That's what I thought... ;)
holomind wrote:
i would also add a section for configuration, as i realize its quite important to have user-configuration when you compile your script and the user cannot change the config easily in sourcecode.
Well, I usually use external files for any user settings if required; the built-in IniRead makes that quite easy.
However, feel free to create your own version of this template if you like.

_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 5:38 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8647
Location: Salem, MA
you should remove the Join from the about box
Code:
; show info message -- DEBUG: to do, otpional
about:
   MsgBox, 64, %programFullName%,
   ( LTrim
      %programFullName%
      %A_Space%by %programAuthor%
     
      [short description]
     
      Use [ALT]+[ESC] to terminate the program.
   )
Return


then you don't have to have `n everywhere

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 6:07 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
engunneer wrote:
you should remove the Join from the about box
[snip]
then you don't have to have `n everywhere
Good catch - why didn't I think of that?! (Probably a remnant from my earlier days... )
Done.

Thanks!

_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 6:33 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8647
Location: Salem, MA
I also tend to keep settings in an INI file alot - maybe you can add a rough outline of generic ini reading?

I usually write mine from scratch each time, but I have seen functions posted in the forum that read every setting from the ini file automagically.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 7:46 pm 
Offline

Joined: October 10th, 2005, 10:44 am
Posts: 299
Location: Germany
engunneer wrote:
I also tend to keep settings in an INI file alot - maybe you can add a rough outline of generic ini reading?

I usually write mine from scratch each time, but I have seen functions posted in the forum that read every setting from the ini file automagically.
I write mine from scratch too - and to be honest, I usually like it that way.
IniWrite is extremely easy to use, so I don't see much of a benefit there.

However, feel free to create a fork - if I like it, I might be tempted to adopt it after all...

_________________
Improving my world, one script at a time.
Join the AutoHotkey IRC channel: irc.freenode.net #autohotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 20th, 2007, 10:32 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Ive just added somefunctions for loading and saving ini files.

see here

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: JamixZol, Rajat, stevep and 13 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