human Posted December 17, 2009 Share Posted December 17, 2009 Hi, I've written two small programs. first one creates a small gui with one button and hide it to the tray. With the second program I want restore the first one to push the button. When I have restored the first program, pushing the button is not possible. Need help! Example: (Code 1) #include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", 0) Opt("GUICoordMode", 1) opt ("GUIOnEventMode",1) opt("TrayAutoPause",0) Dim $MAIN_GUI = GUICreate("TestClient",540,40,120, 40, BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW, $ws_popup), $WS_EX_TOPMOST) Dim $Button = GUICtrlCreateButton("Button", 5,5,220,30) Dim $Status_Feld = GUICtrlCreateLabel("",230,10,300,20) GUICtrlSetOnEvent($Button, "testfunc") GUISetCoord(826,947) GUICtrlSetFont($Status_Feld,14) GUICtrlSetBkColor ($Button,0x00FF00) GUICtrlSetFont($Button,16) GUISetState(@SW_SHOW) GUISetState(@SW_HIDE) while 1 $msg=GUIGetMsg() if $msg=$Button then testfunc() WEnd func testfunc() MsgBox(1,"test","test") EndFunc Code 2: #include <WindowsConstants.au3> opt ("GUIOnEventMode",1) If WinExists("TestClient") Then $Clients = WinList("TestClient") $client_name = "TestClient" $Counter = 0 $Anzahl_Clients = $Clients[0][0] for $Counter = 0 To $Anzahl_Clients $window_title= $clients[$Counter][0] $window_handle= $clients[$Counter][1] Sleep(100) GUISetState(@SW_RESTORE, $window_handle) WinSetState( $window_handle,"",@SW_SHOWNORMAL) WinActivate($client_name,"") $state=WinGetState($window_handle,"") msgbox(1,"Test", $state & $window_handle) if BitAND($state, 16) Then WinSetState($client_name,"",@SW_ENABLE) WinSetState($client_name,"",@SW_SHOW) WinSetState($client_name,"",@SW_restore) EndIf ControlClick($window_handle,"","[CLASS:Button; INSTANCE:1]") Next Else MsgBox(16, "Fehler:", "") EndIf Sleep(200) MsgBox(1, "I/O", "") Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 17, 2009 Moderators Share Posted December 17, 2009 (edited) human,(What does that make the rest of us, I wonder? )I ran across the same problem a while ago. The trick is to use WinSetState to hide the first GUI after having created it with GUISetState. So the first script becomes:#include <GUIConstantsEx.au3> #include <GuiButton.au3> #include <WindowsConstants.au3> Opt("GUIResizeMode", 0) Opt("GUICoordMode", 1) Opt("GUIOnEventMode", 1) Opt("TrayAutoPause", 0) Dim $MAIN_GUI = GUICreate("TestClient", 540, 40, 120, 40, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW, $ws_popup), $WS_EX_TOPMOST) Dim $Button = GUICtrlCreateButton("Button", 5, 5, 220, 30) GUICtrlSetOnEvent($Button, "testfunc") GUICtrlSetBkColor($Button, 0x00FF00) GUICtrlSetFont($Button, 16) Dim $Status_Feld = GUICtrlCreateLabel("", 230, 10, 300, 20) GUICtrlSetFont($Status_Feld, 14) ;GUISetCoord(826, 947) GUISetState(@SW_SHOW) WinSetState($MAIN_GUI, "", @SW_HIDE) While 1 ;$msg = GUIGetMsg() ; GUIGetMsg does not woork in OnEvent mode! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ;If $msg = $Button Then testfunc() Sleep(10) WEnd Func testfunc() MsgBox(1, "test", "test") EndFunc ;==>testfuncI have also tidied it up a bit. There is no point in using GUIGetMsg when you have set OnEvent mode - read the Help file to find out why! But you must put something in the loop to prevent CPU at 100% usage - Sleep(10) will do nicely. I also wondered why you had used GUISetCoord as the Help file says it is "To be used specifically in Opt ("GUICoordMode", 2)" and you have set Opt("GUICoordMode", 1). Anyway, I hope this helps. Ask if anything is unclear. M23Edit: Welcome to the AutoIt forums, by the way! Edited December 17, 2009 by Melba23 dersiniar 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KaFu Posted December 17, 2009 Share Posted December 17, 2009 (edited) The trick is to use WinSetState to hide the first GUI after having created it with GUISetState.I tried for 10 minutes and gave up ... good to know ... Edited December 17, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 17, 2009 Moderators Share Posted December 17, 2009 KaFu,I tried for 10 minutesIt took me a lot longer than that to solve it the first time! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
martin Posted December 17, 2009 Share Posted December 17, 2009 BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW, $ws_popup)No, you mean$WS_POPUPI think. If use extended styles for styles you could get an unexpected result. The code for an extended style could be the code for something unrelated for a style. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
KaFu Posted December 18, 2009 Share Posted December 18, 2009 If use extended styles for styles you could get an unexpected result. The code for an extended style could be the code for something unrelated for a style.While trying I cleaned up the example with no result, the main GUI only had the style $WS_POPUP applied. I could unhide the window, but still the onevent function of the button was inactive although controlclick() returned true in the second program, so I assume it has nothing to do with the style but more with a difference between GUISetState() and WinSetState() I'm not aware of. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
human Posted December 18, 2009 Author Share Posted December 18, 2009 Hi, thanks for your help i tried it to work with "WinSetState" in the first program. it works! 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