Baritonomarchetto Posted May 2, 2013 Share Posted May 2, 2013 Hi all, I wrote a little script intended to show up a GUI with a list you can select a program to load from. The problem is that the selected program, once loaded, is heavily slowed down so the script must be "heavy" while running in the background... here is the code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIScrollbars_Ex.au3" #include <GuiListView.au3> #include <Misc.au3> Local $hDLL = DllOpen("user32.dll") Local $hGUI $hGUI = GUICreate("Select Program To Run", 250, 150,-1,-1,$WS_POPUP+$WS_BORDER) GUISetBkColor(0x3790e8) $listview = GUICtrlCreateListView("Select Program - press 1 to Run", 0, 0, 250,150, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetColumnWidth($listview, 0, 245) GUICtrlSetBkColor(-1,0x3790e8) $P1= GUICtrlCreateListViewItem("Program #1", $listview); ID 4 GUICtrlSetColor (-1, 0xFFFFFF) $P2= GUICtrlCreateListViewItem("Program #2", $listview); ID 5 GUICtrlSetColor (-1, 0xFFFFFF) $P3= GUICtrlCreateListViewItem("Program #3", $listview); ID 6 GUICtrlSetColor (-1, 0xFFFFFF) $win= GUICtrlCreateListViewItem("Exit to Windows", $listview); ID 7 GUICtrlSetColor (-1, 0xFFFFFF) $shutdown= GUICtrlCreateListViewItem("Shut Down PC", $listview); ID 8 GUICtrlSetColor (-1, 0xFFFFFF) GUISetState(@SW_SHOW) ;shows the gui/menu/list While 1 $GUIlistitem = GUICtrlRead($listView); reads the ID of the selected item in the list ;SplashTextOn ( "title", $GUIlistitem) if Not (ProcessExists("P1.exe") Or ProcessExists("P2.exe") Or ProcessExists("P3.exe")) Then If $GUIlistitem==4 And _IsPressed(31) Then ;31 -> Key 1 RunWait("C:/Programs/P1.exe") nocycle() EndIf If $GUIlistitem==5 And _IsPressed(31) Then ;31 -> Key 1 RunWait("C:/Programs/P2.exe") nocycle() EndIf If $GUIlistitem==6 And _IsPressed(31) Then ;31 -> Key 1 RunWait("C:/Programs/P3.exe") nocycle() EndIf If $GUIlistitem==7 And _IsPressed(31) Then ;31 -> Key 1 Exit nocycle() EndIf If $GUIlistitem==8 And _IsPressed(31) Then ;31 -> Key 1 Shutdown(1) nocycle() EndIf Sleep(200) EndIf WEnd Func nocycle() While _IsPressed(31, $hDLL) Sleep(500) WEnd EndFunc DllClose($hDLL) I am not a coder so there should be something of macroscopic i cannot see... If you have some idea on how to improve this "badly-drawn-boy" please tell me Thanks for the help! Link to comment Share on other sites More sharing options...
water Posted May 2, 2013 Share Posted May 2, 2013 To get the pressed key in a GUI you don't use _ISPressed but GUIGetmsg to check for a button (needs to be created in your GUI). For an example check function GUICreate in the help file. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted May 2, 2013 Share Posted May 2, 2013 Example:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $hGUI = GUICreate("Select Program To Run", 250, 150, -1, -1, $WS_POPUP + $WS_BORDER) GUISetBkColor(0x3790e8) Global $listview = GUICtrlCreateListView("Select Program - press 1 to Run", 0, 0, 250, 150, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetColumnWidth($listview, 0, 245) GUICtrlSetBkColor(-1, 0x3790e8) Global $P1 = GUICtrlCreateListViewItem("Program #1", $listview); ID 4 GUICtrlSetColor(-1, 0xFFFFFF) $P2 = GUICtrlCreateListViewItem("Program #2", $listview); ID 5 GUICtrlSetColor(-1, 0xFFFFFF) $P3 = GUICtrlCreateListViewItem("Program #3", $listview); ID 6 GUICtrlSetColor(-1, 0xFFFFFF) $win = GUICtrlCreateListViewItem("Exit to Windows", $listview); ID 7 GUICtrlSetColor(-1, 0xFFFFFF) $shutdown = GUICtrlCreateListViewItem("Shut Down PC", $listview); ID 8 GUICtrlSetColor(-1, 0xFFFFFF) $Start = GUICtrlCreateDummy() Global $AccelKeys[1][2] = [["1", $Start]] GUISetAccelerators($AccelKeys) GUISetState(@SW_SHOW) ;shows the gui/menu/list While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $Start Then $GUIlistitem = GUICtrlRead($listview); reads the ID of the selected item in the list Switch $GUIlistitem Case 4 If Not ProcessExists("P1.exe") Then RunWait("C:\Programs\P1.exe") Case 5 If Not ProcessExists("P2.exe") Then RunWait("C:\Programs\P2.exe") Case 6 If Not ProcessExists("P3.exe") Then RunWait("C:\Programs\P3.exe") Case 7 Exit Case 8 Shutdown(1) EndSwitch EndIf WEnd My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Baritonomarchetto Posted May 2, 2013 Author Share Posted May 2, 2013 (edited) Uh, thank you very much for the help! just a question: why only $P1 in set as Global variable and $P>1 not? EDIT: another Q: will "RunWait" prevent other programs to run while one is running or should i specify: If Not (ProcessExists("P1.exe") Or ProcessExists("P2.exe") or ProcessExists("P3.exe")) Then RunWait("C:\Programs\P1.exe") Edited May 2, 2013 by Baritonomarchetto Link to comment Share on other sites More sharing options...
water Posted May 2, 2013 Share Posted May 2, 2013 Globals are not needed. Stripped down version:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("Select Program To Run", 250, 150, -1, -1, $WS_POPUP + $WS_BORDER) GUISetBkColor(0x3790e8) Global $listview = GUICtrlCreateListView("Select Program - press 1 to Run", 0, 0, 250, 150, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetColumnWidth($listview, 0, 245) GUICtrlSetBkColor(-1, 0x3790e8) GUICtrlCreateListViewItem("Program #1", $listview); ID 4 GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateListViewItem("Program #2", $listview); ID 5 GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateListViewItem("Program #3", $listview); ID 6 GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateListViewItem("Exit to Windows", $listview); ID 7 GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateListViewItem("Shut Down PC", $listview); ID 8 GUICtrlSetColor(-1, 0xFFFFFF) $Start = GUICtrlCreateDummy() Global $AccelKeys[1][2] = [["1", $Start]] GUISetAccelerators($AccelKeys) GUISetState(@SW_SHOW) ;shows the gui/menu/list While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Start $GUIlistitem = GUICtrlRead($listview); reads the ID of the selected item in the list Switch $GUIlistitem Case 4 If Not ProcessExists("P1.exe") Then RunWait("C:\Programs\P1.exe") Case 5 If Not ProcessExists("P2.exe") Then RunWait("C:\Programs\P2.exe") Case 6 If Not ProcessExists("P3.exe") Then RunWait("C:\Programs\P3.exe") Case 7 Exit Case 8 Shutdown(1) EndSwitch EndSelect WEnd My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted May 2, 2013 Share Posted May 2, 2013 EDIT: another Q: will "RunWait" prevent other programs to run while one is running or should i specify:RunWait means: AutoIt will wait until Px.exe has finished. This also means: You can't exit the GUI until the program you called has ended. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Baritonomarchetto Posted May 2, 2013 Author Share Posted May 2, 2013 Thank you a lot Link to comment Share on other sites More sharing options...
water Posted May 2, 2013 Share Posted May 2, 2013 Glad to be of service My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
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