Jump to content

GUI To Add Text, remove text and edit text.


Hyflex
 Share

Recommended Posts

Hey,

I've managed to get so far on creating a little script, I've done the GUI as best as I can but I have now come to the bit I have no idea about... If you launch the GUI below it's fairly easy to see what my aim is...

I need to use the "Accounts" section to have a list of accounts (stored in a text/ini file)

If they were to press Edit Account it would put the username and password into the respective input boxs,

If they edit any details then press "Add/Save Account" it will update the username/password in the text/ini file

If they were to press Remove Account it would delete the account from the list and from the text/ini file

As for the launch button nothing needs to be done with that other than a way so whatever is selected in "Accounts" Section it creates $Username and $Password actually have a valuie.

If anyone could give me some pointers I would much appreciate it.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)

Local $GUIWidth = 350, $GUIHeight = 190
Dim $PosX= (@DesktopWidth - $GUIWidth) / 2
Dim $PosY = (@DesktopHeight - $GUIHeight) / 2

$GUIForm = GUICreate("Launcher", $GUIWidth, $GUIHeight, $PosX, $PosY)

GUISetOnEvent($GUI_EVENT_CLOSE, "GUICloseEvent")

$GUIAddAccountBtn = GUICtrlCreateButton("Add/Save Account", 8, 152, 329, 25)
GUICtrlSetOnEvent(-1, "GUIAddAccountBtnClick")
$GUIRemoveAccountBtn = GUICtrlCreateButton("Remove Account", 128, 64, 105, 25)
GUICtrlSetOnEvent(-1, "GUIRemoveAccountBtnClick")
$GUIEditAccountBtn = GUICtrlCreateButton("Edit Account", 16, 64, 105, 25)
GUICtrlSetOnEvent(-1, "GUIEditAccountBtnClick")
$GUIStartLauncherBtn = GUICtrlCreateButton("Start Launcher", 240, 8, 97, 89)
GUICtrlSetOnEvent(-1, "GUIStartLauncherBtnClick")

$GUIAccountSelector = GUICtrlCreateCombo("", 24, 24, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "GUIAccountSelectorChange")

$GUIUsernameInput = GUICtrlCreateInput("", 16, 112, 145, 21)
$GUIPasswordInput = GUICtrlCreateInput("", 184, 112, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))

$GUIAccountGroup = GUICtrlCreateGroup("Account(s)", 16, 8, 217, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GUIPasswordGroup = GUICtrlCreateGroup("Password", 174, 96, 161, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GUIUsernameGroup = GUICtrlCreateGroup("Username", 6, 96, 161, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

While 1
Sleep(100)
WEnd

Func GUICloseEvent()
; Add stuff here later
Exit
EndFunc   ;==>Form1Close


Func GUIAccountSelectorChange()

EndFunc   ;==>GUIAccountSelectorChange

Func GUIAddAccountBtnClick()

EndFunc   ;==>GUIAddAccountBtnClick

Func GUIEditAccountBtnClick()

EndFunc   ;==>GUIEditAccountBtnClick

Func GUIRemoveAccountBtnClick()

EndFunc   ;==>GUIRemoveAccountBtnClick

Func GUIStartLauncherBtnClick()
; Use IE.au3 here along with some other stuff
EndFunc   ;==>GUIStartLauncherBtnClick
Edited by XxXGoD
Link to comment
Share on other sites

Did you look at the following?

IniWrite

IniWrite

IniDelete

They are good for a small database. If how ever the database is going to be huge look at

_SqLite

I take it the first or second one was "IniRead"

Yeah I looked at them but I don't know how to link them with the GUI, the database is going to be max of 20-25 accounts

Edited by XxXGoD
Link to comment
Share on other sites

I take it the first or second one was "IniRead"

Yeah I looked at them but I don't know how to link them with the GUI, the database is going to be max of 20-25 accounts

Correct tx.

Looking @ this again ... How secure must these saved passwords be?

Are you familiar with arrays?

Link to comment
Share on other sites

Correct tx.

Looking @ this again ... How secure must these saved passwords be?

Are you familiar with arrays?

This is as far as I've got so far... adding two lines:

$Username = GUICtrlRead($GUIUsernameInput)
$Password = GUICtrlRead($GUIPasswordInput)

Arrays confuse the hell out of me and as for security, they can be in text format It doesn't matter at all.

Link to comment
Share on other sites

Only way I've got the combo box semi-working is:

$LoginNamesRead = IniReadSectionNames("HoLogin.ini")
$LoginNames = $LoginNamesRead[1] & '|' & $LoginNamesRead[2] & '|' & $LoginNamesRead[3] & '|' & $LoginNamesRead[4] & '|' & $LoginNamesRead[5] & '|' & $LoginNamesRead[6] & '|'

I can't get hardly any of this working right, im sure after the combo box i'm going to struggle with the edits and the adds... and definately remove

Edited by XxXGoD
Link to comment
Share on other sites

Only way I've got the combo box semi-working is:

$LoginNamesRead = IniReadSectionNames("HoLogin.ini")
$LoginNames = $LoginNamesRead[1] & '|' & $LoginNamesRead[2] & '|' & $LoginNamesRead[3] & '|' & $LoginNamesRead[4] & '|' & $LoginNamesRead[5] & '|' & $LoginNamesRead[6] & '|'

I can't get hardly any of this working right, im sure after the combo box i'm going to struggle with the edits and the adds... and definately remove

Yes there is some work to be done. In stead of doing all of the hard work it can be worth working throug some examples like

If you still have a problem post it here.

Link to comment
Share on other sites

Thanks that helped a fair bit but i've come across some more problems, below is my current code.

1) If I remove all the names from the ini file the macro won't even run...

2) The following selects the first name in the list, I need one to pick the last name in the list...

GUICtrlSetData($GUIAccountSelector, $HoAccounts[1])

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

; Miscellaneous Settings
Opt("GUIOnEventMode", 1)

; Global Variables
Global $HoIni = @ScriptDir & "HoLogin.ini"
Global $HoAccounts

; Find true GUI center
Local $GUIWidth = 350, $GUIHeight = 190
Dim $PosX = (@DesktopWidth - $GUIWidth) / 2
Dim $PosY = (@DesktopHeight - $GUIHeight) / 2

; GUI Launcher
$GUIForm = GUICreate("HoLauncher", $GUIWidth, $GUIHeight, $PosX, $PosY)

; GUI On Event
GUISetOnEvent($GUI_EVENT_CLOSE, "GUICloseEvent")

; GUI Buttons
$GUIAddAccountBtn = GUICtrlCreateButton("Add Account", 8, 152, 329, 25)
GUICtrlSetOnEvent(-1, "GUIAddAccountBtnClick")
$GUIRemoveAccountBtn = GUICtrlCreateButton("Remove Account", 128, 64, 105, 25)
GUICtrlSetOnEvent(-1, "GUIRemoveAccountBtnClick")
$GUISaveAccountBtn = GUICtrlCreateButton("Update Account", 16, 64, 105, 25)
GUICtrlSetOnEvent(-1, "GUISaveAccountBtnClick")
$GUIStartLauncherBtn = GUICtrlCreateButton("Start Launcher", 240, 8, 97, 89)
GUICtrlSetOnEvent(-1, "GUIStartLauncherBtnClick")

; GUI ComboBox
$GUIAccountSelector = GUICtrlCreateCombo("", 24, 24, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "GUIAccountSelectorChange")
;GUICtrlSetData(-1, "" )

; GUI Inputs
$GUIUsernameInput = GUICtrlCreateInput("", 16, 112, 145, 21)
$GUIPasswordInput = GUICtrlCreateInput("", 184, 112, 145, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))

; GUI Groups
$GUIAccountGroup = GUICtrlCreateGroup("Account(s)", 16, 8, 217, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GUIPasswordGroup = GUICtrlCreateGroup("Password", 174, 96, 161, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$GUIUsernameGroup = GUICtrlCreateGroup("Username", 6, 96, 161, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)

; Call GetHoAccounts
If IniReadSectionNames($HoIni) <> @error Then GetHoAccounts()

; Set Default
GUICtrlSetData($GUIAccountSelector, $HoAccounts[1])

; Change Inputs
$Username = GUICtrlRead($GUIAccountSelector)
$Password = IniRead($HoIni, GUICtrlRead($GUIAccountSelector), "Password", "")
GUICtrlSetData($GUIUsernameInput, $Username)
GUICtrlSetData($GUIPasswordInput, $Password)

; Show GUI
GUISetState(@SW_SHOW)

; While Loop
While 1
Sleep(50)
WEnd

; Get HoAccounts from Ini File
Func GetHoAccounts()
$HoAccounts = IniReadSectionNames($HoIni)
For $i = 1 To $HoAccounts[0]
GUICtrlSetData($GUIAccountSelector, $HoAccounts[$i])
Next
EndFunc   ;==>GetHoAccounts


; Change Account from ComboBox
Func GUIAccountSelectorChange()

; Read account
$Username = GUICtrlRead($GUIAccountSelector)
$Password = IniRead($HoIni, GUICtrlRead($GUIAccountSelector), "Password", "")

; Update inputs
GUICtrlSetData($GUIUsernameInput, $Username)
GUICtrlSetData($GUIPasswordInput, $Password)

EndFunc   ;==>GUIAccountSelectorChange


; Add and/or Save Account
Func GUIAddAccountBtnClick()

; Write new account.
IniWriteSection($HoIni, GUICtrlRead($GUIUsernameInput), "")
IniWrite($HoIni, GUICtrlRead($GUIUsernameInput), "Password", GUICtrlRead($GUIPasswordInput))

; Clear Inputs
GUICtrlSetData($GUIUsernameInput, "")
GUICtrlSetData($GUIPasswordInput, "")

; Update Account List
GUICtrlSetData($GUIAccountSelector, "")
GetHoAccounts()

; Set Default
GUICtrlSetData($GUIAccountSelector, $HoAccounts[1])

; Change Inputs
;$Username = GUICtrlRead($GUIAccountSelector)
;$Password = IniRead($HoIni, GUICtrlRead($GUIAccountSelector), "Password", "")
;GUICtrlSetData($GUIUsernameInput, $Username)
;GUICtrlSetData($GUIPasswordInput, $Password)

EndFunc   ;==>GUIAddAccountBtnClick


; Save Account
Func GUISaveAccountBtnClick()

; Find account
$Username = GUICtrlRead($GUIAccountSelector)

; Delete old account
IniDelete($HoIni, $Username)

; Update account list
GUICtrlSetData($GUIAccountSelector, "")
GetHoAccounts()

; Read new account
$Username = GUICtrlRead($GUIUsernameInput)
$Password = GUICtrlRead($GUIPasswordInput)

; Write new account
IniWriteSection($HoIni, GUICtrlRead($GUIUsernameInput), "")
IniWrite($HoIni, GUICtrlRead($GUIUsernameInput), "Password", GUICtrlRead($GUIPasswordInput))

; Clear Inputs
GUICtrlSetData($GUIUsernameInput, "")
GUICtrlSetData($GUIPasswordInput, "")

; Update account list
GUICtrlSetData($GUIAccountSelector, "")
GetHoAccounts()

; Set Default
GUICtrlSetData($GUIAccountSelector, $HoAccounts[1])

; Change Inputs
;$Username = GUICtrlRead($GUIAccountSelector)
;$Password = IniRead($HoIni, GUICtrlRead($GUIAccountSelector), "Password", "")
;GUICtrlSetData($GUIUsernameInput, $Username)
;GUICtrlSetData($GUIPasswordInput, $Password)

EndFunc   ;==>GUISaveAccountBtnClick


; Remove Account
Func GUIRemoveAccountBtnClick()

; Find Account
$Username = GUICtrlRead($GUIAccountSelector)

; Delete Account
IniDelete($HoIni, $Username)

; Update Account List
GUICtrlSetData($GUIAccountSelector, "")
GetHoAccounts()

; Set Default
GUICtrlSetData($GUIAccountSelector, $HoAccounts[1])

; Clear Inputs
GUICtrlSetData($GUIUsernameInput, "")
GUICtrlSetData($GUIPasswordInput, "")

; Change Inputs
;$Username = GUICtrlRead($GUIAccountSelector)
;$Password = IniRead($HoIni, GUICtrlRead($GUIAccountSelector), "Password", "")
;GUICtrlSetData($GUIUsernameInput, $Username)
;GUICtrlSetData($GUIPasswordInput, $Password)

EndFunc   ;==>GUIRemoveAccountBtnClick


; Start Launcher
Func GUIStartLauncherBtnClick()
; Use IE.au3 here along with some other stuff
EndFunc   ;==>GUIStartLauncherBtnClick


; Exit Program
Func GUICloseEvent()
; Add stuff here later
Exit
EndFunc   ;==>GUICloseEvent
Edited by XxXGoD
Link to comment
Share on other sites

Thanks that helped a fair bit but i've come across some more problems, below is my current code.

1) If I remove all the names from the ini file the macro won't even run...

2) The following selects the first name in the list, I need one to pick the last name in the list

1) When I fill in the info and press Add it works ! ?

2)You can add the following just before the GUISetState

GUICtrlSetState($GUIAccountSelector, $GUI_FOCUS) ; set focus
Send("{END}{down}")

Or get the correct GUICtrlSendMsg

Link to comment
Share on other sites

1) When I fill in the info and press Add it works ! ?

2)You can add the following just before the GUISetState

GUICtrlSetState($GUIAccountSelector, $GUI_FOCUS) ; set focus
Send("{END}{down}")

Or get the correct GUICtrlSendMsg

Thanks once again, however if you try and run the whole macro with a blank/empty ini file it goes wrong or press remove loads of times until all accounts are gone...

EDIT: I've tried the {END}{DOWN} but it doesn't work so I tried {PGDN} and it worked perfect :)

Edited by XxXGoD
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...