John117 Posted July 9, 2007 Posted July 9, 2007 I woud like to put together some code that uses names in the code to create buttons. When I press the bottons (Which represent windows userid's, they insert the button name into a run command along with the value of a text box in the following format Run("net send " & $Userid & " " & $Message, "", @SW_MAXIMIZE) Can anyone help add the buttons and a suggestion for future names to make it easy to add?
John117 Posted July 9, 2007 Author Posted July 9, 2007 perhaps you want a simple inputbox on a GUI?Yes, the $Message will be the Input box. I know VBA not auto it, so I dont know how to add an onevent to a button. I have a button, but am not sure how to name it. or refer to its name when clicked.Any code on click would help me understand this.As for the message box. How would you obtain the value of this:GuiCtrlCreateInput("Write Message Here", 75, 120, 200, 100)???as in once it is changedmsgbox(0,"", GuiCtrlCreateInput.value or declare GuiCtrlCreateInput("Write Message Here", 75, 120, 200, 100)as $Messagethenmsgbox(0,"", $message
evilertoaster Posted July 9, 2007 Posted July 9, 2007 look at the helpfile in the 'OnEvent Mode' section of the GUI reference.
John117 Posted July 9, 2007 Author Posted July 9, 2007 Noted and working well now! Thanks! How do I get the value of the input box? looking in the help, to no gain . . .
SadBunny Posted July 9, 2007 Posted July 9, 2007 Noted and working well now! Thanks! How do I get the value of the input box? looking in the help, to no gain . . . Don't you just mean something like this? $a = InputBox("How old?","How old are you?",27) MsgBox(0,"test","the answer was: "&$a) Exit Roses are FF0000, violets are 0000FF... All my base are belong to you.
John117 Posted July 9, 2007 Author Posted July 9, 2007 well, what I was looking for can most easily be understood by running the code below. When the name is clicked, the end result will be taking the name of the botton and the value of the input box in the code. #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode ; GUI GuiCreate("Sample GUI", 250, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; MENU GuiCtrlCreateMenu("Menu&One") GuiCtrlCreateMenu("Menu&Two") GuiCtrlCreateMenu("MenuTh&ree") GuiCtrlCreateMenu("Menu&Four") GUICtrlCreateLabel("My Messenger", 90, 10) ; INPUT GuiCtrlCreateInput("Type Message Here", 10, 30, 230, 60) ;Left, Top, Right, Bottom ; BUTTON $button1 = GuiCtrlCreateButton("HATCHEDA", 10, 100, 100, 30) GUICtrlSetOnEvent($button1, "button1") Func Button1() MsgBox(4096,"Message Sent", "Hatcheda") EndFunc ;Left, Top, Right, Bottom ; BUTTON $button2 = GuiCtrlCreateButton("CROWEBRA", 140, 100, 100, 30) GUICtrlSetOnEvent($button2, "button2") Func Button2() MsgBox(4096,"Message Sent", "Crowebra") EndFunc ; GUI MESSAGE LOOP GuiSetState() While GuiGetMsg() <> $GUI_EVENT_CLOSE WEnd
SadBunny Posted July 9, 2007 Posted July 9, 2007 (edited) I completely rewrote your code, hope you don't mind... My code does what you want it to do, plus it eliminates the need for an OnEvent situation. This in turn will also eliminate the need to write a new function for every name, as well as make it VERY easy to add new names -just make a new button in the array!-. It is easier to read, easier to expand and way shorter ;-) #include <GuiConstants.au3> ; <- ditched OnEvent mode - way easier and shorter without it, no need for a function per button ; GUI GuiCreate("Sample GUI", 250, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; MENU GuiCtrlCreateMenu("Menu&One") GuiCtrlCreateMenu("Menu&Two") GuiCtrlCreateMenu("MenuTh&ree") GuiCtrlCreateMenu("Menu&Four") GUICtrlCreateLabel("My Messenger", 90, 10) ; INPUT $input = GuiCtrlCreateInput("Type Message Here", 10, 30, 230, 60) Dim $buttons[2]; <- make array to store buttons. In this way you can easily add as many buttons as you want without having to create functions for it $buttons[0] = GuiCtrlCreateButton("HATCHEDA", 10, 100, 100, 30) $buttons[1] = GuiCtrlCreateButton("CROWEBRA", 140, 100, 100, 30) ; GUI MESSAGE LOOP GuiSetState() While 1 $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit For $buttonLooper In $buttons; <- /edit: $buttonLooper will contain consecutively all array elements (buttons) in $buttons, so you can do with one function total instead of one function per button If $msg = $buttonLooper Then MsgBox(0,"test","message to "&GUICtrlRead($buttonLooper)&": "&GUICtrlRead($input)) EndIf Next WEnd /edit: added comment for the For ... In ... Edited July 9, 2007 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
evilertoaster Posted July 9, 2007 Posted July 9, 2007 You don't usualyl mix oneventmode and polling mode.On event mode is used by VB so you'll probly be most comfortable using it. Here is you code using that method- expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode ; GUI GuiCreate("Sample GUI", 250, 400) GuiSetIcon(@SystemDir & "\mspaint.exe", 0) ; MENU GuiCtrlCreateMenu("Menu&One") GuiCtrlCreateMenu("Menu&Two") GuiCtrlCreateMenu("MenuTh&ree") GuiCtrlCreateMenu("Menu&Four") GUICtrlCreateLabel("My Messenger", 90, 10) ; INPUT $input=GuiCtrlCreateInput("Type Message Here", 10, 30, 230, 60) ; BUTTON $button1 = GuiCtrlCreateButton("HATCHEDA", 10, 100, 100, 30) GUICtrlSetOnEvent($button1, "button1") ; BUTTON $button2 = GuiCtrlCreateButton("CROWEBRA", 140, 100, 100, 30) GUICtrlSetOnEvent($button2, "button2") GuiSetState() While 1 WEnd Func Button1() MsgBox(4096,"Message Sent", GUICtrlRead($input)) EndFunc Func Button2() MsgBox(4096,"Message Sent", GUICtrlRead($input)) EndFunc
SadBunny Posted July 9, 2007 Posted July 9, 2007 You don't usualyl mix oneventmode and polling mode.On event mode is used by VB so you'll probly be most comfortable using it. Here is you code using that method-You can ofcourse do that too But you will need to write your message sending function for every button, so writing the code will take longer and the code will be much more lengthy than needed if you have many contacts. If you're planning on frequently changing your script to accomodate for different contacts, I would advise against it...But ofcourse there are multiple roads leading to Rome... Roses are FF0000, violets are 0000FF... All my base are belong to you.
Valuater Posted July 9, 2007 Posted July 9, 2007 here's one i wrote a little while back expandcollapse popupDim $un = @UserName Dim $QT_web = "www.ClickTask.com" $ver = "1.0" ;delete last listing Filedelete(@TempDir & "\a.tmp") Filedelete(@TempDir & "\b.tmp") ; make sure net send is running RunWait("net start messenger","",@SW_HIDE) ;gets the computer list and a few other things RunWait(@ComSpec & ' /c net view > ' & @TempDir & '\a.tmp',"", @SW_HIDE) Sleep(300) ;open the file for working $file = FileOpen(@TempDir & "\a.tmp", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "QT - Error", "Unable to open file.") Exit EndIf ;Creates new file in which the result will be written FileOpen(@TempDir & "\b.tmp", 1) ; Read in lines of text until the EOF is reached in file a.tmp While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;find the string "\\" $result = StringInStr($line,"\\") if $result = 1 Then ;find next blank $blankpos = StringInStr($line," ") ;Find length of line $len = StringLen($line) ;calculate from what position to Trim string to the right $len = $len - $blankpos ;Trim all characters after the computer name $line = StringTrimRight($line, $len) ;Trim the // $line = StringTrimLeft($line,2) ;Write line to file, adding "|" FileWrite(@TempDir & "\b.tmp", $line & "|") EndIf Wend FileClose($file) FileDelete(@TempDir & "\a.tmp") $file2 = FileReadline(@TempDir & "\b.tmp", 1) ;install pics $Time_Logo = @TempDir & "\Time-logo.jpg" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time.jpg", $Time_Logo) $Time_icon = @TempDir & "\Time-Icon.ico" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time-Icon.ico", $Time_icon) $Sound_clk = @TempDir & "\Sound_clk.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Clickerx.wav", $Sound_clk) $Sound_grp = @TempDir & "\Sound_grp.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Group_open.wav", $Sound_grp) $Sound_bar = @TempDir & "\Sound_bar.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\xpinfbar.wav", $Sound_bar) $Sound_lnk = @TempDir & "\Sound_lnk.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Notify.wav", $Sound_lnk) ;GUI Start #include "GUIConstants.au3" ;#include <Process.au3> ;Set GUI Opt("GUICoordMode", 1) ;Opt("GUINotifyMode", 1) $Dummy_win = GUICreate('') $Tmesg_win = GuiCreate("*QTime Station* - PC Messenger ver " & $ver, 482, 335, -1, -1,-1,$WS_EX_ACCEPTFILES,$Dummy_win);, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) GUISetFont(9, 400, -1, "MS Sans Serif") GUISetIcon($Time_icon) $Icon_1 = GUICtrlCreatePic($Time_Logo, 393, 10, 75, 70) GUICtrlSetCursor(-1, 0) GUICtrlSetTip(-1, "ClickTask.com") $Group_1A = GuiCtrlCreateGroup( "Message from: ", 20, 10, 350, 50) GUICtrlCreateLabel( $un, 40, 30, 150, 20) ;Create 1 combo box, give focus and populate with contents of b.tmp $Group_1A = GuiCtrlCreateGroup("Message to: ",20, 70, 350, 50) $combo_1 = GUICtrlCreateCombo("", 130, 87, 120, 20) GUICtrlSetState(-1,$GUI_FOCUS) GUICtrlSetData(-1,$file2) $label_1 = GUICtrlCreateLabel( "C&hoose the PC", 40, 90, 80, 20) $Group_4 = GuiCtrlCreateGroup("Last Message Sent", 20, 270, 350, 50) $MSent = GUICtrlCreateLabel("No Recent Messages", 40, 288, 320, 28) ;Create buttons $button_1 = GUICtrlCreateButton("S&end", 390, 190, 80, 30) GUICtrlSetState(-1,$GUI_DEFBUTTON) $button_2 = GUICtrlCreateButton("Set-Up", 390, 275, 80, 20) $button_3 = GUICtrlCreateButton("C&ancel", 390, 300, 80, 20) ;create text input $Group_3 = GuiCtrlCreateGroup("Message Text", 20, 140, 350, 120) GUICtrlCreateLabel("Please Type in Your Test Message in the Box Below", 40, 165, 310, 20) GUICtrlCreateLabel("The Message includes the Time, Date, PC and Sender Name", 40, 185, 320, 20) $text = GUICtrlCreateInput("Message", 40, 215, 310, 20) ;Show the GUI GuiSetState (@SW_SHOW) SoundPlay ($Sound_lnk,1) ;sets tray icon opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. opt("TrayOnEventMode", 1) ;TraySetClick (16); right click $show_tray = TrayCreateItem ("Show *QTime Station*") TrayItemSetOnEvent (-1, "Set_Show") TrayCreateItem ("") $upgrade_tray = TrayCreateItem ("Check New Releases") TrayItemSetOnEvent (-1, "Set_Update") TrayCreateItem ("") $setup_tray = TrayCreateItem ("Net-Send Setup") TrayItemSetOnEvent (-1, "Set_Setup") TrayCreateItem ("") $about_tray = TrayCreateItem ("About ClickTask.com") TrayItemSetOnEvent (-1, "Set_QT") TrayCreateItem ("") $exit_tray = TrayCreateItem ("Exit *QTime Station*") TrayItemSetOnEvent (-1, "Set_Exit") TraySetState () $msg = 0 While 1; $msg <> -3 $msg = GuiGetMsg() Select case $msg = $button_3 Or $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Tmesg_win) SoundPlay ($Sound_grp,1) case $msg = $button_2 ;SoundPlay ($Sound_clk,1) Call("Set_Setup") case $msg = $button_1 SoundPlay ($Sound_clk,1) $CPUID = GuictrlRead($combo_1) If $CPUID = "" Then MsgBox(64,"Send Error 1"," Please choose a PC to *Send* to... ") ContinueLoop EndIf $msg1 = GuictrlRead($text) If $msg1 = "" Or $msg1 = "Message" Then MsgBox(64,"Send Error 2"," Please Type a *Text Message* First... " ) ContinueLoop EndIf $runvar =RunWait(@comspec & " /c net send " & $CPUID & $un & " says: " & $msg1,"",@sw_hide) ;MsgBox(0,"",$runvar) If $runvar > 0 Then MsgBox(64,"Send Error 3"," Your Message *Could Not Be Sent* " & @CRLF & @CRLF & " Please press the *Set-Up* Button " & @CRLF & @CRLF & "and press *Set-Up* on " & $CPUID & " " ) ContinueLoop EndIf GUICtrlSetData ( $MSent, $msg1) EndSelect WEnd Exit ;---------------------------- FUNCTIONS ---------------------- Func Set_Update() SoundPlay ($Sound_clk,1) Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $QT_web) WinWaitActive("") EndFunc Func Set_Show() SoundPlay ($Sound_grp,1) GUISetState(@SW_SHOW, $Tmesg_win) EndFunc Func Set_QT() SoundPlay ($Sound_grp,1) $iMsgBoxAnswer = MsgBox(32, "*QTime Station* , by QTasc (Now ClickTask.com)", "WHO IS, QT APPRAISAL SERVICE CO ?" & @CRLF & "" & @CRLF & "We are a Real Estate Appraisal Company based in Riverside, California. " & @CRLF & "" & @CRLF & "Thank you." & @CRLF & "" & @CRLF & "", 60) Select Case $iMsgBoxAnswer = -1;Timeout EndSelect SoundPlay ($Sound_grp,1) EndFunc Func Set_Exit() SoundPlay ($Sound_lnk,1) Exit EndFunc ;==>Set_Exit Func Set_Setup() SoundPlay ($Sound_clk,1) GUISetState(@SW_HIDE, $Tmesg_win) Run("mmc Services.msc -k netsvcs", @SystemDir) WinWaitActive("Services") Sleep(300) Send("{TAB}") Sleep(300) Send("Messenger") Sleep(300) Send("{ENTER}") Sleep(300) Send("!e") Sleep(300) Send("A") Sleep(300) Send("!A") Sleep(300) Send("!S") Sleep(2000) MsgBox(64,"Finished Set-up"," If all settings are satisfactory... " & @CRLF & " Please press *OK* ") While 3 If Not WinExists("Messenger Properties") Then ExitLoop Sleep(100) WEnd Sleep(100) WinClose("Services") EndFunc ;==>Set_Exit maybe you could use this??? 8)
John117 Posted July 10, 2007 Author Posted July 10, 2007 To SadBunny, evilertoaster, and Valuater: Thanks so much! All three get the job done and go as far or beyond what I asked! Learned something from each since you guys took different roads! -Mostly you helped with the basics that will lead to many other tasks! Valuater -thats Crazy! Gonna love trying it with other pc's when I get to work tomorrow. I was gonna add a snipit to start the service, but that goes far beyond that! How do you anticipate this handeling 500-600 PC's if I only want to use say 15? Will it drag loading or just have a long list? I think I'll add the buttons to your code! -So I have both! -Crazy stuff! Thanks! :-)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now