【已解決】子線程如何對主線程做GuiControl?
第42行的 GuiControl,,下載進度%列%,% 100*A_Index/圖片數量 完全無作用,沒辦法控制進度條。
可執行不可編譯?
我從官網下載的H版,安裝步驟如下:
1.先有L版,再手動安裝H版(MD版的Win32w資料夾)。
2.注意H版下載的檔案排列不整齊,請以下列順序一個個搬運資料:
2.1) lib資料夾 丟進去L版
2.2) 普通版和Multi-threaded Dll MD版兩者擇一,然後選Win32w資料夾裡面內容如下:
2.2.1) AutoHotkeySC.bin 丟進去Complie資料夾覆蓋之
2.2.2) AutoHotkey.exe 丟進去L版覆蓋之
2.2.3) AutoHotkey.dll 丟進去腳本目錄
2.2.4) AutoHotkeyMini.dll 丟進去腳本目錄
2.2.5) msvcr100.dll(MD版才有) 丟進去腳本目錄
2.3) 至於compile資料夾我覆蓋至L版會出問題,會連最基本的編譯都沒辦法,所以就沒覆蓋了。
只要用到AutoHotKey.dll,該腳本就會變得可執行不可編譯。
原腳本代碼
Code: Select all
Gui,Show,x517 y81 w613 h380
Gui,Font,Normal,Tahoma
Gui,Add,GroupBox,x18 y18 w450 h300,步驟一
Gui,Add,Text,x46 y48 w140 h18,請輸入圖片的主網址
Gui,Add,Text,x222 y48 w55 h18,圖片數量
Gui,Add,Text,x297 y48 w80 h18,存檔路徑
Gui,Add,GroupBox,x470 y18 w128 h300,步驟二
Gui,Add,Text,x484 y48 w50 h18,下載進度
Gui,Add,Button,x485 y276 w70 h23 default,開始下載 ;按下按鈕,就會跑到"Button開始下載"的標籤位置
Loop,6 ;產生6行介面
{
Y座標:=40+A_Index*33
Gui,Add,Text,x31 y%Y座標% w10 h12,%A_Index%.
Gui,Add,Edit,x46 y%Y座標% w150 h20 v圖片主網址%A_Index%,
Gui,Add,Edit,x222 y%Y座標% w50 h20 v圖片數量%A_Index%,
Gui,Add,Edit,x297 y%Y座標% w130 h20 v存檔路徑%A_Index%,
Gui,Add,Button,x430 y%Y座標% w25 h20 g下載路徑,%A_Index%
Gui,Add,Progress,x483 y%Y座標% w83 h18 -Smooth v下載進度%A_Index%
}
Return
下載路徑:
FileSelectFolder,存檔路徑%A_GuiControl%,%A_Desktop%,1 ;A_GuiControl這個內建變數,同一個標籤產生不同指令
GuiControl,,存檔路徑%A_GuiControl%,% 存檔路徑%A_GuiControl% ;這邊要用GuiControl重新賦予值,雖然我也不知道為什麼
Return
Button開始下載:
Gui,Submit,NoHide ;儲存使用者輸入的資訊。要用這行命令之後才可以把Edit內的變數拿來用。1
Loop,6 ;外迴圈,控制第幾列
{
線程%A_Index%:=AhkDllThread()
列:=A_Index
線程%A_Index%.Ahkassign.圖片主網址:=圖片主網址%列%
線程%A_Index%.Ahkassign.圖片數量:=圖片數量%列%
線程%A_Index%.Ahkassign.存檔路徑:=存檔路徑%列%
線程%A_Index%.Ahkassign.列:=列 ;這邊不能寫線程%A_Index%.Ahkassign.列:=A_Index
命令=
( % Comments
#NoTrayIcon
Loop,% 圖片數量 ;內迴圈,控制該列下載幾張圖片
{
GuiControl,,下載進度%列%,% 100*A_Index/圖片數量
If A_Index <10 ;由於檔名是001.jpg、999.jpg這樣的連號形式,如果要順利運作必須將迴圈分3部分
{
URLDownloadToFile,% 圖片主網址 "00" A_Index ".jpg",% 存檔路徑 "\00" A_Index ".jpg"
continue
}
else if A_Index <100
{
URLDownloadToFile,% 圖片主網址 "0" A_Index ".jpg",% 存檔路徑 "\0" A_Index ".jpg"
continue
}
else if A_Index <1000
{
URLDownloadToFile,% 圖片主網址 A_Index ".jpg",% 存檔路徑 "\" A_Index ".jpg"
continue
}
}
)
線程%A_Index%.AhkTextDll(命令)
}
MsgBox,,,全部下載完畢,本視窗5秒後關閉,5
Return
GuiClose: ;按視窗右上角X時關閉程式
ExitApp
Return
Code: Select all
Gui,Show,x517 y81 w613 h380
Gui,Font,Normal,Tahoma
Gui,Add,GroupBox,x18 y18 w450 h300,步驟一
Gui,Add,Text,x46 y48 w140 h18,請輸入圖片的主網址
Gui,Add,Text,x222 y48 w55 h18,圖片數量
Gui,Add,Text,x297 y48 w80 h18,存檔路徑
Gui,Add,GroupBox,x470 y18 w128 h300,步驟二
Gui,Add,Text,x484 y48 w50 h18,下載進度
Gui,Add,Button,x485 y276 w70 h23 default,開始下載 ;按下按鈕,就會跑到"Button開始下載"的標籤位置
Loop,6 ;產生6行介面
{
Y座標:=40+A_Index*33
Gui,Add,Text,x31 y%Y座標% w10 h12,%A_Index%.
Gui,Add,Edit,x46 y%Y座標% w150 h20 v圖片主網址%A_Index%,
Gui,Add,Edit,x222 y%Y座標% w50 h20 v圖片數量%A_Index%,
Gui,Add,Edit,x297 y%Y座標% w130 h20 v存檔路徑%A_Index%,
Gui,Add,Button,x430 y%Y座標% w25 h20 g下載路徑,%A_Index%
Gui,Add,Progress,x483 y%Y座標% w83 h18 -Smooth v下載進度%A_Index%
}
Return
下載路徑:
FileSelectFolder,存檔路徑%A_GuiControl%,%A_Desktop%,1 ;A_GuiControl這個內建變數,同一個標籤產生不同指令
GuiControl,,存檔路徑%A_GuiControl%,% 存檔路徑%A_GuiControl% ;這邊要用GuiControl重新賦予值,雖然我也不知道為什麼
Return
Button開始下載:
Gui,Submit,NoHide ;儲存使用者輸入的資訊。要用這行命令之後才可以把Edit內的變數拿來用。1
Loop,6 ;外迴圈,控制第幾列
{
線程%A_Index%:=AhkDllThread()
列:=A_Index
線程%A_Index%.Ahkassign.圖片主網址:=圖片主網址%列%
線程%A_Index%.Ahkassign.圖片數量:=圖片數量%列%
線程%A_Index%.Ahkassign.存檔路徑:=存檔路徑%列%
線程%A_Index%.Ahkassign.列:=列 ;這邊不能寫線程%A_Index%.Ahkassign.列:=A_Index
命令=
( % Comments
#NoTrayIcon
主線程:=AhkExported() ;命名主線程
Loop,% 圖片數量 ;內迴圈,控制該列下載幾張圖片
{
已下載圖片數量:=A_Index
主線程.ahkFunction("下載進度",列,已下載圖片數量,圖片數量) ;這邊要用呼叫主線程函數的方法才可以Guicontrol,另外參數名不可以是A_Index
If A_Index <10 ;由於檔名是001.jpg、999.jpg這樣的連號形式,如果要順利運作必須將迴圈分3部分
{
URLDownloadToFile,% 圖片主網址 "00" A_Index ".jpg",% 存檔路徑 "\00" A_Index ".jpg"
continue
}
else if A_Index <100
{
URLDownloadToFile,% 圖片主網址 "0" A_Index ".jpg",% 存檔路徑 "\0" A_Index ".jpg"
continue
}
else if A_Index <1000
{
URLDownloadToFile,% 圖片主網址 A_Index ".jpg",% 存檔路徑 "\" A_Index ".jpg"
continue
}
}
)
線程%A_Index%.AhkTextDll(命令)
}
Return
下載進度(列,已下載圖片數量,圖片數量) ;控制進度條的函數
{
GuiControl,,下載進度%列%,% 100*已下載圖片數量/圖片數量
}
GuiClose: ;按視窗右上角X時關閉程式
ExitApp
Return