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 

GUI: Dynamically generated buttons' gosubs

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Hülyesamu



Joined: 24 Sep 2004
Posts: 17

PostPosted: Tue Jan 01, 2008 3:28 pm    Post subject: GUI: Dynamically generated buttons' gosubs Reply with quote

Hi, I want to create a popup menu made of array of buttons that reads its content from a text file. (Ie. The first button has a text of THIS, and does THAT, both definded in the text file).

Certeanly, the buttons do the same, but with a different variable (more specifically, they send the keys that is written onto them: A "Kitchen" key says the keys k--i-t-c-h-e-n, etc)

Is it possible to do this in the AutoHotkey? Since the buttons need a "g label" gosub for everyone of them, but at a dynamically generated content it doesn't work.

Question
Back to top
View user's profile Send private message
Mustang



Joined: 17 May 2007
Posts: 415
Location: England

PostPosted: Tue Jan 01, 2008 4:04 pm    Post subject: Reply with quote

Create a text file called "File.txt" with the following in it:
Code:
Name1,Text1
Name2,Text2
Name3,Text3

Then in the same folder a file with the following AHK script:
Code:
Loop, Read, File.txt
{
    Count := A_Index
    Loop, Parse, A_LoopReadLine, `,
    {
        If ( A_Index = 1 )
        {
            MenuName%Count% := A_LoopField
        }
        Else
        {
            MenuText%Count% := A_LoopField
        }
    }
}

Loop, %Count%
{
    Menu, MyMenu, Add, % MenuName%A_Index%, MenuHandler
}
Return

MenuHandler:
{
    MsgBox, % MenuText%A_ThisMenuItemPos%
    Return
}

^!a::
{
    Menu, MyMenu, Show
    Return
}

Use Ctrl+Alt+a to bring up the menu
Edit to your pleasing
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Wed Jan 02, 2008 5:36 am    Post subject: Reply with quote

you can also do it with buttons. give them all the same glabel, and then make the label send/use %A_GuiControl%, which will contain up to the first 63 letters of the button's text.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Hülyesamu



Joined: 24 Sep 2004
Posts: 17

PostPosted: Wed Jan 02, 2008 9:26 am    Post subject: Reply with quote

Thanks, I'll try it.
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
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