AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

AHK Functions - RandStr()
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Titan



Joined: 11 Aug 2004
Posts: 5112
Location: eth0 ::1

PostPosted: Fri Jan 05, 2007 8:05 pm    Post subject: Reply with quote

Skan wrote:
Can you please explain the difference between Signed and Unsigned Integer. That is one thing I have not been able to figure out
Basically signed integers can have negative values whereas unsigned ones are absolute. Two's compliment explains binary representations, you can use my toBin/toInt functions to experiment: e.g. toInt(111110000001) unsigned = 3969, toInt(111110000001, true) signed = -127.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Fri Jan 05, 2007 8:10 pm    Post subject: Reply with quote

Oh! Thanks Titan .. I forgot about that topic completely..

Smile

Edit: Thanks for that wikipedia link too .. Very Happy
_________________
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sat Jan 06, 2007 11:02 am    Post subject: Reply with quote

Thanks, Titan, for this starter.
A simple example: 16bit unsigned integers can go from 0 to 65535.
16bit signed integers go from -32768 to 32767 (IIRC).
So a number above 32767 used as signed number is seen as negative. Take its absolute value or cast it to a bigger number, and you have a wrong number!
It can make subtle bugs...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Sat Jan 06, 2007 12:00 pm    Post subject: Reply with quote

PhiLho wrote:
- A simple example: 16bit unsigned integers can go from 0 to 65535.
- 16bit signed integers go from -32768 to 32767 (IIRC).
- a number above 32767 used as signed number is seen as negative.
- Take its absolute value or cast it to a bigger number, and you have a wrong number!


Thats is very clear.. Thanks for the useful info. I know now why I should use UInt .. I was using Int because it was shorter Embarassed .
_________________
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Sat Jan 06, 2007 2:48 pm    Post subject: Reply with quote

An explanation one step deeper: In computers machine words contain a number (n) of bits: b[0], b[1]…b[n-1], which are ON or OFF. When operations are performed on these words, they are interpreted as characters, integers, decimal numbers, addresses, etc. When they are interpreted as integers, there are two common conventions:
- Unsigned integers. Bits are interpreted as 0/1 binary digits: b[i] * 2**i, so a bit sequence of 1010 means 2**3+2**1 = 10. Number = SUM(i=0..n-1, b[i] * 2**i). The smallest unsigned integer is 0, the largest one is 1+2+4+…=2**n - 1.
- Two's complement signed integers. Bits are interpreted as 0/1 binary digits except the leftmost one b[n-1], which is interpreted as a negative binary digit, -b[n-1]*2**(n-1): Number = SUM(i=0..n-2, b[i] * 2**i) - b[n-1] * 2**(n-1). A bit sequence 10001100 interpreted as 8-bit signed number is -2**7 + 2**3 + 2**2 = -128+8+4 = -116. The smallest signed integer is "1000…" = -2**(n-1), the largest one is "0111…" = 2**(n-1) - 1.

When you choose INT or UINT (or CHAR, or FLOAT…), you tell the computer how to interpret the bunch of bits in the corresponding machine word.
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Sat Jan 06, 2007 5:40 pm    Post subject: Reply with quote

Thank you Sir. Very Happy
_________________
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Thu Feb 01, 2007 8:02 pm    Post subject: ChooseColor() ( w/ Custom Colors support ) Reply with quote

Quote:
ChooseColor()

Quote:
Credit:
This standalone version of ChooseColor is based on majkinetor's work .. Thanks!
Scripts & Functions Topic : ChooseColor wrapper

Also refer:
Ask-for-Help Topic : How to call the standard Choose-Color-dialog? - Micha


ChooseColor() is a 45 line standalone wrapper function to call the built-in windows ChooseColor Dialog. This version of ChooseColor wrapper additionally saves the Custom Colors ( if any selected ) to the default file named CUSTOMCOLOR.BIN into the Windows folder.

Usage : ChooseColor( Color, hPar, ccFile)

  • The function returns the hex color code ( in R G B format ) or -1 if the dialog was cancelled with close button or if escape was pressed.

  • The first parameter may contain a valid color code ( in R G B format ) to initialise a default selected color on the dialog.

  • The dialog opens @ coordinates 0,0 relative to the window ID passed as the parameter 2. If parameter 2 is null/void, Desktop is assumed to be the parent window.

  • Only 16 different colors can be saved as Custom Colors. Parameter 3 facilitates to specify a different filename so that additional Custom color files can be maintained to overcome this limit.

MSDN Reference : ChooseColor Function, CHOOSECOLOR Structure

The function along with a test demo:

Code:
Gui, Add, Button, x200 y275 w150 gChangeBG, Change BackGround Color
Gui, Show, , ChooseColor() Demo
Return

ChangeBG:
 GuiColor := ChooseColor( GuiColor, WinExist() )
 IfGreaterOrEqual,GuiColor,0, Gui,Color,%GuiColor%
Return

GuiClose:
 ExitApp
Return


ChooseColor( Color=0x0, hPar=0x0, ccFile="")  {
Color := SubStr(Color,1,2)="0x" ? Color : "0x" Color      ; Check & Prefix Color with "0x"
VarSetCapacity(CHOOSECOLOR, 36, 0) , mainPtr := (&CHOOSECOLOR)     ; Create Main structure
DllCall( "RtlFillMemory", UInt,mainPtr+0, Int,1, UChar,36 ) ; Insert size of the Structure

hPar := WinExist(ahk_id %hPar%) ; Validate the passed Parent window ID
; Break Parent window ID into 4 bytes
H1 := hPar>>0 & 255,   H2 := hPar>>8 & 255,   H3 := hPar>>16 & 255,   H4 := hPar>>24 & 255
Loop 4                       ; Insert Parent window ID to CHOOSECOLOR structure @ Offset 4
  DllCall( "RtlFillMemory", UInt,mainPtr+3+A_Index, Int,1, UChar,H%A_Index% )

; Break Color into R,G and B values
RGB1 := Color>>16 & 255,    RGB2 := Color>>8  & 255,    RGB3 := Color>>0  & 255
Loop 3                      ; Insert R,G and B values to CHOOSECOLOR structure @ Offset 12
  DllCall( "RtlFillMemory", UInt,mainPtr+11+A_Index, Int,1, UChar,RGB%A_Index% )

; CustomColors ( CUS1 will be primary array and CUS2 will be a copy to detect any change )
VarSetCapacity(CUS1, 64, 0),   aPtr := (&CUS1),   VarSetCapacity(CUS2, 64, 0)
IfEqual,ccFile,, SetEnv,ccFile,%A_WinDir%\CUSTOMCOLOR.BIN ; Assign default save filename
IfExist,%ccFile%,  FileRead,CUS1, *m64 %ccFile%           ; Array CUS1 will be overwritten
Loop 64                                                   ; Copy data from CUS1 to CUS2
 oS:=A_Index-1, DllCall( "RtlFillMemory", UInt,&CUS2+oS, Int,1, UChar,*(&CUS1+oS) )
A1 := aPtr>>0 & 255,   A2 := aPtr>>8 & 255,   A3 := aPtr>>16 & 255,   A4 := aPtr>>24 & 255
Loop 4        ; Insert pointer to Custom colors array to CHOOSECOLOR structure @ Offset 16
   DllCall( "RtlFillMemory", UInt,mainPtr+15+A_Index, Int,1, UChar,A%A_Index% )

; Insert Integer 259 @ Offset 21 (259 is CC_RGBINIT + CC_FULLOPEN + CC_ANYCOLOR )
DllCall( "RtlFillMemory", UInt,mainPtr+20, Int,1,UChar,3  ) ; CC_RGBINIT=1 + CC_FULLOPEN=2
DllCall( "RtlFillMemory", UInt,mainPtr+21, Int,1,UChar,1  ) ; CC_ANYCOLOR=256

If ! DllCall("comdlg32\ChooseColorA", str, CHOOSECOLOR) OR errorLevel   ; Call ChooseColor
     Return -1            ; and return -1 in case of an error or if no color was selected.

Loop 64 ; Compare data CUS2 and CUS1, if custom color changed, then save array to BIN file
  If ( *(&CUS1+A_Index-1) != *(&CUS2+A_Index-1) )   {       ; Check byte by byte
       h := DllCall( "_lcreat", Str,ccFile, Int,0 )         ; Overwrite/create file
            DllCall( "_lwrite", UInt,h, Str,CUS1, Int,64 )  ; write the array,
            DllCall( "_lclose", UInt,h )                    ; close the file,
            Break                                           ; break the loop.
                                                    } 
Hex := "123456789ABCDEF0",   RGB := mainPtr+11
Loop 3 ; Extract nibbles directly from main structure and convert it into Hex (initd. abv)
  HexColorCode .=  SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
Return HexColorCode ; finally ... phew!
}


Note: This function looks very cryptic as I prefer my functions to be standalone/self-contained. I hope InsertInteger() / ExtractInteger are built into AHK in near future.

Smile




** Compact Version ** 2008-06-17

Code:
ChooseColor( Clr=0x0, Par=0x0 )  {
 Hex:="123456789ABCDEF0",     VarSetCapacity(CC,36,0), RGB:=&CC+11, VarSetCapacity(D,64,0)
 NumPut(36,CC,0), NumPut(Par,CC,4), NumPut(Clr,CC,12), NumPut(&D,CC,16), NumPut(259,CC,20)
 If ! DllCall( "comdlg32\ChooseColorA", str,CC ) OR ErrorLevel
   Return -1
 Loop 3
   HexCC .=  SubStr(Hex, (*++RGB >> 4), 1) . SubStr(Hex, (*RGB & 15), 1)
Return HexCC
}


Last edited by SKAN on Tue Jun 17, 2008 12:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Thu Jul 05, 2007 10:54 pm    Post subject: Re: AviFileInfo() Reply with quote

Quote:
ShellFileOperation() - Basic Wrapper

A shell function that can be called to Copy / Move / Delete / Rename File(s). Displays an animated progress bar if the task is time consuming. Progress bar is useful when operating on slower media like Digital Cameras or when dealing with huge files like video.
I have wrapped only the basic functionality. Hopefully, I should be updating it in near future. For customised needs refer MSDN.



Parameters:

The first parameter can be only one of the following:
Code:
FO_MOVE   := 0x1
FO_COPY   := 0x2
FO_DELETE := 0x3
FO_RENAME := 0x4


The Second / Third parameters should be strings containing path to Source and Destination
Source may contain Wildcards but not Target
Source can be a list of files delimited with pipe. ( The wrapper function replaces pipe characters with NULL )
Always use fullpath and not relative.

The fouth parameter can contain a combination of values for which please refer MSDN

Usage Examples:

Code:
ShellFileOperation( 0x2, A_AhkPath, A_DeskTop )                     ; Copy a Single file
ShellFileOperation( 0x2, "C:\Program Files\AutoHotkey", A_DeskTop ) ; Copy the whole folder


Advanced Example: ( Along with the wrapped Shell Function )

The following code performs a recursive scan on the Temporary Internet Files folder and creates a pipe delimited list of .gif files and passes it to the wrapper function which copies the files to the script's subfolder named Gif_Files.

Code:
SetBatchLines -1
SetWorkingDir, %A_ScriptDir%

imgPath := A_Temp . "orary Internet Files"
Loop, %imgPath%\*.gif, 0 ,1
     Source .= A_LoopFileLongPath "|"

Target := A_ScriptDir "\Gif_Files"

flags := ( FOF_RENAMEONCOLLISION := 0x8 ) | ( FOF_NOCONFIRMMKDIR := 0x200 )

ShellFileOperation( 0x2, Source, Target, flags )

Return



ShellFileOperation( fileO=0x0, fSource="", fTarget="", flags=0x0, ghwnd=0x0 )     {

 If ( SubStr(fSource,0) != "|" )
      fSource := fSource . "|"

 If ( SubStr(fTarget,0) != "|" )
      fTarget := fTarget . "|"

 fsPtr := &fSource
 Loop, % StrLen(fSource)
  If ( *(fsPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, fsPtr+(A_Index-1), Int,1, UChar,0 )

 ftPtr := &fTarget
 Loop, % StrLen(fTarget)
  If ( *(ftPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, ftPtr+(A_Index-1), Int,1, UChar,0 )

 VarSetCapacity( SHFILEOPSTRUCT, 30, 0 )                 ; Encoding SHFILEOPSTRUCT
 NextOffset := NumPut( ghwnd, &SHFILEOPSTRUCT )          ; hWnd of calling GUI
 NextOffset := NumPut( fileO, NextOffset+0    )          ; File operation
 NextOffset := NumPut( fsPtr, NextOffset+0    )          ; Source file / pattern
 NextOffset := NumPut( ftPtr, NextOffset+0    )          ; Target file / folder
 NextOffset := NumPut( flags, NextOffset+0, 0, "Short" ) ; options

 DllCall( "Shell32\SHFileOperationA", UInt,&SHFILEOPSTRUCT )
 
Return NumGet( NextOffset+0 )
}


The flag FOF_NOCONFIRMMKDIR supresses the user confirmation for subfolder creation and FOF_RENAMEONCOLLISION takes care of renaming similar filenames.

FOF_RENAMEONCOLLISION: For example I recursively scanned for README.TXT in drive C: and I had a list of 667 files. When copied to the same folder with FOF_RENAMEONCOLLISION, The 1st file was README.TXT, 2nd file was Copy of README.TXT, 3rd file was Copy (1) of README.TXT ... and the last file was Copy (665) of README.TXT

Note: You see a progress bar only if the above takes more than a couple of seconds

Anybody interested Question

Smile
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4032
Location: Pittsburgh

PostPosted: Fri Jul 06, 2007 12:35 am    Post subject: Re: AviFileInfo() Reply with quote

Really nice!
Skan wrote:
Anybody interested Question
Always!
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1359

PostPosted: Fri Jul 06, 2007 2:08 am    Post subject: Re: AviFileInfo() Reply with quote

Laszlo wrote:
Skan wrote:
Anybody interested Question
Always!
Ditto!
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5112
Location: eth0 ::1

PostPosted: Fri Jul 06, 2007 10:24 am    Post subject: Reply with quote

I move around a lot of large files in my backup scripts and what annoys me is that a Progess looks too tacky and Gui requires more code so I never bothered to do either, I wait for the script to exit or use MsgBox. Your function makes things much easier and meets all my needs - cancel button, force overwright etc. so thank you.
_________________

RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Sun Jul 08, 2007 2:53 pm    Post subject: Reply with quote

Thanks to all! Very Happy

Back in FEB 2005 when I had bought my Digital Camera, I was using DOS BAT to move files from the memory stick. When I googled for a tool that could do BATCH in Windows, first I found the WinBatch ( Not free! ) and then further search led me to AutoHotkey ( I heard about AutoIt only from AHK doc and then from our forum! )

Actually I wanted to go after CopyFileEx / MoveFileEx after the much awaited Callback facility was implemented while ShFileOperation() function was always there Exclamation Surprised

ShFileOperation() is a good candidate for StdLib as the basic flags should work even with Windows 95. But documenting it with easy-to-understand language is tougher than the wrapper itself! Sad

Thanks again Smile
Back to top
View user's profile Send private message
Hardeep



Joined: 02 Jul 2006
Posts: 87

PostPosted: Tue Jul 24, 2007 8:36 pm    Post subject: Reply with quote

Nice work Skan...very useful contributions Cool
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6075

PostPosted: Tue Jul 24, 2007 10:30 pm    Post subject: Reply with quote

Hardeep wrote:
Nice work Skan...very useful contributions Cool


Thanks! Very Happy
Nice to hear from you.

Smile
Back to top
View user's profile Send private message
Yogui
Guest





PostPosted: Fri Mar 07, 2008 1:41 am    Post subject: ahk_id for Coping... Moving... etc in Win Explorer Reply with quote

Hi Skan and Forum,

Thanks for the ShellFileOperation funtion is great!!!

Question:
Is there a way to determinate the ahk_id of the window Coping... Moving... etc in Win Explorer that show the progress before (or after but I rather have it before) ShellFileOperation is called.

At the moment I'm using a Hotkey over the coping... Win and I gt the ID store on ""UNDER_HOTKEY_WIN_ID" on My Script

I like to apply the following subroutine to that win whithout clicking on it:

Code:

MCDR_WIN_SET_TRANSPARENCY_ON:

WinSet, Transparent, 200, ahk_id %UNDER_HOTKEY_WIN_ID%

ControlGetPos, CONTROL_0_X, CONTROL_0_Y, CONTROL_0_W, CONTROL_0_H, SysAnimate321, ahk_id %UNDER_HOTKEY_WIN_ID%
ControlGetPos, CONTROL_1_X, CONTROL_1_Y, CONTROL_1_W, CONTROL_1_H, Button1, ahk_id %UNDER_HOTKEY_WIN_ID%

WinGetPos, WIN_X, WIN_Y, WIN_W, WIN_H, ahk_id %UNDER_HOTKEY_WIN_ID%

X0 := CONTROL_0_X - 6
Y0 := CONTROL_0_Y + CONTROL_0_H - 1               ;MAY NEED ADJUSTMENTS IF SYS FONT IS NOT DEFAULT ETC

X1 := CONTROL_1_X - X0
Y1 := CONTROL_1_Y + CONTROL_1_H - Y0 + 14

WinSet, Region, %X0%-%Y0% W%X1% H%Y1% R20-20, ahk_id %UNDER_HOTKEY_WIN_ID%

MCRD_WIN_ENABLED = 0

WinGet, MCDR_WIN_GROUP_ID_LIST, list, ahk_group MCDR_WIN_GROUP

Loop, %MCDR_WIN_GROUP_ID_LIST%
   {
   ControlGet, MCRD_WIN_ENABLED, Enabled, , Button1, ahk_id MCDR_WIN_GROUP_ID_LIST%A_Index%
   MCRD_WIN_ENABLED += MCRD_WIN_ENABLED         ;ZERO ID DISABLE
   }
   
MCRD_WIN_DISABLED := MCDR_WIN_GROUP_ID_LIST - MCRD_WIN_ENABLED
   
WIN_MOVE_X := MonitorWorkArea1Right - X0 - X1
WIN_MOVE_Y := MonitorWorkArea1Bottom - Y0 - (Y1 * MCRD_WIN_DISABLED)       ;MULT BY THE NUMBER OF MCDR WINS

WinMove, ahk_id %UNDER_HOTKEY_WIN_ID%, , WIN_MOVE_X,  WIN_MOVE_Y

Control, Disable, , Button1, ahk_id %UNDER_HOTKEY_WIN_ID%
WinSet, AlwaysOnTop, On, ahk_id %UNDER_HOTKEY_WIN_ID%

;ListVars
   
Return


Then the hotkey again will check the button is disabled and GoSub,
Code:

MCDR_WIN_SET_TRANSPARENCY_OFF:
WinSet, TransColor, Off, ahk_id %UNDER_HOTKEY_WIN_ID%
Control, Enable, , Button1, ahk_id %UNDER_HOTKEY_WIN_ID%
WinSet, Region, , ahk_id %UNDER_HOTKEY_WIN_ID%
WinMove, ahk_id %UNDER_HOTKEY_WIN_ID%, , (A_ScreenWidth/2)-(WIN_W/2), (A_ScreenHeight/2)-(WIN_H/2)
Return


Thanks Again!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 6 of 7

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group