Jump to content

_WinAPI_SetParent


 Share

Recommended Posts

Hi,

I'm trying to figure out how to attach my GUICreate() to the IE Google window. To be more specific I need my GUICreate to show when the Google webpage window is active in IE and then hide when the Google webpage window is inactive.

The script below continuously flashes when the Google webpage window is active. How can I get the following script to show the GUICreate only when the Google webpage window is active without continuously flashing and then hide when it is inactive?

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

$mGuiTitle = "Main GUI Title" ; Main GUI Title
$aGuiTitle = "Google" ; Attach GUI Title

; Create Main GUI
$mGUI = GUICreate($mGuiTitle, 200, 37, 150, 150, $WS_POPUP)

; Set Main GUI window as parent
_WinAPI_SetParent($mGUI, $aGuiTitle)

GUISetState(@SW_HIDE)

WinSetOnTop($mGuiTitle, "", 1)

While 1
    Sleep(10)
    $hMsg = GUIGetMsg()
    If $hMsg = -3 Then Exit
    
    _GuiShowHide()      
WEnd

Func _GuiShowHide()
    ; When attach GUI window 
    ;   1. is active then shows the Main GUI
    ;   2. is not active then hides the Main GUI    
    While WinActive($aGuiTitle)
        WinSetState($mGuiTitle, "", @SW_SHOW)
        WinWaitNotActive($aGuiTitle)
        WinSetState($mGuiTitle, "", @SW_HIDE)
    WEnd    
EndFunc     ;==>_GuiAttach

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

I'm continuing to work on the script. If I close the IE that is associated with the Google window then the GUI will not respond. How can I get the GUI to respond to the IE Google window after IE has been closed and reopened?

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

Opt("WinTitleMatchMode", 4)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $mGuiTitle, $aGuiTitle, $wState = ""

$mGuiTitle = "Main GUI Title" ; Main GUI Title
$aGuiTitle = "Google - Windows Internet Explorer" ; Attach GUI Title

; Getting the Handle to the window I want to attach my toolbar to
$aGui = WinGetHandle($aGuiTitle)

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf   

; Create Main GUI
$mGUI = GUICreate($mGuiTitle, 200, 37, 150, 150, $WS_POPUP)

GUISetState(@SW_HIDE)

AdlibEnable("_GuiShowHide")

While 1
    Sleep(10)
    $hMsg = GUIGetMsg()
    If $hMsg = -3 Then Exit
WEnd

Func _GuiShowHide()
    ; When attach GUI window 
    ;   1. is active then shows the Main GUI
    ;   2. is not active then hides the Main GUI    
    $aGui = WinGetHandle("")
    $aGui = WinGetHandle($aGuiTitle)
    
    If Not WinActive($aGuiTitle) Then
        WinSetState($mGUI, "", @SW_HIDE)
        $wState = True ;Turn On
    ElseIf WinActive($aGuiTitle) Then
        If $wState = True Then          
            ; Set Main GUI window as parent
            _WinAPI_SetParent($mGUI, $aGui)
            WinSetState($mGUI, "", @SW_SHOW)            
            $wState = False ;Turn Off
        EndIf
    EndIf   
EndFunc     ;==>_GuiAttach

Thanks for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Wouldn't it be easier to use _IEAttach() to test for and instance of IE. You could use the "url" option to test for "google.com".

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Wouldn't it be easier to use _IEAttach() to test for and instance of IE. You could use the "url" option to test for "google.com".

:blink:

yeah, that's what i was thinking; in your while loop for the gui, just have a check to see if your ie object is an object, then attempt to attach if it's not and an ie window exists; and set the visibility of your window based on the ie window being active, and the active page's url.
Link to comment
Share on other sites

I think I've made the changes that was suggested above but when the IE Google window is active my GUI is continuously flashing. How can the GUI flashing be fixed?

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

;Opt("WinTitleMatchMode", 4)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $mGuiTitle, $aGuiTitle, $wState = ""

$mGuiTitle = "Main GUI Title" ; Main GUI Title
$aGuiTitle = "Google - Windows Internet Explorer" ; Attach GUI Title

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf   

; Create Main GUI
$mGUI = GUICreate($mGuiTitle, 200, 37, 150, 150, $WS_POPUP)

GUISetState(@SW_HIDE)

AdlibEnable("_GuiShowHide")

While 1
    Sleep(10)
    $hMsg = GUIGetMsg()
    If $hMsg = -3 Then Exit
WEnd

Func _GuiShowHide()
    ; Attach GUI window when
    ;   1. is active then shows the Main GUI
    ;   2. is not active then hides the Main GUI    
    
    ; Attach to a browser with URL  
    $oIE = _IEAttach ("http://www.google.com/", "URL")
    
    If @error = $_IEStatus_NoMatch Then 
        MsgBox(0, "Debug", "$_IEStatus_NoMatch")
    ElseIf @error = $_IEStatus_InvalidValue Then 
        MsgBox(0, "Debug", "$_IEStatus_InvalidValue")
    ElseIf @error = $_IEStatus_Success Then 
        ;MsgBox(0, "Debug", "$_IEStatus_Success")
        If Not WinActive($aGuiTitle) Then
            WinSetState($mGUI, "", @SW_HIDE)
            ;MsgBox(0, "Debug", "Win State Off")
            $wState = True ;Turn On     
        ElseIf WinActive($aGuiTitle) Then           
            If $wState = True Then          
                ; Set Main GUI window as parent
                ;_WinAPI_SetParent($mGUI, $aGui)
                WinSetOnTop($mGUI, "", 1)
                WinSetState($mGUI, "", @SW_SHOW)                
                ;MsgBox(0, "Debug", "Win State On")
                $wState = False ;Turn Off
            EndIf
        EndIf   
    EndIf
EndFunc     ;==>_GuiAttach

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Check the current state of the GUI before setting it. If it's already in the state you were about to set, leave it alone. The flashing is probably caused by re-setting state that's already there.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Check the current state of the GUI before setting it. If it's already in the state you were about to set, leave it alone. The flashing is probably caused by re-setting state that's already there.

I do not understand how to do this because I thought I was checking state of the GUI here:

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf

and then in the function _GuiShowHide().

Here is the full script:

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

;Opt("WinTitleMatchMode", 4)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $mGuiTitle, $aGuiTitle, $wState = ""

$mGuiTitle = "Main GUI Title" ; Main GUI Title
$aGuiTitle = "Google - Windows Internet Explorer" ; Attach GUI Title

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf   

; Create Main GUI
$mGUI = GUICreate($mGuiTitle, 200, 37, 150, 150, $WS_POPUP)

GUISetState(@SW_HIDE)

AdlibEnable("_GuiShowHide")

While 1
    Sleep(10)
    $hMsg = GUIGetMsg()
    If $hMsg = -3 Then Exit
WEnd

Func _GuiShowHide()
    ; Attach GUI window when
    ;   1. is active then shows the Main GUI
    ;   2. is not active then hides the Main GUI    
    
    ; Attach to a browser with URL  
    $oIE = _IEAttach ("http://www.google.com/", "URL")
    
    If @error = $_IEStatus_NoMatch Then 
        MsgBox(0, "Debug", "$_IEStatus_NoMatch")
    ElseIf @error = $_IEStatus_InvalidValue Then 
        MsgBox(0, "Debug", "$_IEStatus_InvalidValue")
    ElseIf @error = $_IEStatus_Success Then 
        ;MsgBox(0, "Debug", "$_IEStatus_Success")
        If Not WinActive($aGuiTitle) Then
            WinSetState($mGUI, "", @SW_HIDE)
            ;MsgBox(0, "Debug", "Win State Off")
            $wState = True ;Turn On     
        ElseIf WinActive($aGuiTitle) Then           
            If $wState = True Then          
                ; Set Main GUI window as parent
                ;_WinAPI_SetParent($mGUI, $aGui)
                WinSetOnTop($mGUI, "", 1)
                WinSetState($mGUI, "", @SW_SHOW)                
                ;MsgBox(0, "Debug", "Win State On")
                $wState = False ;Turn Off
            EndIf
        EndIf   
    EndIf
EndFunc     ;==>_GuiAttach

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

I do not understand how to do this because I thought I was checking state of the GUI here:

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf

and then in the function _GuiShowHide().

Here is the full script:

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

;Opt("WinTitleMatchMode", 4)     ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $mGuiTitle, $aGuiTitle, $wState = ""

$mGuiTitle = "Main GUI Title" ; Main GUI Title
$aGuiTitle = "Google - Windows Internet Explorer" ; Attach GUI Title

If Not WinActive($aGuiTitle) Then       
    $wState = True ;Turn On
ElseIf WinActive($aGuiTitle) Then       
    $wState = False ;Turn Off       
EndIf   

; Create Main GUI
$mGUI = GUICreate($mGuiTitle, 200, 37, 150, 150, $WS_POPUP)

GUISetState(@SW_HIDE)

AdlibEnable("_GuiShowHide")

While 1
    Sleep(10)
    $hMsg = GUIGetMsg()
    If $hMsg = -3 Then Exit
WEnd

Func _GuiShowHide()
    ; Attach GUI window when
    ;   1. is active then shows the Main GUI
    ;   2. is not active then hides the Main GUI    
    
    ; Attach to a browser with URL  
    $oIE = _IEAttach ("http://www.google.com/", "URL")
    
    If @error = $_IEStatus_NoMatch Then 
        MsgBox(0, "Debug", "$_IEStatus_NoMatch")
    ElseIf @error = $_IEStatus_InvalidValue Then 
        MsgBox(0, "Debug", "$_IEStatus_InvalidValue")
    ElseIf @error = $_IEStatus_Success Then 
        ;MsgBox(0, "Debug", "$_IEStatus_Success")
        If Not WinActive($aGuiTitle) Then
            WinSetState($mGUI, "", @SW_HIDE)
            ;MsgBox(0, "Debug", "Win State Off")
            $wState = True ;Turn On     
        ElseIf WinActive($aGuiTitle) Then           
            If $wState = True Then          
                ; Set Main GUI window as parent
                ;_WinAPI_SetParent($mGUI, $aGui)
                WinSetOnTop($mGUI, "", 1)
                WinSetState($mGUI, "", @SW_SHOW)                
                ;MsgBox(0, "Debug", "Win State On")
                $wState = False ;Turn Off
            EndIf
        EndIf   
    EndIf
EndFunc     ;==>_GuiAttach

Thank you for your help,

jfcby

just have a nested while loop that does nothing but sleep while it's the active window; while winactive(blah) or winactive(yourgui). then when neither your gui or the other window are active, it will exit that loop and go back into hiding; but it won't set the winstate when it doesn't need to be messed with...
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...