Jump to content

Is it possible


Recommended Posts

Is it possible to have gui's stay on certain windows if assigned to them. im running a 3rd party application and i want my 32x32 guis to be able to stay on that window only, if specified too, meaning if another window pops up then ky 32x32 window(s) will disappear with the window they are on top of. is it possible to do this and is there any scripts like this already? i didn't have any luck with searching...

Link to comment
Share on other sites

  • Moderators

Hypertrophy,

When I did this a while ago I created my GUI with the TOPMOST attribute and then used the following code in the While...WEnd loop:

; Create My_GUI and use TOPMOST
Global $hMy_GUI = GUICreate("My GUI", ###, ###, ###, ###, -1, $WS_EX_TOPMOST)

;....

While 1
    
    ; Other loop code

    ; Correct position of My_GUI if required
    If WinActive($hExternal_Wnd) Or WinActive($hMy_GUI) Then
        $aExternal_Pos = WinGetPos($hExternal_Wnd)
        If $aExternal_Pos[0] <> $iLast_X Or $aExternal_Pos[1] <> $iLast_Y Then
            $iLast_X = $aExternal_Pos[0]
            $iLast_Y = $aExternal_Pos[1]
            WinMove($hMy_GUI, "", "Set x/y parameters as required")
        EndIf
    EndIf
    
    ; Hide My_GUI when External not active
    If BitAND(WinGetState($hExternal_Wnd), 8) <> 8 And $fToolBar_Vis = True Then
        GUISetState(@SW_HIDE, $hMy_GUI)
    ElseIf BitAND(WinGetState($hExternal_Wnd), 8) = 8 And $fToolBar_Vis = False Then
        GUISetState(@SW_SHOW, $hMy_GUI)
    EndIf
    
WEnd

I thought it worked pretty well. :)

If your GUI has buttons or other controls, you may well need to add the following additional code to make sure the external GUI gets the focus back once you have clicked on your GUI:

; Reactivate external when My_GUI is activated
    If WinActive($hMy_GUI) Then 
        WinActivate($hExternal_Wnd)
    EndIf

Please ask if anything is unclear.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hypertrophy,

Apologies, I copied the snippet from another script and thought I had updated all the variables.

The "unknown" variable is a flag to see if My_GUI is already visible. If you do not test for this, you can end up using GUISetState every time you loop - which leads to flickering. This is true for all controls you have to toggle in this manner and is a good tip.

The amended script is as follows:

; Create My_GUI and use TOPMOST
Global $hMy_GUI = GUICreate("My GUI", ###, ###, ###, ###, -1, $WS_EX_TOPMOST)

; Set visible flag (assuming it is visible to begin with!)
$fMy_GUI_Vis = True

While 1
    
    ; Other loop code

    ; Correct position of My_GUI if required
    If WinActive($hExternal_Wnd) Or WinActive($hMy_GUI) Then
        $aExternal_Pos = WinGetPos($hExternal_Wnd)
        If $aExternal_Pos[0] <> $iLast_X Or $aExternal_Pos[1] <> $iLast_Y Then
            $iLast_X = $aExternal_Pos[0]
            $iLast_Y = $aExternal_Pos[1]
            WinMove($hMy_GUI, "", "Set x/y parameters as required")  ; You obviously use your own params here based on the position of the external GUI
        EndIf
    EndIf
    
    ; Hide My_GUI when External not active
    If BitAND(WinGetState($hExternal_Wnd), 8) <> 8 And $fMy_GUI_Vis = True Then
        GUISetState(@SW_HIDE, $hMy_GUI)
        $fMy_GUI_Vis = False ; Reset flag
    ElseIf BitAND(WinGetState($hExternal_Wnd), 8) = 8 And $fMy_GUI_Vis = False Then
        GUISetState(@SW_SHOW, $hMy_GUI)
        $fMy_GUI_Vis = True ; Reset flag
    EndIf
    
WEnd

Hope you can get it working this time. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

; Create My_GUI and use TOPMOST
Global $hMy_GUI = GUICreate("My GUI", 300, 300, 20, 20, -1, $WS_EX_TOPMOST)

$pad = WinGetHandle("Untitled - Notepad","")
; Set visible flag (assuming it is visible to begin with!)
$fMy_GUI_Vis = True


While 1
    
    ; Other loop code

    ; Correct position of My_GUI if required
    If WinActive("Untitled - Notepad") Or WinActive($hMy_GUI) Then
        $aExternal_Pos = WinGetPos("Untitled - Notepad")
        If $aExternal_Pos[0] <> $iLast_X Or $aExternal_Pos[1] <> $iLast_Y Then
            $iLast_X = $aExternal_Pos[0]
            $iLast_Y = $aExternal_Pos[1]
            WinMove($hMy_GUI, "", 20, 20)
        EndIf
    EndIf
    
    ; Hide My_GUI when External not active
    If BitAND(WinGetState($pad), 8) <> 8 And $fMy_GUI_Vis = True Then
        GUISetState(@SW_HIDE, $hMy_GUI)
    ElseIf BitAND(WinGetState($pad), 8) = 8 And $fMy_GUI_Vis = False Then
        GUISetState(@SW_SHOW, $hMy_GUI)
    EndIf
    
WEnd

That's what everything looks like. Whenever I activate notepad after running your script I get an error on line 19 saying variable used without being declared? Pointing to $iLast_X.

Link to comment
Share on other sites

  • Moderators

Hypertrophy,

That is what you get when you extract code from another script and do not check it first - missing declarations. :) This code works for me:

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

Run("Notepad")
WinWaitActive("Untitled - Notepad")

; Create My_GUI and use TOPMOST
Global $hMy_GUI = GUICreate("My GUI", 300, 300, 20, 20, -1, $WS_EX_TOPMOST)
GUISetState(@SW_HIDE)

; Set visible flag (assuming it is visible to begin with!)
Global $fMy_GUI_Vis = False
; Declare last position variables
Global $iLast_X = 0
Global $iLast_Y = 0

While 1

    ; Other loop code
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit

    ; Correct position of My_GUI if required
    If WinActive("Untitled - Notepad") Or WinActive($hMy_GUI) Then
        $aExternal_Pos = WinGetPos("Untitled - Notepad")
        If $aExternal_Pos[0] <> $iLast_X Or $aExternal_Pos[1] <> $iLast_Y Then
            $iLast_X = $aExternal_Pos[0]
            $iLast_Y = $aExternal_Pos[1]
            WinMove($hMy_GUI, "", $aExternal_Pos[0] + 40, $aExternal_Pos[1] + 60)
        EndIf
    EndIf

    ; Hide My_GUI when External not active
    If BitAND(WinGetState("Untitled - Notepad"), 8) <> 8 And $fMy_GUI_Vis = True Then
        GUISetState(@SW_HIDE, $hMy_GUI)
        $fMy_GUI_Vis = False
    ElseIf BitAND(WinGetState("Untitled - Notepad"), 8) = 8 And $fMy_GUI_Vis = False Then
        GUISetState(@SW_SHOW, $hMy_GUI)
        $fMy_GUI_Vis = True
    EndIf

    ; Reactivate External when My_GUI is activated
    If WinActive($hMy_GUI) Then
        WinActivate("Untitled - Notepad")
    EndIf

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Where would I put the $WS_EX_TOPMOST attribute if my window creation looked like this?

GUICreate("", 24, 24, $aMainGUI_Pos[0] + $ipos[0] + 5, $aMainGUI_Pos[1] + $ipos[1] + 50, _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
Link to comment
Share on other sites

  • Moderators

Hypertrophy,

It is an extended style, so just BitOR it with the others:

BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED, $WS_EX_TOPMOST)

Nice to see that you are BitORing styles. Sometimes simple adding works, but not always - which can cause a lot of headscratching (I speak from bitter experience here!).

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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