Thursday, February 23, 2012

AutoHotkey

Alternative method of displaying Unicode in Autohotkey GUI

Well yes you could just use the Unicode version of Autohotkey. If you're looking for some up and down arrows which is all I wanted, then you don't have to use Unicode and you can use the Chr() function:

msgbox % Chr(24) ; upwards arrow
msgbox % Chr(25) ; downwards arrow, unstable

 

Fun with DllCall in AutoHotkey

Ok so there are more fun things to do out there. If you're the type of AutoHotkey programmer that doesn't like having to use the command prompt to write to an extra text file which your program has to read, then this is for you. DllCall will usually run contained in the program and can be hidden from the end-user.

The one to rule them all:
This is a function I pulled from the Autohotkey forums submitted by SKAN which lists all the functions for a specified Dynamic Link Library (DLL) along with an inputbox for convenience:
InputBox, FunctionToDo, DLL File, Enter the name of the DLL file you want to (suffix with .dll):,,500,120,,,,,shell32.dll
If not ErrorLevel {
	ThisData:=PE_FunctionExports( FunctionToDo )
	IfExist, %A_Temp%\delete_me.txt
		FileDelete, %A_Temp%\delete_me.txt
	FileAppend, %ThisData%, %A_Temp%\delete_me.txt
	RunWait, %A_Temp%\delete_me.txt
}
PE_FunctionExports( PEFile ) {
	; Lists Exported Functions/ Comp@t: WIN32_NT +AHK +LA +LW
	;By SKAN www.autohotkey.com/forum/viewtopic.php?p=379086#379086 CD:20100824/LM:20100825

	VarSetCapacity( $LI,48,0 ), DllCall( "ImageHlp\MapAndLoad", A_IsUnicode ? "AStr" : "Str",PEFile, Int,0, UInt,&$LI, Int,1, Int,1 )
	nPtr := DllCall( "ImageHlp\ImageRvaToVa", UInt,Numget( $LI,12 ), UInt,Numget( $LI,08 ), UInt, NumGet( ( P := DllCall( "ImageHlp\ImageDirectoryEntryToData", UInt, NumGet( $LI,8 ), Int,0, UShort,0, UIntP,nSz )) + 12 ), UInt,0 )
	VarSetCapacity( Var,1024,0 ), VarSetCapacity( List,10240,0 )
	IfEqual,nPtr,0, Return SubStr( DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI ), 0,0 )
	Loop % NumGet( P+24 ) + 1
		A_IsUnicode ? Var := DllCall( "MulDiv", Int,nPtr, Int,1, Int,1, AStr ) : DllCall( "lstrcpy", Str,Var, UInt,nPtr ), nPtr := nPtr+StrLen( Var )+1,  List .= "`n" Var, A_Index=1 ? Omit := StrLen( Var )+2 : StringTrimLeft, List, List, %Omit%
	DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI )
	Return List
}
ExitApp


Examples of DllCall'ing:
// get number of network card interfaces
DllCall("iphlpapi\GetNumberOfInterfaces", "UintP", nIf)
MsgBox % nIf
...
// get current process ID
ProcessID := DllCall("GetCurrentProcessId")
   

Functions to convert Hex 2 RGB and vice-versa

These are for autohotkey and in AHK code. Taken from Autohotkey forums topic 1878:

  • From Hexadecimal to RGB
  • From RGB to Hexadecimal
  • Check for a valid hexadecimal value

   

AutoHotkey Format Date and Format Seconds

As you can tell these are my messed up functions that convert dates into seconds and vice-versa. They're a little disorganised but they're the ones I copy and paste to my scripts then modify.

In it's straightforward form
FormatTime( TimeString, Format )
{
     FormatTime, FormattedTime , TimeString, %Format% 
     return Formattedtime
}


   

Format Numbers in AutoHotkey with Commas

Just a quick note as I use this function in various scripts. This adds the 1000th separator comma:

    	FormatAddCommas(val) {
    		Result:=val
    		StringLen, OutputVar, Result
    		NumLoop := (OutputVar // 3)
    		DNum = 3
    		Loop, % (NumLoop+1)
    		{
    		   StringRight,Digit,Result,%DNum%
    		   StringReplace, Result, Result, %Digit%,`,%Digit%
    		   DNum += 4
    		}
    		StringLen, OutputVar, Result
    		Loop, %OutputVar%
    		{
    			FirstChar:=Substr(Result, 1, 1)
    			IfEqual, FirstChar, `,
    			{
    				Result:=Substr(Result, 2)
    			} else {
    				break
    			}
    		}
    		Return Result
    	}
Use as per usual:
      ValueWithCommas:=FormatAddCommas(NumberWithoutCommas)


One taken from the AutoHotkey forums:
	AddCommas(val)
	{
	  val:= RegExReplace(val, "(\d)(?=(?:\d{3})+(?:\.|$))", "$1,")
	  Return val
 	}

Another not tested:
	AddCommas(val)
	{
	  val:= RegExReplace(val, "(?(?<=\.)(*COMMIT)(*FAIL))\d(?=(\d{3})+(\D|$))", "$0,")
	  Return val
 	}
 

And finally PhiLho's:
CommaAdd(num) {

  VarSetCapacity(fNum,32)
  DllCall("GetNumberFormat",UInt,0x0409,UInt,0,Str,Num,UInt,0,Str,fNum,Int,32)
  return SubStr(fNum,1,StrLen(fNum) - 3)

}
   

Page 1 of 3

Member Login

Joes Latest Members

A huge WELCOME goes to today's newest members:

  • Rovadisa
  • usardet
  • sirisoma
  • ezdating+in+germanyd2
Member Signups (Activated)
BeforeCurrentTrend
Day24é
Week3216=
Month201106ê
Year2,265307ê

Member Stats
87 guests are currently online.
1,101 members are still deciding.
There are 5,553 members in total.

Latest Comments

Paypal Donations

Want to support my work? Any donation is a blessing :c)