Sign in to follow this  
Followers 0
John117

How to make a clickable list instead of buttons

3 posts in this topic

I have the following code that creates a gui with buttons from a script. The end result is a GUI driven windows messenger service.

I would like to change the buttons to a list generated by the array. Could each name in the new list be double clicked to generate a msg box? or would I highlight them and hit a general message button?

I how would I go about creating a list instead of buttons? Thanks for the help!

CODE
#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords

If Not _FileReadToArray( @ScriptDir & "\Add New Contacts Here.txt",$aRecords) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

;The above section is dependand on a txt file with the following name and format.

;Add New Contacts Here.txt -Must be in same directory script

;Userid1

;Userid2

;Userid3

;The txt file would only contain the above three examples or more if you wish. you should not leave space below any names

Dim $aButtons[uBound($aRecords)]

$aHeight = (UBound($aRecords) * 25) + 60

; START NET SEND

RunWait("net start messenger", "", @SW_HIDE)

; GUI

$window = GUICreate(@UserName & "'s Messenger", 250, $aHeight)

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; MENU

$filemenu = GuiCtrlCreateMenu ("File")

$fileitem = GuiCtrlCreateMenuitem ("Add Contacts...",$filemenu)

$separator1 = GuiCtrlCreateMenuitem ("",$filemenu)

$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)

;LABEL - TO BE ADDED WITH USERID DETAIL

$CurrentUserName = GUICtrlCreateLabel("Type Message *Press Button to Send*", 20, 10, 200, 20)

;$CurrentUserName = GUICtrlCreateLabel("My Messenger", 90, 10)

; INPUT

$Edit1 = GUICtrlCreateEdit("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

;$input = GUICtrlCreateInput("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

;BUILD BUTTONS

$aTop = 100

$aLeft = 10

For $x = 1 to $aRecords[0]

$aButtons[$x] = GUICtrlCreateButton( $aRecords[$x], $aLeft, $aTop, 100, 30)

If $aLeft = 10 Then

$aLeft = 140

ContinueLoop

Else

$aLeft = 10

$aTop = $aTop + 40

EndIf

Next

;SET BUTTON FUNCTIONS

GUISetState()

While 1

$cursorinfo = GUIGetCursorInfo($window)

If $cursorinfo[4] = $Edit1 Then

If $cursorinfo[2] = 1 Then

GUICtrlSetData($Edit1, "")

EndIf

EndIf

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

If $msg = $exititem Then Exit

Select

Case $msg = $fileitem

ShellExecute("Add New Contacts Here.txt", "", @ScriptDir, "edit")

EndSelect

For $x = 1 to $aRecords[0]

If $msg = $aButtons[$x] Then

Run("net send " & $aRecords[$x] & " Mesage From " & @UserName & ": " & StringReplace(GUICtrlRead($Edit1), @CRLF, " "), "", @SW_HIDE)

MsgBox(0, "Message Sent", "message to "&$aRecords[$x]&": "& StringReplace(GUICtrlRead($Edit1), @CRLF, " "))

EndIf

Next

WEnd

:)

Share this post


Link to post
Share on other sites



I have the following code that creates a gui with buttons from a script. The end result is a GUI driven windows messenger service.

I would like to change the buttons to a list generated by the array. Could each name in the new list be double clicked to generate a msg box? or would I highlight them and hit a general message button?

I how would I go about creating a list instead of buttons? Thanks for the help!

CODE
#include <GuiConstants.au3>

#include <file.au3>

Dim $aRecords

If Not _FileReadToArray( @ScriptDir & "\Add New Contacts Here.txt",$aRecords) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

;The above section is dependand on a txt file with the following name and format.

;Add New Contacts Here.txt -Must be in same directory script

;Userid1

;Userid2

;Userid3

;The txt file would only contain the above three examples or more if you wish. you should not leave space below any names

Dim $aButtons[uBound($aRecords)]

$aHeight = (UBound($aRecords) * 25) + 60

; START NET SEND

RunWait("net start messenger", "", @SW_HIDE)

; GUI

$window = GUICreate(@UserName & "'s Messenger", 250, $aHeight)

GUISetIcon(@SystemDir & "\mspaint.exe", 0)

; MENU

$filemenu = GuiCtrlCreateMenu ("File")

$fileitem = GuiCtrlCreateMenuitem ("Add Contacts...",$filemenu)

$separator1 = GuiCtrlCreateMenuitem ("",$filemenu)

$exititem = GuiCtrlCreateMenuitem ("Exit",$filemenu)

;LABEL - TO BE ADDED WITH USERID DETAIL

$CurrentUserName = GUICtrlCreateLabel("Type Message *Press Button to Send*", 20, 10, 200, 20)

;$CurrentUserName = GUICtrlCreateLabel("My Messenger", 90, 10)

; INPUT

$Edit1 = GUICtrlCreateEdit("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

;$input = GUICtrlCreateInput("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

;BUILD BUTTONS

$aTop = 100

$aLeft = 10

For $x = 1 to $aRecords[0]

$aButtons[$x] = GUICtrlCreateButton( $aRecords[$x], $aLeft, $aTop, 100, 30)

If $aLeft = 10 Then

$aLeft = 140

ContinueLoop

Else

$aLeft = 10

$aTop = $aTop + 40

EndIf

Next

;SET BUTTON FUNCTIONS

GUISetState()

While 1

$cursorinfo = GUIGetCursorInfo($window)

If $cursorinfo[4] = $Edit1 Then

If $cursorinfo[2] = 1 Then

GUICtrlSetData($Edit1, "")

EndIf

EndIf

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then Exit

If $msg = $exititem Then Exit

Select

Case $msg = $fileitem

ShellExecute("Add New Contacts Here.txt", "", @ScriptDir, "edit")

EndSelect

For $x = 1 to $aRecords[0]

If $msg = $aButtons[$x] Then

Run("net send " & $aRecords[$x] & " Mesage From " & @UserName & ": " & StringReplace(GUICtrlRead($Edit1), @CRLF, " "), "", @SW_HIDE)

MsgBox(0, "Message Sent", "message to "&$aRecords[$x]&": "& StringReplace(GUICtrlRead($Edit1), @CRLF, " "))

EndIf

Next

WEnd

:)
$List = GUICtrlCreateList("", 10, 10, 50, 100)
$L_Data = ''
For $x = 1 to $aRecords[0]
 $L_Data &= $aRecords[$x] &'|'
Next
GUICtrlSetData($List, StringTrimRight($L_Data,1))

A better method of setting the data would be using _GUICtrlListInsertItem() from the GUIList.au3 file in the include folder.

See List Management in the UDF's section of the help file for examples.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thank you! Sorry I missed your post because it wasnt in myusual forum :) I will get to reading!

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  
Followers 0