Merchants

Attaching a GUI to a Existing 3rd Party Window

15 posts in this topic

#1 ·  Posted (edited)

how to stick a GUI to notepad so it comes along when i drag notepad
And the other way around (When you drag the GUI the notepad comes along)

Opt("MouseCoordMode", 2)
#include <WindowsConstants.au3>

$Win = WinGetHandle("notepad.exe")
WinActivate($Win)


Global $iGUI = GUICreate("test", 175, 160, 200, 200)
GUICtrlCreateLabel("Some text", 5, 5)
GUISetStyle($WS_CAPTION, $WS_BORDER)
GUISetState(@SW_SHOW, $iGUI)

GUIRegisterMsg($WM_MOVE, "_Position_Child")

While 1
    Sleep(1)
WEnd

Func _Position_Child()
    Local $aGUI_Main_Pos = WinGetPos($Win)
    WinMove($iGUI, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1])
EndFunc

 

 

Edited by Merchants

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

My take on your solution.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/tc 4 /reel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $aPos

_Resize()

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(25)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    _Resize()
    WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
WEnd

Func _Resize()
    If WinExists("[CLASS:Notepad]") Then
        Global $aPos = WinGetPos("[CLASS:Notepad]")
    Else
        Exit
    EndIf
EndFunc   ;==>_Resize

 

Edited by zone97
Code edit. Match height as well as dock.

 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

30 minutes ago, zone97 said:

My take on your solution.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/tc 4 /reel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $aPos

_Resize()

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(25)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    _Resize()
    WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
WEnd

Func _Resize()
    If WinExists("[CLASS:Notepad]") Then
        Global $aPos = WinGetPos("[CLASS:Notepad]")
    Else
        Exit
    EndIf
EndFunc   ;==>_Resize

 

btw check post 1 again

is it not possible with GUIRegisterMsg?

Share this post


Link to post
Share on other sites

#4 ·  Posted

1 hour ago, Merchants said:

btw check post 1 again

is it not possible with GUIRegisterMsg?

Don't know anything about GUIREgisterMsg.. But did read your original post again, and noticed you wanted one to move the other and vice versa. So I made a new script.. Try this out.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/tc 4 /reel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $aPos = WinGetPos("[CLASS:Notepad]")

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(50)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Global $aPos = WinGetPos("[CLASS:Notepad]")
    Global $bPos = WinGetPos("NotePad Leech!")
    If $bPos[0] <> $aPos[0] + $aPos[2] Or $aPos[1] <> $bPos[1] And WinActive("[CLASS:Notepad]") Then
        WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
    EndIf
    If $bPos[0] <> $bPos[0] - $aPos[2] Or $bPos[1] <> $aPos[1] And WinActive("NotePad Leech!") Then
        WinMove("[CLASS:Notepad]", "", $bPos[0] - 5 - $aPos[2], $bPos[1] - 5, 300, $bPos[3] + 10)
    EndIf
WEnd

 


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Oké not bad it worked. I edit it a little better so it doesn't get hanged up when you drag de GUI

nieuw problem when i drag the notepad it hide the gui and the other way around
any way to fix that?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $aPos = WinGetPos("[CLASS:Notepad]")
$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_TIMER, "_Interrupt")
DllCall("User32.dll", "int", "SetTimer", "hwnd", $Form1, "int", 0, "int", 0, "int", 0)

While 1
    Sleep(1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Interrupt()
    Global $bPos = WinGetPos("NotePad Leech!")
    Global $aPos = WinGetPos("[CLASS:Notepad]")
    If $bPos[0] <> $aPos[0] + $aPos[2] Or $aPos[1] <> $bPos[1] And WinActive("[CLASS:Notepad]") Then
        WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
    EndIf
    If $bPos[0] <> $bPos[0] - $aPos[2] Or $bPos[1] <> $aPos[1] And WinActive("NotePad Leech!") Then
        WinMove("[CLASS:Notepad]", "", $bPos[0] - 5 - $aPos[2], $bPos[1] - 5, 300, $bPos[3] + 10)
    EndIf
EndFunc

 

Share this post


Link to post
Share on other sites

#6 ·  Posted

bump

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

What do you mean it hides the GUI? I just tested it and it doesn't hide for me.


UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites
On 11-1-2017 at 6:19 PM, anthonyjr2 said:

What do you mean it hides the GUI? I just tested it and it doesn't hide for me.

Here u go:

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Oh, I believe that is built into Windows. The most recently activated windows will appear on top of less recently accessed windows. You should be able to fix that by setting WinSetOnTop on both windows.

Opt("WinTitleMatchMode","2")
WinSetOnTop($Form1,"",1)
WinSetOnTop("Notepad","",1)

 

Edited by anthonyjr2
1 person likes this

UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=

Share this post


Link to post
Share on other sites

#11 ·  Posted

I made some changes and updates based upon everyone's suggestions..

  • Removed the resize of notepad when selecting the leech
  • Added always on top suggestion from @anthonyjr2
  • cleaned up the code, and had it launch notepad for us.
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/tc 4 /reel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

Opt("WinTitleMatchMode", "2")

If Not ProcessExists("Notepad.exe") Then Run("Notepad.exe")
Sleep(500)

Global $aPos = WinGetPos("[CLASS:Notepad]")

$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_TIMER, "_Interrupt")
DllCall("User32.dll", "int", "SetTimer", "hwnd", $Form1, "int", 0, "int", 0, "int", 0)

WinSetOnTop($Form1, "", 1)
WinSetOnTop("[CLASS:Notepad]", "", 1)

While 1
    Sleep(1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Interrupt()
    Global $bPos = WinGetPos("NotePad Leech!")
    Global $aPos = WinGetPos("[CLASS:Notepad]")
    If $bPos[0] <> $aPos[0] + $aPos[2] Or $aPos[1] <> $bPos[1] And WinActive("[CLASS:Notepad]") Then
        WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
    EndIf
    If $bPos[0] <> $bPos[0] - $aPos[2] Or $bPos[1] <> $aPos[1] And WinActive("NotePad Leech!") Then
        WinMove("[CLASS:Notepad]", "", $bPos[0] - 5 - $aPos[2], $bPos[1] - 5)
    EndIf
EndFunc   ;==>_Interrupt

 


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

 

59 minutes ago, anthonyjr2 said:

Oh, I believe that is built into Windows. The most recently activated windows will appear on top of less recently accessed windows. You should be able to fix that by setting WinSetOnTop on both windows.

Opt("WinTitleMatchMode","2")
WinSetOnTop($Form1,"",1)
WinSetOnTop("Notepad","",1)

 

 

4 minutes ago, zone97 said:

I made some changes and updates based upon everyone's suggestions..

  • Removed the resize of notepad when selecting the leech
  • Added always on top suggestion from @anthonyjr2
  • cleaned up the code, and had it launch notepad for us.
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/tc 4 /reel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

Opt("WinTitleMatchMode", "2")

If Not ProcessExists("Notepad.exe") Then Run("Notepad.exe")
Sleep(500)

Global $aPos = WinGetPos("[CLASS:Notepad]")

$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_TIMER, "_Interrupt")
DllCall("User32.dll", "int", "SetTimer", "hwnd", $Form1, "int", 0, "int", 0, "int", 0)

WinSetOnTop($Form1, "", 1)
WinSetOnTop("[CLASS:Notepad]", "", 1)

While 1
    Sleep(1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Interrupt()
    Global $bPos = WinGetPos("NotePad Leech!")
    Global $aPos = WinGetPos("[CLASS:Notepad]")
    If $bPos[0] <> $aPos[0] + $aPos[2] Or $aPos[1] <> $bPos[1] And WinActive("[CLASS:Notepad]") Then
        WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
    EndIf
    If $bPos[0] <> $bPos[0] - $aPos[2] Or $bPos[1] <> $aPos[1] And WinActive("NotePad Leech!") Then
        WinMove("[CLASS:Notepad]", "", $bPos[0] - 5 - $aPos[2], $bPos[1] - 5)
    EndIf
EndFunc   ;==>_Interrupt

 

I realy don't like the setontop func
there is a correct way to do this ?

Share this post


Link to post
Share on other sites

#13 ·  Posted

Personally with some of my own code I wish there was a register that you could check to know if a windows is in front of or behind other windows.


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

44 minutes ago, zone97 said:

Personally with some of my own code I wish there was a register that you could check to know if a windows is in front of or behind other windows.

Func ActiveWindow()
    $hWnd1 = WinGetHandle("[CLASS:]")
    If IsHWnd($hWnd1) Then
        WinActivate($hWnd1)
    EndIf
EndFunc   ;==>ActiveWindow

Why not just use WinActivate. If the program exists then call it in front of everything.

Edited by aa2zz6

Share this post


Link to post
Share on other sites

#15 ·  Posted

I Fix it on my own:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $aPos = WinGetPos("[CLASS:Notepad]"), $test=0, $test2=0,$Text,$Text2, $count=0
$Form1 = GUICreate("NotePad Leech!", 300, $aPos[3] - 40, $aPos[0] + 5 + $aPos[2], $aPos[1] + 5)
$Text = GUICtrlCreateLabel("WinActive Notepad: " & $test, 5, 5)
$Text2 = GUICtrlCreateLabel("WinActive Notepad Leech!: " & $test2, 5, 25)
Opt("WinTitleMatchMode","2")
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_TIMER, "_Interrupt")
DllCall("User32.dll", "int", "SetTimer", "hwnd", $Form1, "int", 0, "int", 0, "int", 0)

While 1
    Sleep(1)
    $nMsg = GUIGetMsg()
    Switch $nMsg
            Exit
        Case $GUI_EVENT_CLOSE
    EndSwitch
WEnd

Func _Interrupt()
    Global $bPos = WinGetPos("NotePad Leech!")
    Global $aPos = WinGetPos("[CLASS:Notepad]")
    If $bPos[0] <> $aPos[0] + $aPos[2] Or $aPos[1] <> $bPos[1] And WinActive("[CLASS:Notepad]") Then
        WinMove("NotePad Leech!", "", $aPos[0] + 5 + $aPos[2], $aPos[1] + 5, 300, $aPos[3] - 10)
    EndIf
    If $bPos[0] <> $bPos[0] - $aPos[2] Or $bPos[1] <> $aPos[1] And WinActive("NotePad Leech!") Then
        WinMove("[CLASS:Notepad]", "", $bPos[0] - 5 - $aPos[2], $bPos[1] - 5, 300, $bPos[3] + 10)
    EndIf
    If WinActive("[CLASS:Notepad]") Then
        If $test=0 Then
            WinSetOnTop("NotePad Leech!", "", 1)
            WinSetOnTop("NotePad Leech!", "", 0)
            $test=1
        EndIf
    Else
        $test=0
    EndIf
    If WinActive("NotePad Leech!") Then
        If $test2=0 Then
            WinSetOnTop("[CLASS:Notepad]", "", 1)
            WinSetOnTop("[CLASS:Notepad]", "", 0)
            $test2=1
        EndIf
    Else
        $test2=0
    EndIf
    If $count = 10 Then
        $count=0
        GUICtrlSetData($Text, "WinActive Notepad: " & $test)
        GUICtrlSetData($Text2, "WinActive Notepad Leech!: " & $test2)
    Else
        $count+=1
    EndIf
EndFunc

Thx for everyone's suggestions

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