ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Finally started really using Template.ahk

<< < (2/2)

cranioscopical:
Sometimes I'm a cup short of a coffee or I would have thought of it earlier.
-MilesAhead (June 24, 2011, 02:13 AM)
--- End quote ---

You just need a little sweetener...

40hz:
Sometimes I'm a cup short of a coffee or I would have thought of it earlier.
-MilesAhead (June 24, 2011, 02:13 AM)
--- End quote ---

You just need a little sweetener...
-cranioscopical (June 24, 2011, 01:40 PM)
--- End quote ---

+1 ;D

Sweet dreams and caffeine is what the tech world runs on.

(Not to be confused with three fingers of single-malt Scotch and a dry bowl of Corn Flakes: the REAL "Breakfast of Champions." :P )

MilesAhead:
Miles, maybe you could share the template so that others may have a starting point for their templates? ;)
-jgpaiva (June 24, 2011, 04:32 AM)
--- End quote ---

That's no problem.  Usually if Scite4AHK is installed there's a file in Windows\ShellNew folder called Template.ahk.  Next I have to work on templates for AutoIt3 and FreeBASIC.  Although FB is more likely to be command line unless I start playing around with the dialog resource editors.

Here's my Template.ahk.  Also since it uses a few routines in MilesAhead.ahk I'll include that as it helps to make some things generic.

Template.ahk


--- ---; AutoHotkey Script Template for MilesAhead
;#SingleInstance force
#SingleInstance ignore
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Include MilesAhead.ahk
progname := _FileBaseName(A_ScriptFullPath)
Menu Tray,NoStandard
Menu Tray,Add,Donate,DoDonate
Menu Tray,Add,Visit Hotkey Page,DoVisit
Menu Tray,Add,About,DoAbout
Menu Tray,Add
Menu Tray,Add,Quit,DoQuit
Menu Tray,Default,About
Menu Tray,Tip,%progname%

; boiler plate ini file naming
;
;~ IniFile = %A_ScriptDir%\%A_ScriptName%
;~ IniFile := RegExReplace(IniFile,"i)ahk$","ini")
;~ IniFile := RegExReplace(IniFile,"i)exe$","ini")


;change hotkey and do something here
!+F10::
Return

DoAbout:
  FileGetVersion,filever,%progname%.exe
  MyMsg =
  (
%progname% v %filever% Copyright (c) 2011 www.FavesSoft.com`n
Enter Usage info here`n
  )
  MsgBox, 4160, About %progname%, %MyMsg%
Return

DoDonate:
  Run,"http://www.favessoft.com/donate.html"
Return

DoVisit:
  Run,"http://www.favessoft.com/hotkeys.html"
Return

DoQuit:
  ExitApp

MilesAhead.ahk


--- ---;
; MilesAhead include script with a few system related functions
;

; returns non 0 if program is running
_IsRunning(program)
{
Process,Exist,%program%
Return errorlevel
}

_LoWord(arg)
  {
    Return arg & 0xFFFF
  }

_HiWord(arg)
  {
    Return arg >> 16
  }

_LoByte(arg)
  {
    Return arg & 0x00FF
  }

_HiByte(arg)
  {
    Return (arg & 0xFF00) >> 8
  }

_WinVersionMajor()
  {
    Return _LoByte(_LoWord(DllCall("kernel32.dll\GetVersion", "UInt", -1)))
  }

_WinVersionMinor()
  {
    Return _HiByte(_LoWord(DllCall("kernel32.dll\GetVersion", "UInt", -1)))
  }

_WinVersion()
  {
    dwVersion := DllCall("kernel32.dll\GetVersion", "UInt", -1)
    Return _LoByte(_LoWord(dwVersion)) . "."
    . _HiByte(_LoWord(dwVersion))
  }

;call EmptyWorkingSet in AHK
_EmptyWorkingSet()
  {
    Return DllCall("psapi.dll\EmptyWorkingSet", "UInt", -1)
  }

;reduce memory footprint by calling EmptyWorkingSet
_ReduceMemory()
  {
    If _WinVersionMajor() > 4
    {
      Return _EmptyWorkingSet()
    }
    Return false
  }

;function by HotKeyIt on AHK forums
FormatMessageFromSystem(ErrorCode)
  {
    VarSetCapacity(Buffer, 2000)
    DllCall("FormatMessage"
            , "UInt", 0x1000      ; FORMAT_MESSAGE_FROM_SYSTEM
            , "UInt", 0
            , "UInt", ErrorCode
            , "UInt", 0x800 ;LANG_SYSTEM_DEFAULT (LANG_USER_DEFAULT=0x400)
            , "UInt", &Buffer
            , "UInt", 500
            , "UInt", 0)
    VarSetCapacity(buffer,-1)
    Return Buffer
  }

_GetWorkArea(ByRef left, ByRef top, ByRef right, ByRef bottom)
  {
    VarSetCapacity(work_area,16,0)
    success := DllCall( "SystemParametersInfo", "uint", 0x30, "uint", 0, "uint", &work_area, "uint", 0 )
    If success =
    {
      Return 0
    }
    left := NumGet(work_area,0)
    top := NumGet(work_area,4)
    Right := NumGet(work_area,8)
    Bottom := NumGet(work_area,12)
    Return 1
  }

_MarginWorkArea(ByRef left, ByRef top, ByRef right, ByRef bottom, ByRef margin = 4)
  {
    If _GetWorkArea(left, top, Right, Bottom)
    {
      If Margin is Integer
      {
        If (Margin < 0) or (Margin > 12)
          Margin := 4
      }
      Else
        Margin := 4
      left += Margin
      top += Margin
      Right -= Margin
      Bottom -= Margin
      Return 1
    }
    Return 0
  }

_TaskbarGapArea(ByRef left, ByRef top, ByRef right, ByRef bottom,  percentgap = 5)
{
  _GetWorkArea(left, top, right, bottom)
  If (right - left = A_ScreenWidth) And (bottom - top = A_ScreenHeight)
  {
    Return
  }
  Else If (bottom < A_ScreenHeight)
  {
    bottom -= (bottom // 100 * percentgap)
  }
  Else If (top > 0)
  {
    top += (bottom - top) // 100 * percentgap
  }
  Else If (left > 0)
  {
    left += (right - left) // 100 * percentgap
  }
  Else
 {
    right -= (right - left) // 100 * percentgap
 }
}

_GlassEnabled()
  {
    isEnabled = false
    If _WinVersionMajor() < 6
    {
      Return false
    }
    DllCall("dwmapi.dll\DwmIsCompositionEnabled", "UInt", &isEnabled)
    Return %isEnabled%
  }

_EnableBlurBehind(hwnd)
  {
    VarSetCapacity(struct, 16, 0)
    NumPut(1, struct, 0, "UInt")  ; dwFlags=DWM_BB_Enable
    NumPut(1, struct, 4,  "Int")  ; fEnable=TRUE
    DllCall("dwmapi.dll\DwmEnableBlurBehindWindow", "UInt", hwnd, "UInt", &struct)
  }

;returns string, wrapped in quotes when conataining spaces
_WrapQuotes(str)
  {
    If InStr(str," ")
    {
      str := """" . str . """"
    }
    Return str
  }

_FileBaseName(path)
  {
    SplitPath,path,,,,basename
    Return basename
  }

_FileDir(path)
  {
    SplitPath,path,,fdir
    Return fdir
  }

_FileDirWithSlash(path)
  {
    Return _FileDir(path) . "\"
  }

_CheckForUpdate(url="http://www.favessoft.com/",ininame="FavesVersions.ini")
  {
    urlfile := url . ininame
    localfile := A_ScriptDir . "\" . ininame
    param := _FileBaseName(A_ScriptFullPath)
    If (FileExist(localfile))
    {
      FileDelete,%localfile%
    }
    ;MsgBox, 4160, , localfile is %localfile%
    URLDownloadToFile,%urlfile%,%localfile%
    If ErrorLevel
    {
      MsgBox, 4112, %param%, Server access failed!
      Return
    }
    IniRead,onlinever,%localfile%,Versions,%param%,%A_Space%
    IniRead,zipfile,%localfile%,Downloads,%param%,%A_Space%
    FileGetVersion,localver,%A_ScriptFullPath%
    If localver =
    {
      MsgBox, 4112, %param%, local Version Info Not Found!
      Return
    }
    If onlinever =
    {
      MsgBox, 4112, %param%, Online Version Info Not Found!
      Return
    }
    ;MsgBox, 4160, URLDown Online Verson, %onlinever%
    ;MsgBox, 4160, URLDown local Verson, %localver%

    If (onlinever > localver)
    {
      If zipfile =
      {
        MsgBox, 4112, %param%, Could not determine Download Filename!
        Return
      }
      MsgBox, 0x1024, %param%, Current Version is %localver% : Download %onlinever% ?
      IfMsgBox Yes
      {
        urlfile := url . zipfile
        ziplocalfile := A_ScriptDir . "\" . zipfile
        URLDownloadToFile,%urlfile%,%ziplocalfile%
        If ErrorLevel
        {
          MsgBox, 4112, %param%, Download attempt failed!!
          Return
        }
        Run,%ziplocalfile%
        Run,%A_ScriptDir%
        If (FileExist(localfile))
        {
          FileDelete,%localfile%
        }
        ExitApp
      }
    }
    Else
    {
      MsgBox, 4160, %param%, %localver% is the Latest Version
    }
    If (FileExist(localfile))
    {
      FileDelete,%localfile%
    }
    Return
  }

MilesAhead:
Sometimes I'm a cup short of a coffee or I would have thought of it earlier.
-MilesAhead (June 24, 2011, 02:13 AM)
--- End quote ---

You just need a little sweetener...
-cranioscopical (June 24, 2011, 01:40 PM)
--- End quote ---

Then I'd be sweet AND sour.   heh heh

Navigation

[0] Message Index

[*] Previous page

Go to full version