Sign in to follow this  
Followers 0
curtyo

Showing a GUI when a certain window is active

7 posts in this topic

So i'm trying to get a gui window to hide itself when a certain window is not active, but show when that window is active. The problem seems to be that when i show the GUI window, it sets it as the active window, causing my code to back and forth. Any help appreciated. Thank you. (using calculator to test with)

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$gui = GUICreate("My GUI", 150, 200, @DesktopWidth / 100 * 15, @DesktopHeight / 100 * 90, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
Opt("GUICoordMode", 2)
$Button_2 = GUICtrlCreateButton("Button Test", 0, -1)


While 1
$msg = GUIGetMsg()
WinSetOnTop($gui, "", 1)

$title = WinGetTitle("")

ToolTip($title)

If $title == "Calculator" Then
GUISetState(@SW_SHOW)

Else
GUISetState(@SW_HIDE)

EndIf

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Share this post


Link to post
Share on other sites

Hi,

Welcome to the autoit forum :)

Try this :

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt("GUICoordMode", 2)

Local $hGUI = GUICreate("My GUI", 150, 200, @DesktopWidth / 100 * 15, @DesktopHeight / 100 * 90, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
Local $iButton_2 = GUICtrlCreateButton("Button Test", 0, -1)

Local $iMsg = 0, $hWnd = 0, $sTitle = ""

While 1
    $iMsg = GUIGetMsg()
    If $iMsg = $GUI_EVENT_CLOSE Then ExitLoop

    $hWnd = WinGetHandle("[active]")

    $sTitle = WinGetTitle($hWnd)
    ToolTip($sTitle)

    If $sTitle == "Calculator" And $hWnd <> $hGUI Then
        GUISetState(@SW_SHOWNA, $hGUI)
    ElseIf $hWnd <> $hGUI Then
        GUISetState(@SW_HIDE, $hGUI)
    EndIf
WEnd

GUIDelete($hGUI)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

It works!!! Thank you very much :)

Share this post


Link to post
Share on other sites

You're welcome ;)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Sorry to be a pain, another question i have is i'm trying to create a GUI but the buttons dont seem to appear where i place them, im assuming there is some option that is preventing them from overlapping. Is there a way around this?

Local $hGUI = GUICreate("My GUI", 180, 90, @DesktopWidth / 100 * 20, @DesktopHeight / 100 * 90, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
Local $iButton_2 = GUICtrlCreateButton("FBlue", 10, 10, 70)
Local $iButton_3 = GUICtrlCreateButton("FRed", 10, 30, 70)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I don't understand what's wrong with your buttons as they are displayed normally.

OK, I got it. It's the GUICoordMode flag set to 2 which does this. Remove the function or take it in consideration :)

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Works fine for me also...

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
Local $hGUI = GUICreate("My GUI", 180, 90, @DesktopWidth / 100 * 20, @DesktopHeight / 100 * 90, BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
Local $iButton_2 = GUICtrlCreateButton("FBlue", 10, 10, 70)
Local $iButton_3 = GUICtrlCreateButton("FRed", 10, 30, 70)
     guisetstate()
while 1
 switch guigetmsg()
  case $gui_event_close
   Exit
  case $iButton_2
   ConsoleWrite('Button 2' & @LF)
  case $iButton_3
   ConsoleWrite('Button 3' & @LF)
 EndSwitch
WEnd

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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