AutoHotkey Community

It is currently May 27th, 2012, 7:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 166 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 12  Next
Author Message
 Post subject:
PostPosted: October 13th, 2006, 5:28 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Laszlo wrote:
Chr(160), which looks like a Space, which cannot name a variable.


I tried typing it directly as well as with x := Chr(160) .. Both work fine.. Thanks! :D

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2006, 7:39 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Laszlo, :)

I would like you to change Chr(128) to Chr(160) in the following post
http://www.autohotkey.com/forum/viewtop ... 3434#83434
as in future I will be pointing it for any future request @ ask-for-help.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


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

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
at your service

(but it is still your script, with a trivial mod)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2006, 7:47 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Laszlo wrote:
at your service


:shock:
:lol:

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2006, 1:23 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
This is an interesting technique. I can't comment on it much without studying it in depth because the conditions under which a variable is created dynamically are fairly complicated.

It might be of interest that you can use VarSetCapacity to retrieve the current capacity of a variable:

capacity := VarSetCapacity(x)

If the capacity is zero, the variable has either never been used or has been explicitly freed by the script (or it's a local variable that hasn't been populated yet by the function's current call).

Some variables have a permanent capacity that cannot be freed. This typically happens for those with a capacity of between 1 and 63 but that have never risen above 63. This enhances performance because the program can avoid having to ever reallocate or free such variables (which can be a costly operation when done thousands of times in a loop). It can also save memory in some cases because it uses a compressed form of memory that has less overhead than traditional dynamic memory.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2006, 10:24 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Thanks for the important and useful information. :)

VarExist() had relevance to the post @ Ask-for-help topic: How to determine if variable exists? by Richard where

Richard as guest wrote:
"Is there a way in autohotkey to determine whether a certain variable exists?"

"I would like to be able to tell the difference between a variable that does not exist and a variable that exists, but has an empty-string for a value."


I am not able to guess where this would be very useful, or how many people would really need it, but is it possible to have in-built function like VarExist() to test Variables ?

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2006, 10:58 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Goyyah wrote:
is it possible to have in-built function like VarExist() to test Variables ?
Would be useful with #MustDeclareVars.
Since there's IsLabel() already I would prefer to have IsVar().

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2006, 11:32 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Titan wrote:
Since there's IsLabel() already I would prefer to have IsVar().


I wanted the function to sound like WinExist().
This is because the function would return the pointer if the variable existed. Since A_??* variables did not have a pointer I chose to return 0,1,2 instead.

IsVar() sounds good!

:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 15th, 2006, 12:42 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Goyyah wrote:
I wanted the function to sound like WinExist().
Me too, one would expect IsLabel(LabelName, Type). In the end, it's Chris' decision.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: SoundCard()
PostPosted: November 10th, 2006, 9:37 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
SoundCard()

Returns the number of soundcards available on a system.
A script can test the target machine for availability of a soundcard before playing an audio file.

Code:
SoundCard() {
Return DllCall("winmm.dll\waveOutGetNumDevs")
}


Example:
Code:
If SoundCard()
   SoundPlay, %A_WinDir%\Media\The Microsoft Sound.wav, wait
Return

SoundCard() {
Return DllCall("winmm.dll\waveOutGetNumDevs")
}


I am surprised to find search does not reveal any requests for this :roll:
Anyways!, :D



PS: For midi one may use DllCall("winmm.dll\midiOutGetNumDevs") to ascertain midi compatibility!

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: AviFileInfo()
PostPosted: November 23rd, 2006, 3:15 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
AviFileInfo()

Returns the video properties of an AVI file as a pipe delimited string.


Here is the function along with a working example:


Code:
; Written by A.N.Suresh Kumar AKA "Goyyah", 23-Nov-2006
; Post: http://www.autohotkey.com/forum/viewtopic.php?p=91036#91036

Loop, %A_WinDir%\*.AVI {

AviFileInfo := AviFileInfo(A_LoopFileLongPath)
StringSplit, Field, AviFileInfo, |

FPS      := (Field8/Field7) ;  FPS is dwRate / dwScale
Duration := FormatSeconds(Round(Field9/FPS,0)) ; Duration is dwLength / FPS

MsgBox, 0, Properties :: %A_LoopFileName%,
(
FileFullPath     `t: %A_LoopFileLongPath%
FileSize         `t: %A_LoopFileSizeKB% KB

MaxBytesPerSec   `t: %Field1%
Flags            `t: %Field2%
Caps             `t: %Field3%
No Of Streams    `t: %Field4%
Sugg. BufferSize `t: %Field5%
Video Size       `t: %Field6%
Frames per second`t: %FPS%
Duration         `t: %Duration%

Scale            `t: %Field7%
Rate             `t: %Field8%
Frames           `t: %Field9%
Edit Count       `t: %Field10%
File Type        `t: %Field11%
)
}
Return

AviFileInfo(AviFile) {
VarSetCapacity( av, 108, 0 )                           ; av = AVIFILEINFO structure
DllCall( "avifil32.dll\AVIFileInit" )
DllCall( "avifil32.dll\AVIFileOpenA", Intp,hFile, Str,AVIFile , Int,0, Int,0 )
DllCall( "avifil32.dll\AVIFileInfoA", Int,hFile, Int,&av, Int,108 )
DllCall( "avifil32.dll\AVIFileRelease", Int,hFile )
mb := (*(&av+ 0))+(*(&av+ 1)<<8)+(*(&av+ 2)<<16)+(*(&av+ 3)<<24) ; dwMaxBytesPerSec
fl := (*(&av+ 4))+(*(&av+ 5)<<8)+(*(&av+ 6)<<16)+(*(&av+ 7)<<24) ; dwFlags
ca := (*(&av+ 8))+(*(&av+ 9)<<8)+(*(&av+10)<<16)+(*(&av+11)<<24) ; dwCaps
st := (*(&av+12))+(*(&av+13)<<8)+(*(&av+14)<<16)+(*(&av+15)<<24) ; dwStreams
sb := (*(&av+16))+(*(&av+17)<<8)+(*(&av+18)<<16)+(*(&av+19)<<24) ; dwSuggBufferSize
wi := (*(&av+20))+(*(&av+21)<<8)+(*(&av+22)<<16)+(*(&av+23)<<24) ; dwWidth
he := (*(&av+24))+(*(&av+25)<<8)+(*(&av+26)<<16)+(*(&av+27)<<24) ; dwHeight
sc := (*(&av+28))+(*(&av+29)<<8)+(*(&av+30)<<16)+(*(&av+31)<<24) ; dwScale
ra := (*(&av+32))+(*(&av+33)<<8)+(*(&av+34)<<16)+(*(&av+35)<<24) ; dwRate
le := (*(&av+36))+(*(&av+37)<<8)+(*(&av+38)<<16)+(*(&av+39)<<24) ; dwLength
ec := (*(&av+40))+(*(&av+41)<<8)+(*(&av+42)<<16)+(*(&av+43)<<24) ; dwEditCount
Loop, 64                                                         
         ft := ft . Chr( *(&av+43+(A_Index)) )                   ; szFileType[64]
Return mb "|" fl "|" ca "|" st "|" sb "|" wi "x" he "|" sc "|" ra "|" le "|" ec "|" ft
}

FormatSeconds(NumberOfSeconds)  { ; Taken from AHK Documentation ( FormatTime )
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    return NumberOfSeconds//3600 ":" mmss 
}


    Snapshots of the message boxes:
    Image______Image

Edit Note: Do not be discouraged by the bit-shifting seen inside the AviFileInfo() function. It is actually easy to modify. You can keep what you want and delete the rest like the example follows:

Code:
AviFileInfo(AviFile) {
VarSetCapacity( av, 108, 0 )                           ; av = AVIFILEINFO structure
DllCall( "avifil32.dll\AVIFileInit" )
DllCall( "avifil32.dll\AVIFileOpenA", Intp,hFile, Str,AVIFile , Int,0, Int,0 )
DllCall( "avifil32.dll\AVIFileInfoA", Int,hFile, Int,&av, Int,108 )
DllCall( "avifil32.dll\AVIFileRelease", Int,hFile )
wi := (*(&av+20))+(*(&av+21)<<8)+(*(&av+22)<<16)+(*(&av+23)<<24) ; dwWidth
he := (*(&av+24))+(*(&av+25)<<8)+(*(&av+26)<<16)+(*(&av+27)<<24) ; dwHeight
Return wi "x" he ; only the video size
}


:)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on December 1st, 2006, 11:57 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2006, 3:43 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Very nice.
I don't see why you didn't wrapped up the field reading in some function (I would have used my GetNextUInt function to even avoid any offset computing), as all these numbers are hard to read and maintain.
Anyway, you uncovered some interesting functions, thanks.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2006, 4:25 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear PhiLho, :)

You wrote:
Very nice.


Thanks! :D

You wrote:
I don't see why you didn't wrapped up the field reading in some function (I would have used my GetNextUInt function to even avoid any offset computing), as all these numbers are hard to read and maintain.


Originally I had used ExtractInteger(), then absorbed it within the function to make it standalone.
I am waiting for ExtractInteger() & InsertInteger() to be built into AHK. :)
I have been playing with pointers a lot these days, and the best is yet to come.

Yes .. It is hard to read .. I will try to do some colouring!

Thanks again & Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: DriveSpaceFreeBytes()
PostPosted: December 1st, 2006, 7:46 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
DriveSpace()

Returns the FreeSpace / Capacity of a Drive in bytes.
Parameter 1 should be a valid drive letter.
Parameter 2 should be 1 for fetching the freespace and 2 for retrieving the drive capacity.


Code:
FreeSpace     := DriveSpace("C:\", 1)
DiskCapacity  := DriveSpace("C:\", 2)
MsgBox, 64,Drive C:, % "FreeSpace`t: " FreeSpace "`nDrive Capacity`t: " DiskCapacity
Return

DriveSpace(Drv="", Free=1) {
DriveGet, Drives, List
StringLeft, Drv, Drv, 1
If (!InStr(Drives,%Drv%))
    Return -1
Drv := Drv . ":\"
VarSetCapacity(SPC, 30, 0)  ; Sectors Per Cluster
VarSetCapacity(BPS, 30, 0)  ; Bytes Per Sector
VarSetCapacity(FC , 30, 0)  ; Free Clusters
VarSetCapacity(TC , 30, 0)  ; Total Clusters
DllCall("GetDiskFreeSpaceA", Str,Drv, UIntp,SPC
                , UIntp,BPS, UIntp,FC, UIntp,TC)
Return Free=1 ? (SPC*BPS*FC) : (SPC*BPS*TC) ; Ternary Operator requires 1.0.46+
}


Requested at Ask For Help Topic : Hard Disk Drive
Thanks to PhiLho. DriveSpaceFreeBytes() was changed to DriveSpace() and now it also retrieves a drive's capacity.


    ** Edit: Function Optimised/Shortened on 04-Nov-2009 **


Code:
DriveSpace( D="C:", M=1) {
If DllCall( "GetDiskFreeSpaceA", Str,Chr(*(&D)) ":", UIntP,S, UIntP,B, UIntP,F, UIntP,T )
   Return M ? (S*B*F) : (S*B*T)
}

FormatByteSize( I=0 ) {
 VarSetCapacity(F,16), DllCall( "shlwapi.dll\StrFormatByteSize64A", Int64,I,Str,F,Int,16 )
Return F
}


Last edited by SKAN on November 4th, 2009, 5:24 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2006, 6:26 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Useful function.
To get total space of disk, use Return SPC * BPS * TC instead of Return SPC * BPS * FC...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 166 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 12  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Cristi®, nothing and 10 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