Jump to content

Attaching element to existing GUI


Recommended Posts

Dear AI forums,

I have an existing program that runs in a window of static size. What I want to do is overlay an extra button (preferably an image in the same style) on top of this window at specific coordinates within that window (so it will move with the window if dragged elsewhere) to expand on it's functionality.

How do I go about this? I have searched for quite a bit, but wasn't able to find anything.

Link to comment
Share on other sites

In the past I have used this. It is quite dirty, but depending what your requirements are it may work.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinDetectHiddenText", 1)
Opt("WinTitleMatchMode", 2)
Opt("GUIOnEventMode", 1)

$wrapper = GUICreate("", 1,1,1,1)
$gui = GUICreate("title", 100, 100, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST, $wrapper)
$OK_button = GUICtrlCreateButton("Button", 0, 0,218,28)
GUISetState()
$state = 1
$count = 0
$found_save = ""
GUICtrlSetOnEvent($OK_button, "button")
Run("notepad")

While 1
    If WinActive("Notepad") Then
            activate()
            $pos = WinGetPos("Notepad")
                WinMove($gui, "", $pos[0], $pos[1]+100, 220, 30)
        Else
            deactivate()
        EndIf
        Sleep(200)
WEnd

Func button()
MsgBox(0,"","Button Clicked")
EndFunc   ;==>print

Func activate()
    If $state = 0 Then
        WinSetState($gui, "", @SW_SHOW)
        WinActivate("Notepad")
        $state = 1
    EndIf
EndFunc   ;==>activate



Func deactivate()
    If $state = 1 Then
        If $count > 3 Then
            WinSetState($gui, "", @SW_HIDE)
            $state = 0
        EndIf
        $count = $count + 1
    Else
        $count = 0
    EndIf
EndFunc   ;==>deactivate
Link to comment
Share on other sites

 

In the past I have used this. It is quite dirty, but depending what your requirements are it may work.

<code>

 

Hey, thanks for the reply. I have also asked this elsewhere and they came up with a shorter resolution:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; NotepadAddOn
ShellExecute('notepad')
WinWaitActive("[CLASS:Notepad]", "")
$pos_A = WinGetPos("[CLASS:Notepad]", "")
$hGui = GUICreate('YOUR GUI', 65, 30, $pos_A[0], $pos_A[1] - 50, 0x80880008, 0x00000008)
$Btn = GUICtrlCreatePic("C:\Button.gif", 0, 0, 65, 30)

GUISetState(@SW_SHOW) ; will display an empty dialog box
AdlibRegister('_WinMove', 10)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
   Switch $msg
         Case $Btn
            Run ('something.exe')
    EndSwitch
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Func _WinMove()
        $p_A = WinGetPos("[CLASS:Notepad]", "")
        WinMove($hGui, "", $p_A[0], $p_A[1] + 150 + $p_A[3] - 200)
EndFunc   ;==>_WinMove
Link to comment
Share on other sites

can this

 

_WinAPI_SetParent($MyGui, WinWaitActive('yourwintitleorsomething'))
WinSetOnTop ( $MyGui, "" , 1 )
help in this case (instead of all win move all the time even if win dont change pos)? Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

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