Jump to content

problems with @sw_hide and sw_show


human
 Share

Recommended Posts

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

  • Moderators

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   ;==>testfunc

I 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). :evil:

Anyway, I hope this helps. Ask if anything is unclear. :evil:

M23

Edit: Welcome to the AutoIt forums, by the way! :idea:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Link to comment
Share on other sites

  • Moderators

KaFu,

I tried for 10 minutes

It took me a lot longer than that to solve it the first time! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW, $ws_popup)

No, you mean

$WS_POPUP

I 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

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.
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...