Sign in to follow this  
Followers 0
martin

No message generated for controls in child window.

15 posts in this topic

Is the example below expected behaviour?

This is the child window which can be run by itself in which case it isn't a child

$ch = GUICreate("Child",300,300)
$testBtn = GUICtrlCreateButton("Test",100,100)

if winexists("Parent") then
  GUISetState(@SW_HIDE)
Else
     GUISetState()
EndIf

while 1
    $Msg = GUIGetMsg()
    if $msg = -3 then Exit
    if $msg = $testBtn then msgbox(262144,"result","button pressed")
WEnd

 

When the button is pressed a message box appears of course.

But if you run this

$AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")

$Parent = guicreate("Parent",700,500)
GUISetState()

Run('"' & $AutoItProdexePath & '\AutoIt3.exe "' & ' "' & @ScriptDir & '\Child.au3"')
DllCall("user32.dll", "int", "SetParent", "hwnd", "Child", "hwnd", $Parent)

WinSetState("Child", "", @SW_SHOW)

while GUIGetMsg() <> -3
WEnd
 

then the button doesn't generate a message although the close icon does.

Should I have expected that or is something wrong?


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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think it's probably expected behaviour, because the child GUI is never set to an active state. What exactly you are trying to do is unclear to me.

;

$ch = GUICreate("Child",300,300)
$testBtn = GUICtrlCreateButton("Test",100,100)

GUISetState()

while 1
    $Msg = GUIGetMsg()
    if $msg = -3 then Exit
    if $msg = $testBtn then msgbox(262144,"result","button pressed")
WEnd

;

$AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")

$Parent = guicreate("Parent",700,500)
GUISetState()

Run('"' & $AutoItProdexePath & '\AutoIt3.exe "' & ' "' & @ScriptDir & '\Child.au3"')
DllCall("user32.dll", "int", "SetParent", "hwnd", "Child", "hwnd", $Parent)

while GUIGetMsg() <> -3
WEnd

;

Edit

I tried a few different things and made a mistake coming to my first conclusion.

Edited by czardas

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Well, if I start the 1st time the parent script then the child script will be started but is hidden.

If I'm closing the parent script and start it again then another child window will be created which become visible. That means 2 child scripts are running and
 

DllCall("user32.dll", "int", "SetParent", "hwnd", "Child", "hwnd", $Parent)

set probably to the 1st child script which is still hidden.

If you show the child gui at the 1st time directly it works. I assume setting the parent using "child" is not unique.

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir")

$Parent = guicreate("Parent",700,500)
GUISetState()

Run('"' & $AutoItProdexePath & '\AutoIt3.exe "' & ' "' & @ScriptDir & '\Child.au3"')
WinWait("Child") ; <=== What about this?
DllCall("user32.dll", "int", "SetParent", "hwnd", "Child", "hwnd", $Parent)

WinSetState("Child", "", @SW_HIDE)
Sleep(2000)
WinSetState("Child", "", @SW_SHOW)

while GUIGetMsg() <> -3
WEnd

;

It's a little confusing.

Edited by czardas

Share this post


Link to post
Share on other sites

There is an error in my example in the first post and it was over complicated, although the problem is exactly the same. If you create a window like this

$ch = GUICreate("Child",300,300,10,10)
$testBtn = GUICtrlCreateButton("Test",100,100)
GUISetState()
sleep(500); some code which maybe takes some time
GUISetState(@SW_HIDE)
while 1
    $Msg = GUIGetMsg()
    if $msg = -3 then Exit
    if $msg = $testBtn then msgbox(262144,"result","button pressed")
WEnd
 
 

 

Say you compile that and run it. Then run this scrript

winsetstate("Child","",@SW_SHOW)

 

Then you will see that the button is unresponsive.

So if an AutoIt gui sets itself to hide, and an external method is used to show it then the gui is unresponsive. That is what I am trying to demonstrate and to me it seems wrong.

But I suppose that, apart from the problem it caused me for a while, it isn't a big deal.


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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I'm not sure if there's a bug here or not. If you run the following code by itself (without the parent), you get the same unresponsive effect.

$ch = GUICreate("Child",300,300)
$testBtn = GUICtrlCreateButton("Test",100,100)
GUISetState(@SW_HIDE)
WinSetState("Child", "", @SW_SHOW)

while 1
    $Msg = GUIGetMsg()
    if $msg = -3 then Exit
    if $msg = $testBtn then msgbox(262144,"result","button pressed")
WEnd
Edited by czardas

Share this post


Link to post
Share on other sites

For some reason when you run that script in post #6 and you click the button, $Msg contains -7 when you click it and -8 when you let it go, even though the button's ID is 3.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, I hadn't thought of trying that. It shows exactly what I'm saying and it gives the solution.

If instead of

GuiSetState(@SW_HIDE)

I can use

WinSetState("Child","",@SW_HIDE)

and that works

$ch = GUICreate("Child",300,300,10,10)
$testBtn = GUICtrlCreateButton("Test",100,100)
GUISetState()
sleep(500)
winsetstate("Child","",@SW_HIDE)
while 1
    $Msg = GUIGetMsg()
    if $msg = -3 then Exit
    if $msg = $testBtn then msgbox(262144,"result","button pressed")
WEnd

 

Thanks czardas

1 person likes this

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.

Share this post


Link to post
Share on other sites

@BrewManNH

You are seeing the codes for MouseDown and MouseUp I think.


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.

Share this post


Link to post
Share on other sites

But I wasn't seeing the messages for the button at all was what I was saying. I didn't realize the -7/-8 was the mouse button messages, but that makes sense. But not seeing the button activated was odd.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Yes, I agree that it's odd which is why I started the thread. But we discovered that using using GuiSetState(@SW_HIDE) stops messages from most controls and they aren't turned on again using WinSetState(...,..,$SW_SHOW), but if you hide the gui using WinSetState then when you show it again with WInSetState everything works.

In my opinion its a bug but it's pretty trivial to get round and it will only happen very rarely so I'm not going to worry about it.


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.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I find it hard to differentiate between the two functions, in terms of what they do to a window. The following test strongly indicates that the button is always rendered inactive when the window is hidden. It doesn't make any difference which native function you use to hide the window: I tried both. You may notice that when the button is clicked on the hidden window, other windows lose focus, although you can't see the GUI and no message appears.

;

Local $hGUI = GUICreate("Child", 300, 300)
Local $hTestBtn = GUICtrlCreateButton("Test", 100, 100)
GUISetState()

WinSetState("Child", "", @SW_HIDE)
AdLibRegister("ClickIt", 2000)

while 1
    $Msg = GUIGetMsg()
    If $msg = -3 then Exit
    If $msg = $hTestBtn Then TestClick()
WEnd

Func ClickIt()
    ControlClick("Child", "", $hTestBtn)
    AdLibUnRegister("ClickIt")
    AdLibRegister("GetOutOfHere", 2000)
EndFunc

Func TestClick()
    MsgBox(262144,"result","button pressed")
    WinSetState("Child", "", @SW_SHOW)
EndFunc

Func GetOutOfHere()
    WinSetState("Child", "", @SW_SHOW)
    AdLibUnRegister("GetOutOfHere")
EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites

That's beyond what I was looking at though the effect might be related.

The help makes no claims about controlclick working on hidden windows and even warns that it is best to activate the target window before using controlclick, so I think expecting a control on a hidden AutoIt window to respond is a bit optimisistic.


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.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I was myself surprised that it was possible to action the click, assuming the loss of focus with other windows to be a good indicator of this. The idea was to further determine that both functions do something very similar (the behaviour of the hidden windows appears to be the same). So far the only apparent difference is context: local or external access. If this is true then it points to there being a bug.

Edited by czardas

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