1

Тема: AHK: Как Выбрать путь сохранения значений из GUI?

Здравствуйте!

Имеется вопрос:

Возможно ли внутри AHK использовать проводник, для сохранения значений, которые я укажу в параметре?


Gui, Add, Edit, x46 y37 w240 h20 , %Val%

Есть цель:

Добавить несколько строк Edit и две кнопки "Сохранить" и "Загрузить".

Нужно, чтобы при нажатие на кнопку GUI "Сохранить", у меня открывался проводник, где я смогу выбрать путь до сохранения файла, аналогично с  загрузкой файла, со всеми значениями %Val1% %Val2% и т.д, через Абзац.

Помогите, пожалуйста!

2

Re: AHK: Как Выбрать путь сохранения значений из GUI?

Как раз хотел создать подобную тему, ибо к сожалению ничего не нашел похожего. Мне необходимо вызвать окно "Обзор", где я выбираю какой-либо файл или папку. Необходимо получить путь к выбранной папке, файлу. Прошу ваших советов.

Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

3

Re: AHK: Как Выбрать путь сохранения значений из GUI?

belyankin12

Нашел в одном вики-примере этот код:

; Example: This is a working script that writes some text to a file then reads it back into memory.
; It provides the same functionality as this DllCall-example.

FileSelectFile, FileName, S16,, Create a new file:
if (FileName = "")
    return
file := FileOpen(FileName, "w")
if !IsObject(file)
{
    MsgBox Can't open "%FileName%" for writing.
    return
}
TestString := "This is a test string.`r`n"  ; When writing a file this way, use `r`n rather than `n to start a new line.
file.Write(TestString)
file.Close()

; Now that the file was written, read its contents back into memory.
file := FileOpen(FileName, "r-d") ; read the file ("r"), share all access except for delete ("-d")
if !IsObject(file)
{
    MsgBox Can't open "%FileName%" for reading.
    return
}
CharsToRead := StrLen(TestString)
TestString := file.Read(CharsToRead)
file.Close()
MsgBox The following string was read from the file: %TestString%

Он открывает проводник для сохранения, но я точно не знаю что за что отвечает.

Вот ссылка на эту информацию:
https://autohotkey.com/docs/commands/FileOpen.htm

4

Re: AHK: Как Выбрать путь сохранения значений из GUI?

belyankin12

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force 



Gui, +ToolWindow 
Gui, Add, Edit, r1 w100, ********
Gui, Add, Edit, r1 w100, ********
Gui, Add, Button,  w100 h30 gSave, Сохранить
Gui, Add, Button,  w100 h30 gLoad, Загрузить
Gui, Show,, *****
Return


Save:
FileSelectFile, FileName, S, %A_Desktop%, Create a new file:

if FileName !=
    MsgBox,  %FileName%
return




Load:
FileSelectFile, SelectedFile,, %A_Desktop%, Open a file:

if SelectedFile !=
    MsgBox, %SelectedFile%
return

GuiClose:
ExitApp

5

Re: AHK: Как Выбрать путь сохранения значений из GUI?

Попробуйте почитать справку. Уже существуют стандартные формы для чтения файла и сохранения файла.

6

Re: AHK: Как Выбрать путь сохранения значений из GUI?

Clannad5


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force 



Gui, +ToolWindow 
Gui, Add, Edit, vEdit r1 w100, %Val%
Gui, Add, Button,  w100 h30 gSave, Сохранить
Gui, Add, Button,  w100 h30 gLoad, Загрузить
Gui, Show,, *****
Return


Save:
GuiControlGet, Edit
FileAppend, %Edit%, % A_Desktop "\" Edit ".txt"   
return


Load:
FileSelectFile, SelectedFile,, %A_Desktop%, Open a file:
FileRead, val, %SelectedFile%
GuiControl,, Edit, %val%
return



GuiClose:
ExitApp

7

Re: AHK: Как Выбрать путь сохранения значений из GUI?

Мой косяк, проявил невнимательность. Спасибо за подсказку.

Когда вы говорите что не можете сделать, вам всего-лишь не хватает фантазии придумать какой-нибудь костыль.

8

Re: AHK: Как Выбрать путь сохранения значений из GUI?

Если нужен современный апи с большими возможностями:
https://www.autohotkey.com/boards/viewtopic.php?t=53136

9

Re: AHK: Как Выбрать путь сохранения значений из GUI?

inseption86

Спасибо!
Я немного обновил код, добавив сохранение через проводник:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force 



Gui, +ToolWindow 
Gui, Add, Edit, vEdit r1 w100, %Val%
Gui, Add, Button,  w100 h30 gSave, Сохранить
Gui, Add, Button,  w100 h30 gLoad, Загрузить
Gui, Show,, *****
Return


Save:
GuiControlGet, Edit
FileSelectFile, FileName, S16,%A_Scriptdir%\Profile\, Сохранить профиль, *.txt
FileAppend, 
(
 %Edit%
), %FileName%.txt
return

Load:
FileSelectFile, SelectedFile,, %A_Scriptdir%, Открыть профиль:
FileRead, val, %SelectedFile%
GuiControl,, Edit, %val%
return



GuiClose:
ExitApp