Jump to content

Sometimes Window doesn't show with _WinAPI_SetParent


nend
 Share

Recommended Posts

Hi guys,

I have used _WinAPI_SetParent to connect a window to the Windows background/desktop.

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hParent = WinGetHandle('[CLASS:Progman;TITLE:Program Manager]')

Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400, 100, 100, -1, $WS_EX_TOOLWINDOW)

; Attach window to the desktop (always on bottom)
_WinAPI_SetParent($hForm, $hParent)

GUISetState(@SW_SHOWNOACTIVATE)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

I'd used this script from the help file and a lot of time it won't show the window, the program start but the just the window won't show.

If the window is not showing I pressed 2 times on the "task view" button on the Windows taskbar and it wil the show the window.

I can't find logic in it when the window show or when it nog showing.

I inserted in a program and a lot of people says they have the same issues.

I used it on a Windows 10 64 bit

Has anyone a idea why this happens?

Edited by nend
Link to comment
Share on other sites

Yeah I'm aware of that, sometimes it works for me for me for a day or longer but when it stops working the only thing what works is to press 2 times on the "task view" button on the Windows taskbar and than it appears again.

I have the same problem on 2 pc almost clean installed.

Edited by nend
Link to comment
Share on other sites

@JohnOne

I found a way to reproduce the problem.

Start the script and open a second virtual desktop,  click on the taskview button and go to the second desktop.
Close the second desktop and you wil see that the Window has disapear.
If you stop the script and restart it it will not show again untill you pressed 2 times on the taskview button even when you has only one desktop.

This behaviour keeps coming up until you restart window. 

Edited by nend
Link to comment
Share on other sites

I believe it to be windows.

It appears that the gui is actually swallowed by the other desktop (if that's a good term)

Run your test, create a new desk top and switch to it, you will see your gui.

It's as though the handle to a second desktop is being reused in some weird and freaky fashion, bug if you ask me.

EDIT: If I'm correct it could actually lead to a security risk, I don't believe you are supposed to be able to script across desktops, at least not without jumping through hoops.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It not only happens when you switch desktops, it would also take place a lot of time when you use 1 desktop.

This was the only point I can reproduce it, but if your pc is on for a long time and your working with it it also happens.

Link to comment
Share on other sites

Do you confirm you gui is created on a phantom desktop, then when you create a new one, it is on it?

I also believe that when the window appears it is because _WinAPI_SetParent failed.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Looks like you simply not getting proper desktop handle.

Solution...

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hParent = _WinAPI_GetDesktopWindow ( ) ; <<<<


Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400, 100, 100, -1, $WS_EX_TOOLWINDOW)

; Attach window to the desktop (always on bottom)
ConsoleWrite (_WinAPI_SetParent($hForm, $hParent) & @LF)

GUISetState(@SW_SHOW)


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I would like to say it works.... but it don't.

Normally as it works the window attach to the desktop and is the lowest in the z order (except for the desktop)

Now the window is vissible but the window is not attach to the desktop.

That is just were I want this function for

Edited by nend
Link to comment
Share on other sites

#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

;$aWins = WinList()
;_ArrayDisplay($aWins)

Local $hParent = WinGetHandle ( "[CLASS:Progman;TITLE:Program Manager]")
ConsoleWrite("Error: " & @error & @LF)
ConsoleWrite("Progman: " & $hParent & @LF)

Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400, 100, 100, -1, $WS_EX_TOOLWINDOW, $hParent)  ; <<<<

;Local $oldparent = _WinAPI_SetParent($hForm, $hParent)
;ConsoleWrite("Error: " & @error & @LF)
;ConsoleWrite ("Old parent: " & $oldparent & @LF)

Local $newparent = _WinAPI_GetParent($hForm)
ConsoleWrite("Error: " & @error & @LF)
ConsoleWrite("New parent: " & $newparent & @LF)

GUISetState(@SW_SHOWNOACTIVATE)


Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

32 minutes ago, JohnOne said:

This line sets @error

Local $hParent = WinGetHandle('[CLASS:Progman;TITLE:Program Manager]')

Where do you even get that from?

This is from the helpfile (if you search for _WinAPI_GetParent) from AutoIT, the script at the first post in this tread comes from the helpfile.

Edited by nend
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...