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 

Set Toggle Menu in ini file

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Newbie 64
Guest





PostPosted: Mon Sep 14, 2009 9:48 pm    Post subject: Set Toggle Menu in ini file Reply with quote

Could somebody help me out a little please.
I have entered the code below and I only want to get the toggle text on the Tray Menu to read the ini file when it is first opened, but it always seems to revert back to the default (of ...on) and ignores the ini file.

Could somebody show me where i have gone wrong?


Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
SetTitleMatchMode, Slow
IniRead, t_MenuItemHide, C:\Hotkey.ini, Section, Key
;---------------------------------------------------------
; Names for the tray menu items:
t_MenuItemHide = Ignore Word On
t_MenuItemShow = Ignore Word Off
;---------------------------------------------------------
Menu, Tray, Add, %t_MenuItemHide%, t_ShowHide
Menu, Tray, Default, %t_MenuItemHide%
Menu, Tray, Add ;Separator
Menu, Tray, Add, Pause Script..., Pause
Menu, Tray, Add, Exit..., Exit
Menu, Tray, NoStandard

t_IsVisible = y
;---------------------------------------------------------
SetTimer, KeepAlive, 250
return
;---------------------------------------------------------
KeepAlive:
IfWinExist,Untitled - Notepad
{
WinActivate
  SendInput Add some text here
  Sleep, 400
WinWaitClose,Untitled - Notepad
}
else
if t_IsVisible = y
{
  ifWinExist, Document1 - Microsoft Word
    {
     WinActivate
     SendInput Add some pictures here
     WinWaitClose, Document1 - Microsoft Word
     }
}
Run, Calc.exe
Sleep, 1000
WinWaitClose, Calculator
return
;---------------------------------------------------------
t_ShowHide:
>^f11::
if t_IsVisible = y
{
   Menu, Tray, Rename, %t_MenuItemHide%, %t_MenuItemShow%
   t_IsVisible = n
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
else
{
   Menu, Tray, Rename, %t_MenuItemShow%, %t_MenuItemHide%
   t_IsVisible = y
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
return
;---------------------------------------------------------

Pause:
Pause
return

t_MenuExit:
Exit:
Msgbox, 4372, Warning , Are you sure you wish to Exit.
ifMsgBox, No   
return

ExitApp
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Sep 14, 2009 9:53 pm    Post subject: Reply with quote

Just a wild guess here, I see you're using c:\file.ext as a location. In general, processes do not have access to that directory. try using %A_ScriptDir%\file.ext as the location of the inifile and see if that works?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Newbie 64
Guest





PostPosted: Mon Sep 14, 2009 10:05 pm    Post subject: Reply with quote

Hi AnttiV

I only changed this file location for the forum as I thought everybody would have a c:\ drive.

It doesn't matter where it is, it just seems to ignore it.
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Sep 14, 2009 10:54 pm    Post subject: Reply with quote

You first read t_MenuItemHide from the Inifile, then explicitly define it in the next line, so any value that gets read from the file is overwritten.

Code:
IniRead, t_MenuItemHide, C:\Hotkey.ini, Section, Key
;---------------------------------------------------------
; Names for the tray menu items:
t_MenuItemHide = Ignore Word On


Also, you Write t_MenuItemShow, but Read t_MenuItemHide? Is this the way it should be?

EDIT: Also, the F11 hotkey saves the same variable, regardless of any settings!

Code:
>^f11::
if t_IsVisible = y
{
   Menu, Tray, Rename, %t_MenuItemHide%, %t_MenuItemShow%
   t_IsVisible = n
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
else
{
   Menu, Tray, Rename, %t_MenuItemShow%, %t_MenuItemHide%
   t_IsVisible = y
   IniWrite, %t_MenuItemShow%, C:\Hotkey.ini,Section, Key
}
return


EDIT3: Fingers quicker than brain, sorry Smile

Anyways, you'd better of reading/writing the value of t_IsVisible, than the menuitems, as they are just the labels, and t_IsVisible is the variable that is checked.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
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