Jump to content
Sign in to follow this  
BitByteBit

Listen for a button that isn't created yet

Recommended Posts

BitByteBit

It goes as such:

1. User drags a .lnk

2. Shortcut source is written to .ini

3. Program creates a button corresponding to path in .ini(Also sets icon on the button)

My problem is that I need the button to correspond to an action, but I can't have a "Case $Button1" in the While loop because on startup it might not exists.

Here is what I have so far, quite a leap from what I started with 12 hours ago if I say so myself(see earlier topic).

ANY pointers or hints will be greatly appreciated!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ButtonConstants.au3>

dim $detail[1],$ProgArray[1]
$Gui = GUICreate("Laiz",153, 200, 192, 124,$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
$Go = GUICtrlCreateButton("Go!",117, 153, 32, 21)
$Program = GUICtrlCreateInput("", 0, 155, 118, 18)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState(@SW_SHOW)

$L1 = IniRead("C:\Vault.ini","Programs",1,"Not Found")
$L2 = IniRead("C:\Vault.ini","Programs",2,"Not Found")
$L3 = IniRead("C:\Vault.ini","Programs",3,"Not Found")
$L4 = IniRead("C:\Vault.ini","Programs",4,"Not Found")
$L5 = IniRead("C:\Vault.ini","Programs",5,"Not Found")
$L6 = IniRead("C:\Vault.ini","Programs",6,"Not Found")
$L7 = IniRead("C:\Vault.ini","Programs",7,"Not Found")
$L8 = IniRead("C:\Vault.ini","Programs",8,"Not Found")
$L9 = IniRead("C:\Vault.ini","Programs",9,"Not Found")

if $L1  <> "Not Found" then $Button1 = GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L1,1)
if $L2  <> "Not Found" then $Button2 = GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L2,1)
if $L3  <> "Not Found" then $Button3 = GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L3,1)
if $L4  <> "Not Found" then $Button4 = GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L4,1)
if $L5  <> "Not Found" then $Button5 = GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L5,1)
if $L6  <> "Not Found" then $Button6 =GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L6,1)
if $L7  <> "Not Found" then $Button7 =GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L7,1)
if $L8  <> "Not Found" then $Button8 = GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L8,1)
if $L9  <> "Not Found" then $Button9 = GUICtrlCreateButton("", 100, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L9,1)




While 1
   $Msg = GUIGetMsg()
    Switch $Msg
        Case $Go
        $Prog_1 = GUICtrlRead($Program)
        $Detail = FileGetShortcut($Prog_1)
        If IsArray($Detail) Then
            Write()
    else
        $ProgArray = GUICtrlRead($Program)
        $Detail = $ProgArray
        Write()
    EndIf
    If not @error then
    if $msg = $Button1 then
    ShellExecute($L1)
endif
endif

            EndSwitch
WEnd







Func Write()
If $L1 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","1",$Detail [0])
GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
$L1 = IniRead("C:\Vault.ini","Programs",1,"Not Found")
GUICtrlSetImage(-1, $L1,1)
else
Write2()
EndIf
EndFunc
Func Write2()
If $L2 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","2",$Detail [0])
$Button2 = GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
$L2 = IniRead("C:\Vault.ini","Programs",2,"Not Found")
GUICtrlSetImage(-1, $L2,1)
else
Write3()
EndIf
EndFunc
Func Write3()
If $L3 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","3",$Detail [0])
$Button3 = GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
$L3 = IniRead("C:\Vault.ini","Programs",3,"Not Found")
GUICtrlSetImage(-1, $L3,1)
else
Write4()
EndIf
EndFunc
Func Write4()
If $L4 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","4",$Detail [0])
$Button4 = GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
$L4 = IniRead("C:\Vault.ini","Programs",4,"Not Found")
GUICtrlSetImage(-1, $L4,1)
else
Write5()
EndIf
EndFunc
Func Write5()
If $L5 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","5",$Detail [0])
$Button5 = GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
$L5 = IniRead("C:\Vault.ini","Programs",5,"Not Found")
GUICtrlSetImage(-1, $L5,1)
else
Write6()
EndIf
EndFunc
Func Write6()
If $L6 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","6",$Detail [0])
$Button6 =GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
$L6 = IniRead("C:\Vault.ini","Programs",6,"Not Found")
GUICtrlSetImage(-1, $L6,1)
else
Write7()
EndIf
EndFunc
Func Write7()
If $L7 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","7",$Detail [0])
$Button7 =GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
$L7 = IniRead("C:\Vault.ini","Programs",7,"Not Found")
GUICtrlSetImage(-1, $L7,1)
else
Write8()
EndIf
EndFunc
Func Write8()
If $L8 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","8",$Detail [0])
$Button8 = GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
$L8 = IniRead("C:\Vault.ini","Programs",8,"Not Found")
GUICtrlSetImage(-1, $L8,1)
else
Write9()
EndIf
EndFunc
Func Write9()
If $L9 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","9",$Detail [0])
$Button9 = GUICtrlCreateButton("", 100, 100, 50, 50, $BS_ICON)
$L9 = IniRead("C:\Vault.ini","Programs",9,"Not Found")
GUICtrlSetImage(-1, $L9,1)
EndIf
EndFunc

Share this post


Link to post
Share on other sites
water

"Predefine" it by using "Global $Button1" etc. at the top of your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
BitByteBit

Thank you for your reply

I tried that,it tries to run the line underneath, check for yourself if you don't understand what I mean.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ButtonConstants.au3>
Opt("TrayIconDebug",1)

dim $detail[1],$ProgArray[1]
Global $Button1,$Button2,$Button3,$Button4,$Button5,$Button6,$Button7,$Button8,$Button9
$Gui = GUICreate("Laiz",153, 200, 192, 124,$WS_MINIMIZEBOX,$WS_EX_ACCEPTFILES)
$Go = GUICtrlCreateButton("Go!",117, 153, 32, 21)
$Program = GUICtrlCreateInput("", 0, 155, 118, 18)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
GUISetState(@SW_SHOW)

$L1 = IniRead("C:\Vault.ini","Programs",1,"Not Found")
$L2 = IniRead("C:\Vault.ini","Programs",2,"Not Found")
$L3 = IniRead("C:\Vault.ini","Programs",3,"Not Found")
$L4 = IniRead("C:\Vault.ini","Programs",4,"Not Found")
$L5 = IniRead("C:\Vault.ini","Programs",5,"Not Found")
$L6 = IniRead("C:\Vault.ini","Programs",6,"Not Found")
$L7 = IniRead("C:\Vault.ini","Programs",7,"Not Found")
$L8 = IniRead("C:\Vault.ini","Programs",8,"Not Found")
$L9 = IniRead("C:\Vault.ini","Programs",9,"Not Found")

if $L1  <> "Not Found" then $Button1 = GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L1,1)
if $L2  <> "Not Found" then $Button2 = GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L2,1)
if $L3  <> "Not Found" then $Button3 = GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L3,1)
if $L4  <> "Not Found" then $Button4 = GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L4,1)
if $L5  <> "Not Found" then $Button5 = GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L5,1)
if $L6  <> "Not Found" then $Button6 =GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L6,1)
if $L7  <> "Not Found" then $Button7 =GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L7,1)
if $L8  <> "Not Found" then $Button8 = GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L8,1)
if $L9  <> "Not Found" then $Button9 = GUICtrlCreateButton("", 100, 100, 50, 50, $BS_ICON)
GUICtrlSetImage(-1, $L9,1)




While 1
   $Msg = GUIGetMsg()
    Switch $Msg
        Case $Go
        $Prog_1 = GUICtrlRead($Program)
        $Detail = FileGetShortcut($Prog_1)
        If IsArray($Detail) Then
            Write()
    else
        $ProgArray = GUICtrlRead($Program)
        $Detail = $ProgArray
        Write()
    EndIf
    Case $Button1
    ShellExecute($L1)
    Case $Button2
    ShellExecute($L2)
    Case $Button3
    ShellExecute($L3)
    Case $Button4
    ShellExecute($L4)
    Case $Button5
    ShellExecute($L5)
    Case $Button6
    ShellExecute($L6)
    Case $Button7
    ShellExecute($L7)
    Case $Button8
    ShellExecute($L8)
    Case $Button9
    ShellExecute($L9)
    EndSwitch
WEnd







Func Write()
If $L1 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","1",$Detail [0])
GUICtrlCreateButton("", 0, 0, 50, 50, $BS_ICON)
$L1 = IniRead("C:\Vault.ini","Programs",1,"Not Found")
GUICtrlSetImage(-1, $L1,1)
else
Write2()
EndIf
EndFunc
Func Write2()
If $L2 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","2",$Detail [0])
$Button2 = GUICtrlCreateButton("", 50, 0, 50, 50, $BS_ICON)
$L2 = IniRead("C:\Vault.ini","Programs",2,"Not Found")
GUICtrlSetImage(-1, $L2,1)
else
Write3()
EndIf
EndFunc
Func Write3()
If $L3 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","3",$Detail [0])
$Button3 = GUICtrlCreateButton("", 100, 0, 50, 50, $BS_ICON)
$L3 = IniRead("C:\Vault.ini","Programs",3,"Not Found")
GUICtrlSetImage(-1, $L3,1)
else
Write4()
EndIf
EndFunc
Func Write4()
If $L4 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","4",$Detail [0])
$Button4 = GUICtrlCreateButton("", 0, 50, 50, 50, $BS_ICON)
$L4 = IniRead("C:\Vault.ini","Programs",4,"Not Found")
GUICtrlSetImage(-1, $L4,1)
else
Write5()
EndIf
EndFunc
Func Write5()
If $L5 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","5",$Detail [0])
$Button5 = GUICtrlCreateButton("", 50, 50, 50, 50, $BS_ICON)
$L5 = IniRead("C:\Vault.ini","Programs",5,"Not Found")
GUICtrlSetImage(-1, $L5,1)
else
Write6()
EndIf
EndFunc
Func Write6()
If $L6 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","6",$Detail [0])
$Button6 =GUICtrlCreateButton("", 100, 50, 50, 50, $BS_ICON)
$L6 = IniRead("C:\Vault.ini","Programs",6,"Not Found")
GUICtrlSetImage(-1, $L6,1)
else
Write7()
EndIf
EndFunc
Func Write7()
If $L7 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","7",$Detail [0])
$Button7 =GUICtrlCreateButton("", 0, 100, 50, 50, $BS_ICON)
$L7 = IniRead("C:\Vault.ini","Programs",7,"Not Found")
GUICtrlSetImage(-1, $L7,1)
else
Write8()
EndIf
EndFunc
Func Write8()
If $L8 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","8",$Detail [0])
$Button8 = GUICtrlCreateButton("", 50, 100, 50, 50, $BS_ICON)
$L8 = IniRead("C:\Vault.ini","Programs",8,"Not Found")
GUICtrlSetImage(-1, $L8,1)
else
Write9()
EndIf
EndFunc
Func Write9()
If $L9 = "Not Found" then
IniWrite("C:\Vault.ini","Programs","9",$Detail [0])
$Button9 = GUICtrlCreateButton("", 100, 100, 50, 50, $BS_ICON)
$L9 = IniRead("C:\Vault.ini","Programs",9,"Not Found")
GUICtrlSetImage(-1, $L9,1)
EndIf
EndFunc

Share this post


Link to post
Share on other sites
water

Initialize the variables with a value that isn't returned by GuiGetMsg:

Global $Button1=-1,$Button2=-1,$Button3=-1,$Button4=-1,$Button5=-1,$Button6=-1,$Button7=-1,$Button8=-1,$Button9=-1
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.