- Where istrhe ini file saved to:
Code: Select all
Gui, Show, x131 y91 h296 w300, New GUI Window Gui, Add, Edit, x46 y50 w100 h30 vMyEdit1, Edit1 Gui, Add, Button, x46 y180 w100 h40 , Save Gui, Add, Button, x166 y180 w100 h40 , Load Return ButtonSave: Gui, Submit, NoHide IniWrite, %MyEdit1%, settings.ini, history, edit1 Return ButtonLoad: IniRead, MyEdit1, settings.ini, history, edit1 GuiControl, , MyEdit1, %MyEdit1% Return GuiClose: ExitApp
- Can I make the GUI automatically save and load the ini file?
Learning IniWrite & IniRead Topic is solved
Learning IniWrite & IniRead
Last edited by LAPIII on 13 Mar 2022, 17:59, edited 1 time in total.
Re: Learning IniWrite & IniRead
1.
2. What do you mean saying "automatically"?Filename
The name of the .ini file, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Re: Learning IniWrite & IniRead
Notepad++ automatically saves and loads such a file so I can write in the unsaved notes there and they'll always load when opening the app.
Re: Learning IniWrite & IniRead
I think it will look something like this:
Code: Select all
Gui, Show, x131 y91 h296 w300, New GUI Window
Gui, Add, Edit, x46 y50 w100 h30 vMyEdit1,
Gui, Add, Button, x46 y180 w100 h40 , Save
Gui, Add, Button, x166 y180 w100 h40 , Load
gosub, ButtonLoad
OnExit, ExitSub
Return
ButtonSave:
Gui, Submit, NoHide
IniWrite, %MyEdit1%, settings.ini, history, edit1
Return
ButtonLoad:
IniRead, MyEdit1, settings.ini, history, edit1
GuiControl, , MyEdit1, %MyEdit1%
Return
GuiClose:
ExitApp
ExitSub:
gosub, ButtonSave
ExitApp
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Re: Learning IniWrite & IniRead
Terrific, now can you get rid of the buttons please?
Re: Learning IniWrite & IniRead
Try to do that by your own. If you'll fail, post here your best attempt and we'll fix it.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Re: Learning IniWrite & IniRead
I did it:
I just Implemented into my other GUI, can you help:
Does it matter if I use vMyEdit1 or vEdit1?
Code: Select all
#SingleInstance, Force
Gui, Show, x700 y150 h296 w300, New GUI Window
Gui, Add, Edit, x46 y50 w100 h30 vMyEdit1,
gosub, ButtonLoad
OnExit, ExitSub
Return
ButtonSave:
Gui, Submit, NoHide
IniWrite, %MyEdit1%, settings.ini, history, edit1
Return
ButtonLoad:
IniRead, MyEdit1, settings.ini, history, edit1
GuiControl, , MyEdit1, %MyEdit1%
Return
ExitSub:
gosub, ButtonSave
ExitApp
Code: Select all
#SingleInstance, Force
Gui, Font, s17 cOlive, Ink Free
Gui, Show, X1211 Y305 w485 h800
Gui, Add, Text,, `n`n
Gui, Add, Edit, r12 w450 vEditl -VScroll, 1) `n2) `n3) `n4) `n5) `n6) `n7) `n8) `n9) `n10) `n`n`n`n
Gui, color,,ECD4C2
Gui, color, 9CB4B3
Gui, +Alwaysontop
OnMessage( 0x200, "WM_MOUSEMOVE" )
WinSet, Style, -0xC00000, A
WinSet, Region, 0-100 300-306 w610 H500 R100-100, ahk_class AutoHotkeyGUI
gosub, ButtonLoad
return
WM_MOUSEMOVE( wparam, lparam, msg, hwnd )
{
if wparam = 1 ; LButton
PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}
WheelUp::Up
WheelDown::Down
ButtonSave:
Gui, Submit, NoHide
IniWrite, %edit1%, GUI.ini, history, edit1
Return
ButtonLoad:
IniRead, edit1, GUI.ini, history, edit1
GuiControl, , MyEdit1, %MyEdit1%
Return
guiclose:
ExitApp
return
Esc::ExitApp
Re: Learning IniWrite & IniRead
You may use any variables names as you like. MyEdit1 or Edit1 all are nice, obviously. But since you've chosen Edit1 these line becomes buggy:
Spoiler
And you've forgotten about OnExit of OnExit() to save Edit content before you close your gui. Read about it here: OnExit.Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.
Re: Learning IniWrite & IniRead
I just can't get this to write an ini file:
The GUI will show for a split second If I use ExitApp in line 16.
Code: Select all
#Singe downleInstance, Force
OnExit, ExitSub
Gui, Show, x825 y163 w485 h800 ; GUI
Gui, color, 9CB4B3 ; GUI background color
Gui, Font, s18 cOlive, Ink Free ; font
Gui, +Alwaysontop ; always on top
OnMessage( 0x200, "WM_MOUSEMOVE" ) ; drag
WinSet, Style, -0xC00000, A ; no title bar
Gui, Add, Text,, `n`n ; blank lines
Gui, Add, Edit, r10 w400 vEditl -VScroll, 1) `n2) `n3) `n4) `n5) `n6) `n7) `n8) `n9) `n10) ; text box without scrollbar
Gui, color,,ECD4C2 ; text box background color
WinSet, Region, 0-100 300-300 w555 H675 R100-100, ahk_class AutoHotkeyGUI ; GUI shape
Gui, Add, Button, x46 y450 w100 h40 , Save
Gui, Add, Button, x166 y450 w100 h40 , Load
gosub, ButtonLoad
WM_MOUSEMOVE( wparam, lparam, msg, hwnd ) ; drag
{
if wparam = 1 ; LButton
PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}
WheelUp::Up ; scroll
WheelDown::Down
ButtonSave: ; button
Gui, Submit, NoHide
IniWrite, %MyEdit1%, GUI.ini, history, edit1
Return
ButtonLoad: ; button
IniRead, MyEdit1, GUI.ini, history, edit1
GuiControl, , MyEdit1, %MyEdit1%
Return
GuiClose:
ExitApp
ExitSub:
gosub, ButtonSave
Enter::ExitApp
The GUI will show for a split second If I use ExitApp in line 16.
Re: Learning IniWrite & IniRead
You are trying to reference a control named MyEdit1, but it is not named that. You left it named Editl, and that is not Edit1 with the number 1, it is the Editl with a lowercase letter L. So first get your ones and Ls straightened out. Then apparently you’re missing a key point from your last question: It doesn’t matter what you name your variable: Edit1, Editl, MyEdit1, or anything else, but you must reference what you actually named it when you defined the control using the v option.
Re: Learning IniWrite & IniRead
I was confused on syntax. I changed my file name to GUI.ini, section to Section, key to GUI key, and ControlID to GUIID. Therefore I have changed these lines:
But the scripts still won't save the ini file. Why? Here's the whole script:
Code: Select all
Gui, Add, Edit, r10 w400 vMyGUI -VScroll
Code: Select all
IniWrite, %MyGUI%, GUI.ini, Section, GUI key
Code: Select all
IniRead, MyGUI, GUI.ini, Section, GUI key
GuiControl, , GUIID, %MyGUI%
Code: Select all
#SingleInstance, Force
Gui, Show, x825 y163 w485 h800 ; GUI
Gui, color, 9CB4B3 ; GUI background color
Gui, Font, s18 cOlive, Ink Free ; font
Gui, +Alwaysontop ; always on top
OnMessage( 0x200, "WM_MOUSEMOVE" ) ; drag
WinSet, Style, -0xC00000, A ; no title bar
Gui, Add, Text,, `n`n ; blank lines
Gui, Add, Edit, r10 w400 vMyGUI -VScroll ; text box without scrollbar
Gui, color,,ECD4C2 ; text box background color
WinSet, Region, 0-100 300-300 w555 H675 R100-100, ahk_class AutoHotkeyGUI ; GUI shape
Gui, Add, Button, x46 y450 w100 h40 , Save
Gui, Add, Button, x166 y450 w100 h40 , Load
gosub, ButtonLoad
OnExit, ExitSub
Return
WM_MOUSEMOVE( wparam, lparam, msg, hwnd ) ; drag
{
if wparam = 1 ; LButton
PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}
WheelUp::Up ; scroll
WheelDown::Down
ButtonSave: ; IniWrite
Gui, Submit, NoHide
IniWrite, %MyGUI%, GUI.ini, Section, GUI key
Return
ButtonLoad: ; IniRead
IniRead, MyGUI, GUI.ini, Section, GUI key
GuiControl, , GUIID, %MyGUI%
Return
ExitSub:
gosub, ButtonSave
Enter::ExitApp
Re: Learning IniWrite & IniRead
It works for me though
At least saving works, that is, loading does not.
Code: Select all
[Section]
GUI key=asdfsadf
Re: Learning IniWrite & IniRead
Your ini read should rather look like this
...for that single value.
The exit behavior is weird, below gosub, ButtonSave should be an ExitApp, as that from Enter::ExitSub is only for Enter.
And .ini files are for simple values, not sure if you can actually load multiline text, for that I'd do sth like:
and
Code: Select all
IniRead, iniValue, GUI.ini, Section, GUI key
GuiControl, Text, MyGUI, %iniValue%
The exit behavior is weird, below gosub, ButtonSave should be an ExitApp, as that from Enter::ExitSub is only for Enter.
And .ini files are for simple values, not sure if you can actually load multiline text, for that I'd do sth like:
Code: Select all
iniValue := StrReplace(MyGUI, "`n", "``n")
<save>
Code: Select all
<load>
iniValue := StrReplace(iniValue, "``n", "`n")
GuiControl, Text, MyGUI, %iniValue%
Re: Learning IniWrite & IniRead
When I tried to put this into my script, it said that this isn't a recognized action.
Hardcoder wrote: ↑04 Mar 2022, 22:02Your ini read should rather look like this...for that single value.Code: Select all
IniRead, iniValue, GUI.ini, Section, GUI key GuiControl, Text, MyGUI, %iniValue%
The exit behavior is weird, below gosub, ButtonSave should be an ExitApp, as that from Enter::ExitSub is only for Enter.
Enter::ExitSub didn't work so I just used ExitSub.
Here's my script with your other suggestions (the script still doesn't save or load):
Code: Select all
#SingleInstance, Force
Gui, Show, x825 y163 w485 h800 ; GUI
Gui, color, 9CB4B3 ; GUI background color
Gui, Font, s18 cOlive, Ink Free ; font
Gui, +Alwaysontop ; always on top
OnMessage( 0x200, "WM_MOUSEMOVE" ) ; drag
WinSet, Style, -0xC00000, A ; no title bar
Gui, Add, Text,, `n`n ; blank lines
Gui, Add, Edit, r10 w400 vMyGUI -VScroll ; text box without scrollbar
Gui, color,,ECD4C2 ; text box background color
WinSet, Region, 0-100 300-300 w555 H675 R100-100, ahk_class AutoHotkeyGUI ; GUI shape
Gui, Add, Button, x46 y450 w100 h40 , Save
Gui, Add, Button, x166 y450 w100 h40 , Load
gosub, ButtonLoad
OnExit, ExitSub
Return
WM_MOUSEMOVE( wparam, lparam, msg, hwnd ) ; drag
{
if wparam = 1 ; LButton
PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
}
WheelUp::Up ; scroll
WheelDown::Down
ButtonSave: ; IniWrite
Gui, Submit, NoHide
IniWrite, %MyGUI%, GUI.ini, Section, GUI key
Return
ButtonLoad: ; IniRead
IniRead, iniValue, GUI.ini, Section, GUI key
GuiControl, , GUIID, %MyGUI%
Return
iniValue := StrReplace(MyGUI, "`n", "``n")
<save>
<load>
iniValue := StrReplace(iniValue, "``n", "`n")
GuiControl, Text, MyGUI, %iniValue%
ExitSub:
gosub, ButtonSave
ExitApp
Re: Learning IniWrite & IniRead
You left my placeholders <save> and <load> in the script, they were meant to be replaced by your code to save/load.
When I place the code above/below them at the respective positions, it works.
I don't post the corrections, you need to understand why and where, it's not much to do, and these placeholders do tell you.
When I place the code above/below them at the respective positions, it works.
I don't post the corrections, you need to understand why and where, it's not much to do, and these placeholders do tell you.
Re: Learning IniWrite & IniRead
Thank you very much. Two questions though:
- Where is the ini file saved?
- If I were to add a hotkey, how would you close the GUI to keep this script running?
Re: Learning IniWrite & IniRead
From IniWrite:
RussFilename
The name of the .ini file, which is assumed to be in %A_WorkingDir% if an absolute path isn't specified.
Re: Learning IniWrite & IniRead
Thanks @Hardcoder, I hit submit and forgot all about the second question.
Russ
Russ
Re: Learning IniWrite & IniRead
How would I assign a file path to save the ini file?
Who is online
Users browsing this forum: Google [Bot] and 124 guests