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 

Noob ini and GUI menu togglecheck problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Sun Jul 20, 2008 8:11 am    Post subject: Noob ini and GUI menu togglecheck problem Reply with quote

Hi,

I'm having trouble attaching my GUI menu checkbox to a default ini state and to a function and then to write and save changes in the checkbox state to the ini and of course to alter the functions behaviour if the checkbox is checked or unchecked. I've looked for examples but the only one I found was over my head Embarassed . Can someone please show me how to do that with the information below.

Code:
ini state, if it's 1 I want to checkbox to start off checked
[default]

Checkbox=1

-----------------------------------------------------

IniRead, Checkbox, Notepad.ini, default, Checkbox,

-----------------------------------------------------

Menu, MyMenu, Add, &MenuItem, ToggleState
Menu, MenuBar, Add, &FirstMenu, :MyMenu
Gui, Menu, MenuBar

-----------------------------------------------------

ToggleState:
menu, MyMenu, ToggleCheck, &MenuItem
return

-----------------------------------------------------

MyFunction:

if(Checkbox)
  {   
    SetTimer, AutoRun, On
  }
  else
  {   
    SetTimer, AutoRun, Off
  }
return

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






PostPosted: Sun Jul 20, 2008 10:54 am    Post subject: Reply with quote

Code:
CheckBox=1

Menu, MyMenu, Add, &MenuItem, ToggleState
Menu, MenuBar, Add, &FirstMenu, :MyMenu
Gui, Menu, MenuBar
Gui, Show, w300 h300
Menu, MyMenu, % (CheckBox) ? "Check" : "Uncheck", &MenuItem
Return

ToggleState:
menu, MyMenu, ToggleCheck, &MenuItem
return
Back to top
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Sun Jul 20, 2008 12:00 pm    Post subject: Reply with quote

Thanks very much. Wow, never done anything like that, will give me plenty to think about. Really appreciate your help Smile
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Jul 20, 2008 12:04 pm    Post subject: Reply with quote

?: is ternary operator. you can shorten the code everywhere with ternary operator.
i'd recommend to read [VxE]'s ternary tutorial
hth
Back to top
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Sun Jul 20, 2008 1:43 pm    Post subject: Reply with quote

I like that way of doing things, I'll study up on that Wink
Back to top
View user's profile Send private message
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Sun Jul 20, 2008 6:23 pm    Post subject: Reply with quote

Do you have the function read it's original state from the ini, and after that from the toggling and then just rewrite the ini as you exit or do you change the ini with every toggle?
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Jul 20, 2008 7:23 pm    Post subject: Reply with quote

Use OnExit

Code:
OnExit, LabelName
Return

LabelName:
;Iniwrite here
MsgBox, Commands in this label will be executed at script exit
Return
Back to top
Guest






PostPosted: Sun Jul 20, 2008 7:37 pm    Post subject: Reply with quote

there was a mistake. replace return to Exitapp
Back to top
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Mon Jul 21, 2008 3:58 am    Post subject: Reply with quote

I was doing it each time and it would only switch once. I thought I had seen that in a script searching one day. Thanks again, you've been a great help Smile
Back to top
View user's profile Send private message
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Tue Jul 22, 2008 4:11 am    Post subject: Reply with quote

Code:
CheckBox=1

Menu, MyMenu, Add, &MenuItem, ToggleState
Menu, MenuBar, Add, &FirstMenu, :MyMenu
Gui, Menu, MenuBar
Gui, Show, w300 h300
Menu, MyMenu, % (CheckBox) ? "Check" : "Uncheck", &MenuItem
Return

ToggleState:
menu, MyMenu, ToggleCheck, &MenuItem
return


-----------------------------------------------------

MyFunction:

if(Checkbox)
  {   
    SetTimer, AutoRun, On
  }
  else
  {   
    SetTimer, AutoRun, Off
  }
return

-----------------------------------------------------



This is still giving me problems Embarassed . I've tried a million ways but I can only get 'myfuntion' to toggle once. The ticks keep toggling but the function itself doesn't. How do I connect 'MyFunction' to the &MenuItem tick box so that it can toggle on and off any amount of times? I guess it also needs a value so that 'checkbox' can be written back to the ini. Very confused, my non menu type checkboxes toggle back and forward without any problem. I can't even find a working script in the 'scripts and' functions' forum that uses the menu this way to study, nobody seems to do it this way....
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 913
Location: The Interwebs

PostPosted: Tue Jul 22, 2008 4:14 am    Post subject: Reply with quote

Code:
MyFunction:

if(Checkbox)
  {   
    SetTimer, AutoRun, On
  }
  else
  {   
    SetTimer, AutoRun, Off
  }
Checkbox := !Checkbox ;this will toggle the variable to true/false each time
return


is this what you're looking for?
Back to top
View user's profile Send private message AIM Address
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Tue Jul 22, 2008 5:52 am    Post subject: Reply with quote

If checkbox is the original reading (1 or 0) from the ini- how do I associate the ticking on and off from &MenuItem with MyFunction and to give me a value to write back to the ini on exit?

Perhaps I am missing something here..
Back to top
View user's profile Send private message
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Tue Jul 22, 2008 6:19 am    Post subject: Reply with quote

Perhaps I should clarify the state of my dimentia Laughing

Code:

ini state, if it's 1 I want to checkbox to start off checked
[default]

Checkbox=1

-----------------------------------------------------

Menu, MyMenu, Add, &MenuItem, ToggleState
Menu, MenuBar, Add, &FirstMenu, :MyMenu
Gui, Menu, MenuBar
Gui, Show, w300 h300

 So this next line simply starts the checkbox in the default position?

Menu, MyMenu, % (CheckBox) ? "Check" : "Uncheck", &MenuItem
Return


And this toggles the tick back and forth?

ToggleState:
menu, MyMenu, ToggleCheck, &MenuItem
return


-----------------------------------------------------

MyFunction:

if(Checkbox)
  {   
    SetTimer, AutoRun, On
  }
  else
  {   
    SetTimer, AutoRun, Off
  }

Checkbox := !Checkbox ;this will toggle the variable to true/false each time
return
-----------------------------------------------------


So what I don't see is how the script knows that MyFunction is associated with &MenuItem and what variable I can write to the ini so that 'checkbox' opens next startup where it ended up on exit...
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 913
Location: The Interwebs

PostPosted: Tue Jul 22, 2008 6:37 am    Post subject: Reply with quote

Logman wrote:

So what I don't see is how the script knows that MyFunction is associated with &MenuItem

It doesn't, for now. Add
Code:
GoSub, MyFunction

under the label "ToggleState" (beneath the line "Menu, MyMenu, ToggleCheck, &MenuItem")


Logman wrote:

and what variable I can write to the ini so that 'checkbox' opens next startup where it ended up on exit...


You would write/read the variable "Checkbox"
Back to top
View user's profile Send private message AIM Address
Logman



Joined: 19 Feb 2008
Posts: 54

PostPosted: Tue Jul 22, 2008 7:41 am    Post subject: Reply with quote

Fantastic, got it working. Two remaining problems. It is not writing 0 to the ini if it is unchecked on exit but I'm not sure how to do that with this in the script - Checkbox := !Checkbox, do I need to give check and uncheck the values of 1 and 0 somewhere? My attempt is down the bottom. And second, the function in my script has a mousemove in it, with these alterations the mousemove is not happening but the clicking etc still is, any reason you can think of why that may be? The exact same script without a menu has the mousemove working fine Surprised .I now have this-

Code:

IniRead, Checkbox, MyScript.ini, MyItems, Checkbox

;-------------------------------------------------------------

Menu, MyMenu, Add, &MenuItem, ToggleState
Menu, MenuBar, Add, &FirstMenu, :MyMenu
Gui, Menu, MenuBar

Menu, MyMenu, % (CheckBox) ? "Check" : "Uncheck", &MenuItem
Return

;-------------------------------------------------------------

SetTimer, AutoRun, 1000
GoSub, MyFunction

;-------------------------------------------------------------

ToggleState:
menu, MyMenu, ToggleCheck, &MenuItem
GoSub, MyFunction
return

;-------------------------------------------------------------

MyFunction:

if(Checkbox)
  {   
    SetTimer, AutoRun, On
  }
  else
  {   
    SetTimer, AutoRun, Off
  }
Checkbox := !Checkbox
return

;-------------------------------------------------------------

OnExit, CheckboxStatus
Exitapp

CheckboxStatus:
IniWrite, %Checkbox% , MyScript.ini, MyItems, Checkbox

GuiClose:
ExitApp


;-------------------------------------------------------------



Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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