Jump to content

Showing a GUI when a certain window is active


Recommended Posts

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
Link to comment
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.

Link to comment
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)
Link to comment
Share on other sites

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
Link to comment
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

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