I have encountered strange results, which may be a bug when using my script with 125% font size which is 120 DPI. Im usually using AHK_H on Win7 32-bit, but get the same results with AHK 1.1.16.05. The strange results are radiobuttons and checkboxes has irregular/unsymetrical y spacing between them in my gui script. Testing the same script with 96 and 144 DPI the spacing is perfectly symetrical. The problem only occurs when using 120 DPI and are specifical visible between radiobuttons. Perhaps there is a bug in the AHK 120 DPI-awareness code?
This is the script you can test with:
Spoiler
Add some source and destination folders and some shows to your liking or use this ini, which should be saved and placed in the same folder as the script.
Code: Select all
#NoEnv
SetWinDelay, -1
CopyMessage := 0x0205 ; WM_RBUTTONUP := 0x0205, WM_RBUTTONDBLCLK := 0x0206
MaxShowsPerColumn := "15" ; max number of rows per column for show checkboxes
DefOverWrite := False ; default status of the overwrite checkbox
DefMinSize := 1048576 * 4 ; default minimum file size to use the progress routine (4 MB)
CBFunc := RegisterCallback("FileProgressCB" . (A_PtrSize = 8 ? "64" : "32"))
GuiTitle := "Copy/Move Files"
Clipboard := ""
; ======================================================================================================================
; INI
SettingsIni := A_ScriptDir . "\Settings.ini" ; INI file
IniRead, sfolders, %SettingsIni%, Source_Folders, Key, %A_Space%
IniRead, dfolders, %SettingsIni%, Destination_Folders, Key, %A_Space%
IniRead, titles, %SettingsIni%, Show_titles_name, Key, %A_Space%
If (sFolders = "") || (dFolders = "") || (titles = "")
{
GoSub, EditIni
Reload
ExitApp
}
; ----------------------------------------------------------------------------------------------------------------------
Source_Folders := {}
Source_Folders_num := []
for i, sfolder in StrSplit(sfolders, "|") {
Source_Folders_num.Insert(sfolder)
Source_Folders[sfolder] := false
}
Destination_Folders := {}
Destination_Folders_num := []
for i, dfolder in StrSplit(dfolders, "|") {
Destination_Folders_num.Insert(dfolder)
Destination_Folders[dfolder] := false
}
Show_titles_name := {}
for i, title in StrSplit(titles, "|")
Show_titles_name[title] := false
Show_titles_num := []
for title in Show_titles_name
Show_titles_num.Insert(title)
; ======================================================================================================================
; (Re)Create the main GUI
CreateMainGui:
CopyControls := {}
Gui, SelectGui:New, +LabelSelectGui
Gui, Font, s8 w500, Arial
; ----------------------------------------------------------------------------------------------------------------------
; Source folders
GBControls := ""
for index, sfolder in Source_Folders_num ; create the Radios as a radio group
{
IsChecked := Source_Folders[sfolder]
Options := A_Index = 1 ? "ym Section vSrcRadios" : "xs y+2"
Gui, Add, Radio, %Options% Checked%IsChecked% hwndHSrcRadio, % sfolder
GBControls .= "|" . HSrcRadio
CopyControls[HSrcRadio + 0] := sfolder
}
GroupBox("GB1", "Source Folders", 10, 10, SubStr(GBControls, 2), 110)
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Radio, ym vCopy Checked, Copy
Gui, Add, Radio, y+2 vMove, Move
GroupBox("GB2", "Copy or Move", 10, 10, "Copy|Move", 90)
; ----------------------------------------------------------------------------------------------------------------------
; Destination folders
GBControls := ""
for index, dfolder in Destination_Folders_num ; create the Radios as a radio group
{
IsChecked := Destination_Folders[dfolder]
Options := A_Index = 1 ? "ym Section vDstRadios" : "xs y+2"
Gui, Add, Radio, %Options% Checked%IsChecked% hwndHDstRadio, % dfolder
GBControls .= "|" . HDstRadio
CopyControls[HDstRadio + 0] := dfolder
}
GroupBox("GB3", "Destination Folders", 10, 10, SubStr(GBControls, 2), 110)
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Edit, xm w123 vNewRecFolder,
Gui, Add, Button, x+5 yp w40 hp vAddNewRecFolder gAddNewRecFolder, +
GroupBox("GB4", "Add New Source Folder", 10, 10, "NewRecFolder|AddNewRecFolder")
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Edit, yp x+10 w124 vNewBackupFolder,
Gui, Add, Button, x+5 yp w40 hp vAddNewBackupFolder gAddNewBackupFolder, +
GroupBox("GB5", "Add New Destination Folder", 10, 10, "NewBackupFolder|AddNewBackupFolder")
; ----------------------------------------------------------------------------------------------------------------------
; Shows
GBControls := ""
for index, title in Show_titles_num
{
IsChecked := Show_titles_name[title]
Options := A_Index = 1 ? "xm Section" : (Mod(A_Index, MaxShowsPerColumn) = 1) ? "ys Section" : "xs y+2"
Gui, Add, Checkbox, %Options% Checked%IsChecked% vShowCB%index% hwndHShowCB gCheckShow, % title
GBControls .= "|ShowCB" . index
CopyControls[HShowCB + 0] := title
}
GroupBox("GB6", "Shows", 10, 10, SubStr(GBControls, 2), 200)
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Edit, w123 vNewShowControl,
Gui, Add, Button, x+5 yp w40 hp vAddShowControl gAddShowControl, +
GroupBox("GB7", "Add New Show", 10, 10, "NewShowControl|AddShowControl")
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Edit, yp x+10 w124 vDeleteControl,
Gui, Add, Button, x+5 yp w40 hp vDeleteControlButton gDeleteControlButton, –
GroupBox("GB8", "Delete Folders or Shows", 10, 10, "DeleteControl|DeleteControlButton")
; ----------------------------------------------------------------------------------------------------------------------
Gui, Add, Button, xm w389 vLaunchMove gLaunchMove Default, C o p y / &M o v e
Gui, Show, , % GuiTitle
; ----------------------------------------------------------------------------------------------------------------------
OnMessage(CopyMessage, "CopyContent")
Return
; ======================================================================================================================
CopyContent(W, L, M, H) {
Global CopyControls
If (A_Gui = "SelectGui") && (Caption := CopyControls[H])
{
Clipboard := Caption
ToolTip, % Clipboard . "`nwas copied to the clipboard!"
SetTimer, ToolTipTimeout, -1000
Return 0
}
}
ToolTipTimeout:
ToolTip
Return
;-----------------------------------------------------------------------------------------------------------------------
SelectGuiClose:
SelectGuiEscape:
ExitApp
;-----------------------------------------------------------------------------------------------------------------------
CheckShow:
GuiControlGet, IsChecked,, % A_GuiControl
index := SubStr(A_GuiControl, 7)
if IsChecked
Show_titles_name[Show_titles_num[index]] := true
else
Show_titles_name[Show_titles_num[index]] := false
return
;-----------------------------------------------------------------------------------------------------------------------
AddNewRecFolder:
GuiControlGet, NewRecFolder,, NewRecFolder
if NewRecFolder=
return
if Source_Folders.HasKey(NewRecFolder)
{
MsgBox, 0, %GuiTitle%, % "Sourcefolder '" NewRecFolder "' already exists"
return
}
Source_Folders_num.Insert(NewRecFolder)
Source_Folders[NewRecFolder] := false
sfolders := ""
for i, sfolder in Source_Folders_num
sfolders .= sfolder "|"
IniWrite, % RTrim(sfolders, "|"), %SettingsIni%, Source_Folders, Key
gosub, CreateMainGui
return
;-----------------------------------------------------------------------------------------------------------------------
AddNewBackupFolder:
GuiControlGet, NewBackupFolder,, NewBackupFolder
if NewBackupFolder=
return
if Destination_Folders.HasKey(NewBackupFolder)
{
MsgBox, 0, %GuiTitle%, % "Sourcefolder '" NewBackupFolder "' already exists"
return
}
Destination_Folders_num.Insert(NewBackupFolder)
Destination_Folders[NewBackupFolder] := false
dfolders := ""
for i, dfolder in Destination_Folders_num
dfolders .= dfolder "|"
IniWrite, % RTrim(dfolders, "|"), %SettingsIni%, Destination_Folders, Key
gosub, CreateMainGui
return
;-----------------------------------------------------------------------------------------------------------------------
AddShowControl:
GuiControlGet, NewShowControl,, NewShowControl
if NewShowControl=
return
if Show_titles_name.HasKey(NewShowControl)
{
MsgBox, 0, %GuiTitle%, % "Show title '" NewShowControl "' already exists"
return
}
Show_titles_name[NewShowControl] := false
titles := ""
Show_titles_num := []
for title in Show_titles_name {
Show_titles_num.Insert(title)
titles .= title "|"
}
IniWrite, % RTrim(titles, "|"), %SettingsIni%, Show_titles_name, Key
gosub, CreateMainGui
return
;-----------------------------------------------------------------------------------------------------------------------
DeleteControlButton:
GuiControlGet, DeleteControl,, DeleteControl
if DeleteControl=
return
DeleteIndex := 0
if Source_Folders.HasKey(DeleteControl) {
if (Source_Folders_num.MaxIndex() = 1)
{
MsgBox, 0, %GuiTitle%, You must not delete the only one source folder!
Return
}
For i, sfolder in Source_Folders_num {
if (sfolder = DeleteControl) {
DeleteIndex := i
break
}
}
if (DeleteIndex) {
Source_Folders_num.Remove(DeleteIndex)
Source_Folders.Remove(DeleteControl)
sfolders := ""
for i, sfolder in Source_Folders_num
sfolders .= sfolder "|"
IniWrite, % RTrim(sfolders, "|"), %SettingsIni%, Source_Folders, Key
}
}
else if Destination_Folders.HasKey(DeleteControl) {
if (Destination_Folders_num.MaxIndex() = 1)
{
MsgBox, 0, %GuiTitle%, You must not delete the only one destination folder!
Return
}
For i, dfolder in Destination_Folders_num {
if (dfolder = DeleteControl) {
DeleteIndex := i
break
}
}
if (DeleteIndex) {
Destination_Folders_num.Remove(DeleteIndex)
Destination_Folders.Remove(DeleteControl)
dfolders := ""
for i, dfolder in Destination_Folders_num
dfolders .= dfolder "|"
IniWrite, % RTrim(dfolders, "|"), %SettingsIni%, Destination_Folders, Key
}
}
else if Show_titles_name.HasKey(DeleteControl) {
if (Show_titles_num.MaxIndex() = 1)
{
MsgBox, 0, %GuiTitle%, You must not delete the only one show title!
Return
}
Show_titles_name.Remove(DeleteControl)
Show_titles_num := []
titles := ""
for title in Show_titles_name {
Show_titles_num.Insert(title)
titles .= title "|"
}
IniWrite, % RTrim(titles, "|"), %SettingsIni%, Show_titles_name, Key
}
else {
MsgBox, 0, %GuiTitle%, "No Folder or Show exists with this name '" DeleteControl "'.`nNothing will be deleted."
return
}
gosub, CreateMainGui
return
;-----------------------------------------------------------------------------------------------------------------------
LaunchMove:
Gui, Submit, NoHide
RecFolder := Source_Folders_num[SrcRadios]
if (RecFolder = "")
{
MsgBox, 0, %GuiTitle%, Sorry!`n`nSelect a source folder, please!
return
}
DestFolder := RTrim(Destination_Folders_num[DstRadios], "\")
if (DestFolder = "")
{
MsgBox, 0, %GuiTitle%, Sorry!`n`nSelect a destination folder, please!
return
}
SelectedShow := ""
for sShow, IsChecked in Show_titles_name
{
if IsChecked
{
SelectedShow := sShow
break
}
}
If (SelectedShow = "")
{
MsgBox, 0, %GuiTitle%, Sorry!`n`nSelect at least one show, please!
return
}
Gui, +Disabled
; ======================================================================================================================
; Copy/move GUI
; Get the height of a pushbutton
Gui, Dummy: Add, Button, vC
GuiControlGet, C, Dummy:Pos
Gui, Dummy: Destroy
; ----------------------------------------------------------------------------------------------------------------------
; Create the GUI
Gui, ExecGui: New, -SysMenu +Owner +LastFound +AlwaysOnTop +OwnDialogs +Disabled
Gui, Margin, 10, 10
Gui, Add, Text, w600, Destination folder
Gui, Add, Text, xm y+2 w510 h%CH% +0x0008
Gui, Add, Text, xp+3 yp+1 wp-4 hp-2 +0x2200 vDestFolder, %DestFolder%
Gui, Add, Button, x+10 yp-1 w80 h%CH% vBtnSelect gSelectFolder, Select
Gui, Add, Checkbox, xm y+2 hp vMoveFiles Checked%Move%, Move files
Gui, Add, Checkbox, x+10 yp hp vOverWrite Checked%DefOverWrite%, Overwrite existing
Gui, Add, Text, xm y+10, Files found in Source folder
Gui, Add, ListView, xm y+2 w600 r7 -Hdr -Multi Checked Grid AltSubmit vLVFiles, FP|DS|FD|FN|FS|DF
Gui, Add, Text, xm y+10, Source folder
Gui, Add, Text, xm y+2 w600 h%CH% +0x0008
Gui, Add, Text, xp+3 yp+1 wp-4 hp-2 +0x0200 vSrcFolder
Gui, Add, Text, xm y+2 w510, Current file
Gui, Add, Text, xm y+2 w600 h%CH% +0x0008
Gui, Add, Text, xp+3 yp+1 wp-4 hp-2 +0x0200 vFileCurrent
Gui, Add, Text, xm y+2 w80 Section, Current size
Gui, Add, Text, xm y+2 w80 h%CH% +0x0008
Gui, Add, Text, xp+1 yp+1 wp-2 hp-2 Center +0x0200 vSizeCurrent
Gui, Add, Text, x270 ys w80 Center, Total size
Gui, Add, Text, xp y+2 w80 h%CH% +0x0008
Gui, Add, Text, xp+1 yp+1 wp-2 hp-2 Center +0x0200 vSizeTotal
Gui, Add, Text, x530 ys w80 Center, Processed
Gui, Add, Text, xp y+2 w80 h%CH% +0x0008
Gui, Add, Text, xp+1 yp+1 wp-2 hp-2 Center +0x0200 vSizeDone
Gui, Add, Text, xm y+2 w510, Current file progress
Gui, Add, Text, x+10 yp w80 Center, Percent
Gui, Add, Progress, xm y+2 w510 h%CH% vFileProgress -Smooth, 0
Gui, Add, Text, x+10 yp w80 h%CH% +0x0008
Gui, Add, Text, xp+1 yp+1 wp-2 hp-2 Center +0x0200 vFilePercent
Gui, Add, Text, xm y+2 w510, Total progress
Gui, Add, Text, x+10 yp w80 Center, Percent
Gui, Add, Progress, xm y+2 w510 h%CH% vTotalProgress -Smooth, 0
Gui, Add, Text, x+10 yp w80 h%CH% +0x0008
Gui, Add, Text, xp+1 yp+1 wp-2 hp-2 Center +0x0200 vTotalPercent
Gui, Add, Button, xm y+20 w80 gStart vBtnStart, Start
Gui, Add, Button, x270 yp wp gCancel vBtnCancel Disabled, Cancel
Gui, Add, Button, x530 yp wp gAbort vBtnAbort, Abort
Gui, Add, StatusBar
Gui, Show, , %GuiTitle%
SB_SetParts(200)
SB_SetText(" Gathering files...")
; Get the files --------------------------------------------------------------------------------------------------------
CurrentBytes := 0
TotalSize := 0
TotalCopied := 0
FileCount := 0
GuiControl, -Redraw, LVFiles
Loop, %RecFolder%\*.*, 0, 0 ; not recurse into subfolders.
{
for title, IsChecked in Show_titles_name
{
if IsChecked
{
If InStr(A_LoopFilename, title)
{
FilePath := A_LoopFileLongPath
FileDir := A_LoopFileDir
FileSize := A_LoopFileSize
FileName := A_LoopFileName
LV_Add("Check", FilePath, DisplaySize(FileSize), FileDir, FileName, FileSize, DestFolder . "\" . title)
TotalSize += FileSize
FileCount++
break
}
}
}
}
LV_ModifyCol()
LV_ModifyCol(2, "Right")
Loop, 4
LV_ModifyCol(A_Index + 2, 0)
GuiControl, +Redraw, LVFiles
GuiControl, +gLVCheck, LVFiles
If (FileCount = 0) || (TotalSize = 0){
MsgBox, 0, %GuiTitle%, No files to copy/move!
GoSub, Abort
}
GuiControl, , SizeTotal, % DisplaySize(TotalSize)
SB_SetText(" " . FileCount . " file(s) to copy/move")
Gui, -Disabled
Return
; ======================================================================================================================
#IfWinActive ahk_class AutoHotkeyGUI
WheelDown::
ControlClick, SysListView321, A,,WD
ControlClick, SysListView322, A,,WD
ControlClick, SysListView323, A,,WD
return
WheelUp::
ControlClick, SysListView321, A,,WU
ControlClick, SysListView322, A,,WU
ControlClick, SysListView323, A,,WU
return
; ======================================================================================================================
LVCheck:
Critical
Gui, +OwnDialogs
If (A_GuiEvent == "I") && InStr(ErrorLevel, "c") ; not case-sensitive
{
LV_GetText(FileSize, A_EventInfo, 5)
If InStr(ErrorLevel, "C", True) ; case-sensitive -> checked
{
FileCount++
TotalSize += FileSize
}
Else
{
FileCount--
TotalSize -= FileSize
}
GuiControl, , SizeTotal, % DisplaySize(TotalSize)
SB_SetText(" " . FileCount . " file(s) to copy/move")
}
Return
; ----------------------------------------------------------------------------------------------------------------------
SelectFolder:
Gui, +OwnDialogs
DestFolder := ""
FileSelectFolder, DestFolder, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}, 0, Destination folder:
If !(ErrorLevel)
GuiControl, , DestFolder, %DestFolder%
Return
Return
; ----------------------------------------------------------------------------------------------------------------------
Start:
Gui, Submit, NoHide
Gui, +OwnDialogs
If (FileCount = 0) || (TotalSize = 0)
MsgBox, 0, %GuiTitle%, No files to copy/move!
GuiControlGet, DestFolder
Disable := True
GoSub, UpdateControls
GuiControl, , SizeTotal, % DisplaySize(TotalSize)
Action := MoveFiles ? "Moving" : "Copying"
SB_SetText(" Preparing...")
CopyErrors := 0
ProcessedCount := 0
ErroneousFiles := ""
SrcFolder := ""
SB_SetText(" " . Action . "...")
UpdateSpeed(True)
File := {}
RowNumber := 0
PROGRESS_CANCEL := False
While (RowNumber := LV_GetNext(RowNumber, "Checked")) {
LV_GetText(FilePath, RowNumber, 1)
LV_GetText(FileDir , RowNumber, 3)
LV_GetText(FileName, RowNumber, 4)
LV_GetText(FileSize, RowNumber, 5)
LV_GetText(DestDir , RowNumber, 6)
File := {Path: FilePath, Name: FileName, Copied: False}
WinSetTitle, %Action% files ... (%A_Index% of %FileCount%)
If (FileDir <> SrcFolder)
GuiControl, , SrcFolder, % (SrcFolder := FileDir)
If (DestDir <> DestFolder)
GuiControl, , DestFolder, % (DestFolder := DestDir)
GuiControl, , FileCurrent, % FileName
GuiControl, , SizeCurrent, % DisplaySize(FileSize)
GuiControl, , FileProgress, 0
While !InStr(FileExist(DestFolder), "D")
{
FileCreateDir, % DestFolder
If (ErrorLevel)
{
MsgBox, 5, %GuiTitle%, % "Error!`n`nFile:`t" . FileName . "`n"
. "Couldn't create the destination folder!"
IfMsgBox, Retry
Continue
PROGRESS_CANCEL := True
Break, 2
}
}
Loop {
CB := FileSize >= DefMinSize ? CBFunc : 0
If !CopyOrMoveFileWithProgress(MoveFiles, File, DestFolder, CB, OverWrite)
{
LastError := ErrorLevel
If (PROGRESS_CANCEL)
Break, 2
MsgBox, 5, %GuiTitle%, % "Error!`n`nFile:`t" . FileName . "`n"
. "Error:`t" . LastError . "`n"
. GetErrorMessage(LastError)
IfMsgBox, Retry
Continue
PROGRESS_CANCEL := True
Break, 2
}
Break
}
If (File.Copied) {
If (CB = 0) {
ProcessedCount++
TotalPercent := Round((CurrentBytes += FileSize) / TotalSize * 100)
GuiControl, , SizeDone, % DisplaySize(CurrentBytes)
GuiControl, , TotalProgress, %TotalPercent%
GuiControl, , TotalPercent, %TotalPercent% `%
UpdateSpeed()
}
TotalCopied += FileSize
}
Else {
ErroneousFiles .= FilePath . "`n"
CopyErrors++
}
Sleep, -1
}
SB_SetText("")
SB_SetText("", 2)
If (CopyErrors = 0) || (PROGRESS_CANCEL)
{
If (PROGRESS_CANCEL)
MsgBox, 0, %GuiTitle%, Cancelled!`n`nThe operation was cancelled after processing %ProcessedCount% files!
GoSub, Abort
}
Else
{
MsgBox, 0, %GuiTitle%, Done with %CopyErrors% errors!`n`nErroneous files:`n%ErroneousFiles%
Disable := False
GoSub, UpdateControls
}
Return
; ----------------------------------------------------------------------------------------------------------------------
Abort:
Gui, SelectGui: -Disabled
Gui, Destroy
Return
; ----------------------------------------------------------------------------------------------------------------------
Cancel:
Gui, +OwnDialogs
MsgBox, 4, % GuiTitle, Do you really want to cancel the operation?
IfMsgBox, Yes
PROGRESS_CANCEL := True
Return
; ----------------------------------------------------------------------------------------------------------------------
UpdateControls:
GuiControl, Disable%Disable%, BtnSelect
GuiControl, Disable%Disable%, MoveFiles
GuiControl, Disable%Disable%, OverWrite
GuiControl, Disable%Disable%, LVFiles
GuiControl, Disable%Disable%, BtnStart
GuiControl, Enable%Disable%, BtnCancel
GuiControl, Disable%Disable%, BtnAbort
Return
;-----------------------------------------------------------------------------------------------------------------------
CopyOrMoveFileWithProgress(MoveFile, FileObj, DestFolder, CallbackFunc, OverWrite := False) {
; CopyFileEx() -> msdn.microsoft.com/en-us/library/windows/desktop/aa363852(v=vs.85).aspx
; COPY_FILE_FAIL_IF_EXISTS = 0x0001, COPY_FILE_NO_BUFFERING = 0x1000
; MoveFileWithProgress -> msdn.microsoft.com/en-us/library/windows/desktop/aa365242(v=vs.85).aspx
; MOVEFILE_COPY_ALLOWED = 0x02, MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20, MOVEFILE_WRITE_THROUGH = 0x08
Static CopyFlags := (DllCall("Kernel32.dll\GetVersion", "UChar") < 6) ? 0 : 0x1000
Static MoveFlags := 0x0A
; Critical
If (MoveFile) {
If DllCall("Kernel32.dll\MoveFileWithProgress"
, "Str", FileObj.Path
, "Str", DestFolder . "\" . FileObj.Name
, "Ptr", CallbackFunc
, "Ptr", 0
, "UInt", MoveFlags | !!(OverWrite)) {
Return (FileObj.Copied := True)
}
}
Else {
If DllCall("Kernel32.dll\CopyFileEx"
, "Str", FileObj.Path
, "Str", DestFolder . "\" . FileObj.Name
, "Ptr", CallbackFunc
, "Ptr", 0
, "Ptr", 0
, "UInt", CopyFlags | !(OverWrite)) {
Return (FileObj.Copied := True)
}
}
ErrorLevel := A_LastError
Return False
}
; ----------------------------------------------------------------------------------------------------------------------
FileProgressCB64(TFS, TBT, SS, SBT, SN, CBR, HSRC, HDST, Data) {
Global TotalSize, TotalCopied, CurrentBytes, PROGRESS_CANCEL
Gui, ExecGui: Default
UpdateProgress(TFS, TBT)
UpdateSpeed()
Sleep, -1
Return (PROGRESS_CANCEL ? 1 : 0)
}
; ----------------------------------------------------------------------------------------------------------------------
FileProgressCB32(TFSLO, TFSHI, TBTLO, TBTHI, SSLO, SSHI, SBTLO, SBTHI, SN, CBR, HSRC, HDST, Data) {
Global TotalSize, TotalCopied, CurrentBytes, PROGRESS_CANCEL
Gui, ExecGui: Default
TFS := TFSLO + (TFSHI << 32), TBT := TBTLO + (TBTHI << 32)
UpdateProgress(TFS, TBT)
UpdateSpeed()
Sleep, -1
Return (PROGRESS_CANCEL ? 1 : 0)
}
; ----------------------------------------------------------------------------------------------------------------------
UpdateProgress(TFS, TBT) {
Global TotalSize, TotalCopied, CurrentBytes
CurrentBytes := TotalCopied + TBT
FilePercent := Round(TBT / TFS * 100)
TotalPercent := Round(CurrentBytes / TotalSize * 100)
GuiControl, , SizeDone, % DisplaySize(CurrentBytes)
GuiControl, , FileProgress, %FilePercent%
GuiControl, , FilePercent, %FilePercent% `%
GuiControl, , TotalProgress, %TotalPercent%
GuiControl, , TotalPercent, %TotalPercent% `%
}
; ----------------------------------------------------------------------------------------------------------------------
UpdateSpeed(Init := False) {
Global CurrentBytes, TotalSize
Static Seconds := 0, TickCount := 0
If !(Init) {
If ((A_TickCount - TickCount) > 1000) {
Unit := " kB/s"
Seconds += 1
TickCount += 1000
Speed := Round(CurrentBytes / 1024 / Seconds, 1)
If (Speed >= 1024) {
Speed := Round(Speed / 1024, 1)
Unit := " MB/s"
}
SB_SetText(" Overall speed: " . Speed . Unit, 1)
TimeRemaining := StrFromTimeIntervall(Round((TotalSize - CurrentBytes) / (CurrentBytes / Seconds), 3))
SB_SetText(" Time remaining: " . TimeRemaining, 2)
}
}
Else {
Seconds := 0
TickCount := A_TickCount
}
}
; ----------------------------------------------------------------------------------------------------------------------
DisplaySize(FileSize) {
Static KB := 1024
Static MB := KB * 1024
Static GB := MB * 1024
Return (FileSize >= GB) ? (Round(FileSize / GB, 3) . " GB")
: (FileSize >= MB) ? (Round(FileSize / MB, 1) . " MB")
: (FileSize >= KB) ? (Round(FileSize / KB) . " KB")
: FileSize
}
; ----------------------------------------------------------------------------------------------------------------------
GetErrorMessage(MsgNum) {
VarSetCapacity(Msg, 4098, 0)
If DllCall("Kernel32.dll\FormatMessage", "UInt", 0x1200, "Ptr", 0, "UInt", MsgNum, "UInt", 0x0400
, "Str", Msg, "Int", 2048, "Ptr", 0, "UInt")
Return Msg
Return ""
}
; ----------------------------------------------------------------------------------------------------------------------
StrFromTimeIntervall(S) { ; s = seconds
; http://msdn.microsoft.com/en-us/library/bb759980(v=vs.85).aspx
VarSetCapacity(Out, 128, 0)
DllCall("Shlwapi.dll\StrFromTimeInterval", "Str", Out, "UInt", 64, "UInt", S * 1000, "Int", 30)
Return Out
}
;************************** GroupBox *******************************
;
; Adds and wraps a GroupBox around a group of controls in
; the default Gui. Use the Gui Default command if needed.
; For instance:
;
; Gui, 2:Default
;
; sets the default Gui to Gui 2.
;
; Add the controls you want in the GroupBox to the Gui using
; the "v" option to assign a variable name to each control. *
; Then immediately after the last control for the group
; is added call this function. It will add a GroupBox and
; wrap it around the controls.
;
; Example:
;
; Gui, Add, Text, vControl1, This is Control 1
; Gui, Add, Text, vControl2 x+30, This is Control 2
; GroupBox("GB1", "Testing", 20, 10, "Control1|Control2")
; Gui, Add, Text, Section xMargin, This is Control 3
; GroupBox("GB2", "Another Test", 20, 10, "This is Control 3")
; Gui, Add, Text, yS, This is Control 4
; GroupBox("GB3", "Third Test", 20, 10, "Static4")
; Gui, Show, , GroupBox Test
;
; * The "v" option to assign Control ID is not mandatory. You
; may also use the ClassNN name or text of the control.
;
; Author: dmatch @ AHK forum
; Date: Sept. 5, 2011
;
;********************************************************************
GroupBox(GBvName ; Name for GroupBox control variable
,Title ; Title for GroupBox
,TitleHeight ; Height in pixels to allow for the Title
,Margin ; Margin in pixels around the controls
,Piped_CtrlvNames ; Pipe (|) delimited list of Controls
,MinWidth := 0 ; Optional minimum width ; <<<<< changed
,MinHeight := 0) ; Optional minimum height ; <<<<< changed
{
Local ctl, ctlX, ctlY, ctlW, ctlH, maxX, maxY, minX, minY, xPos, yPos ; all else assumed Global
minX := 99999
minY := 99999
maxX := 0
maxY := 0
Loop, Parse, Piped_CtrlvNames, |, %A_Space%
{
; Get position and size of each control in list.
GuiControlGet, ctl, Pos, %A_LoopField%
; Creates ctlX, ctlY, ctlW, ctlH
if (ctlX < minX) ; check for minimum X
minX := ctlX
if (ctlY < minY) ; check for minimum Y
minY := ctlY
if ((ctlX + ctlW) > maxX) ; check for maximum X
maxX := ctlX + ctlW
if (ctlY + ctlH > maxY) ; check for maximum Y
maxY := ctlY + ctlH
; Move the control to make room for the GroupBox
xPos := ctlX + Margin
yPos := ctlY + TitleHeight + Margin ;fixed margin
GuiControl, Move, %A_LoopField%, x%xPos% y%yPos%
}
; Re-purpose the ctlW and ctlH variables
ctlW := maxX - minX + (2 * Margin) ; calculate width for GroupBox
If (MinWidth > ctlW)
ctlW := MinWidth
ctlH := maxY - MinY + TitleHeight + (2 * Margin) ; calculate height for GroupBox (fixed 2 * margin)
If (MinHeight > ctlH)
ctlH := MinHeight
; Add the GroupBox
Gui, Add, GroupBox, v%GBvName% x%minX% y%minY% w%ctlW% h%ctlH%, %Title%
Return
}
; ======================================================================================================================
; Create or repair the INI file
EditIni:
Gui, IniGui: New, +LastFound +LabelIniGui
Gui, Margin, 10, 10
Gui, Font, s12 cA00000
Gui, Add, Text, vHeading, Either the program has been started the first time`nor your Settings.ini has been corrupted!
GuiControlGet, H, Pos, Heading
HW2 := HW // 2
Gui, Font
If (sFolders = "")
{
Gui, Add, Text, xm, Add at least one source folder, please:
Gui, Add, ListBox, xm y+2 w%HW% r3 vIniSrcFolders Readonly
Gui, Add, Button, xm y+2 w%HW2% gIniAddSrc, Add
}
If (dFolders = "")
{
Gui, Add, Text, , Add at least one destination folder, please:
Gui, Add, ListBox, xm y+2 w%HW% r3 vIniDstFolders Readonly
Gui, Add, Button, xm y+2 w%HW2% gIniAddDst, Add
}
If (titles = "")
{
Gui, Add, Text, , Add at least one show title, please:
Gui, Add, ListBox, xm y+2 w%HW% r3 vIniTitles Readonly
Gui, Add, Edit, xm y+2 w%HW2% vShowTitle
Gui, Add, Button, x+5 yp w50 hp gIniAddTitle, +
}
Gui, Add, Button, xm w100 gIniApply, Apply
X := HX + HW - 100
Gui, Add, Button, x%X% yp wp gIniAbort, Abort
Gui, Show, , %GuiTitle%
WinWaitActive
WinWaitClose
Return
IniGuiClose:
IniGuiEscape:
IniAbort:
Gui, Destroy
ExitApp
IniAddSrc:
Gui, +OwnDialogs
SrcFolder := ""
FileSelectFolder, SrcFolder, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}, 0, Source folder:
If !(ErrorLevel)
GuiControl, , IniSrcFolders, %SrcFolder%
Return
IniAddDst:
Gui, +OwnDialogs
DstFolder := ""
FileSelectFolder, DstFolder, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}, 0, Destination folder:
If !(ErrorLevel)
GuiControl, , IniDstFolders, %DstFolder%
Return
IniAddTitle:
GuiControlGet, ShowTitle
If (ShowTitle := Trim(ShowTitle))
GuiControl, , IniTitles, %ShowTitle%
Return
IniApply:
SrcFolders := DstFolders := ShowTitles := ""
If (sFolders = "")
{
GuiControlGet, HLB, HWND, IniSrcFolders
ControlGet, SrcFolders, List, , , ahk_id %HLB%
If (SrcFolders = "")
Return
}
If (dFolders = "")
{
GuiControlGet, HLB, HWND, IniDstFolders
ControlGet, DstFolders, List, , , ahk_id %HLB%
If (DstFolders = "")
Return
}
If (titles = "")
{
GuiControlGet, HLB, HWND, IniTitles
ControlGet, ShowTitles, List, , , ahk_id %HLB%
If (ShowTitles = "")
Return
}
If (SrcFolders)
{
StringReplace, SrcFolders, SrcFolders, `n, |, All
IniWrite, %SrcFolders%, %SettingsIni%, Source_Folders, Key
}
If (DstFolders)
{
StringReplace, DstFolders, DstFolders, `n, |, All
IniWrite, %DstFolders%, %SettingsIni%, Destination_Folders, Key
}
If (ShowTitles)
{
StringReplace, ShowTitles, ShowTitles, `n, |, All
IniWrite, %ShowTitles%, %SettingsIni%, Show_titles_name, Key
}
Gui, Destroy
Return
Code: Select all
[Source_Folders]
Key=D:\TV\Recording Service|D:\Edited Recordings|E:\|D:\
[Destination_Folders]
Key=E:\TV\Unedited|E:\TV\Edited|E:\|D:\
[Show_titles_name]
Key=American Chopper|Arga snickaren|Gold Divers|Gold Rush|Gordon’s Kitchen Nightmares|Hell’s Kitchen|Hundra procent bonde|Ice Cold Gold|Ink Master USA|Jungle Gold|Mannen som talar med hundar|Mythbusters|Solsidan|Tidsresenärerna|Top Gear|Ullared|Whale Wars|Wheeler Dealers