Jump to content

button docked to application window


Recommended Posts

Does anyone have a snippit of code showing a button docked to a application window? I've seen the examples of when you move the application, the docked GUI doesn't move until you release the mouse button after you move the app. I need something that can move the button in real time while the app window moves. I've got a application that many of my users move, and I want to add a small script to it so when they click the button, it runs a macro for them.

I'd be real grateful if someone could help me out.

Link to comment
Share on other sites

Maybe...

#include<ANYGUI.au3>
#include <GuiConstants.au3>

Run("notepad.exe")

WinWaitActive("")

$hWnd = _GuiTarget ("Untitled - Notepad")
$child = _TargetaddChild ("", 0, 0, 50000, 20, $hWnd)
$Button1 = GUICtrlCreateButton("Spell Check!", 0, 0, 100, 20)
$Button2 = GUICtrlCreateButton("Replace Word", 400, 0, 100, 20)
$ListBox1 = GUICtrlCreateList("", 100, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL)
$ListBox2 = GUICtrlCreateList("", 250, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL)
$edit = ControlGetHandle($hWnd, "", 15)
$Combo = GUICtrlCreateCombo("", 500, 0, 80, 20)
GUICtrlSetState($Button2, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While WinExists($hWnd)
    $msg = GUIGetMsg()
    Switch $msg
;~   Case $GUI_EVENT_CLOSE, $Button3
;~    _Exit()
        Case $Button1
            If ControlGetText($hWnd, "", 15) <> "" Then
                _test()
            Else
                MsgBox(0, "Error", "No text to check")
            EndIf
        Case $Button2
            _test()
        Case $ListBox1
           _test()
        Case $ListBox2
            GUICtrlSetState($Button2, $GUI_ENABLE)
        Case $Combo
           _test()
           
    EndSwitch
    $size = WinGetClientSize($hWnd)
    If WinExists($hWnd) Then
        ControlMove($hWnd, "", 15, 0, 20, $size[0], $size[1] - 20)
        ControlMove($hWnd, "", "button2", $size[0], 25, 20, 20)
    EndIf
    Sleep(10)
WEnd

Func _test()
    MsgBox(0, "ControlGetText", ControlGetText($hWnd, "", 15))
    MsgBox(0, "GUICtrlRead", GUICtrlRead($edit))
EndFunc   ;==>_test

Func _Exit()    
    Exit
EndFunc   ;==>_Exit

8)

NEWHeader1.png

Link to comment
Share on other sites

humm, another way around this maybe-

Global $MouseOffset
Global $FirstMove=True
Global $GUI=GUICreate("Main GUI",200,200,50,50)

GUIRegisterMsg(0x0216,"MoveGUI")

GUISetState()

While 1
    Sleep(100)
WEnd

func MoveGUI()
    if $FirstMove then
        $MouseOffset=GUIGetCursorInfo()
        $FirstMove=False
    EndIf
    WinMove($GUI,"",MouseGetPos(0)-$MouseOffset[0],MouseGetPos(1)+$MouseOffset[1])
EndFunc

Although you'll have think of some event you can use to re-flag the $FirstMove or else you'll start getting small offset errors after the first move.

Edited by evilertoaster
Link to comment
Share on other sites

Maybe...

#include<ANYGUI.au3>
#include <GuiConstants.au3>

Run("notepad.exe")

WinWaitActive("")

$hWnd = _GuiTarget ("Untitled - Notepad")
$child = _TargetaddChild ("", 0, 0, 50000, 20, $hWnd)
$Button1 = GUICtrlCreateButton("Spell Check!", 0, 0, 100, 20)
$Button2 = GUICtrlCreateButton("Replace Word", 400, 0, 100, 20)
$ListBox1 = GUICtrlCreateList("", 100, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL)
$ListBox2 = GUICtrlCreateList("", 250, 0, 150, 20, $LBS_NOTIFY + $WS_VSCROLL)
$edit = ControlGetHandle($hWnd, "", 15)
$Combo = GUICtrlCreateCombo("", 500, 0, 80, 20)
GUICtrlSetState($Button2, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While WinExists($hWnd)
    $msg = GUIGetMsg()
    Switch $msg
;~   Case $GUI_EVENT_CLOSE, $Button3
;~    _Exit()
        Case $Button1
            If ControlGetText($hWnd, "", 15) <> "" Then
                _test()
            Else
                MsgBox(0, "Error", "No text to check")
            EndIf
        Case $Button2
            _test()
        Case $ListBox1
           _test()
        Case $ListBox2
            GUICtrlSetState($Button2, $GUI_ENABLE)
        Case $Combo
           _test()
           
    EndSwitch
    $size = WinGetClientSize($hWnd)
    If WinExists($hWnd) Then
        ControlMove($hWnd, "", 15, 0, 20, $size[0], $size[1] - 20)
        ControlMove($hWnd, "", "button2", $size[0], 25, 20, 20)
    EndIf
    Sleep(10)
WEnd

Func _test()
    MsgBox(0, "ControlGetText", ControlGetText($hWnd, "", 15))
    MsgBox(0, "GUICtrlRead", GUICtrlRead($edit))
EndFunc   ;==>_test

Func _Exit()    
    Exit
EndFunc   ;==>_Exit

8)

Looks promising, but it won't run. I wanted to see it in action first. :)

I'm going to have to work on AnyGUI to see how to fix it.

Link to comment
Share on other sites

I'm running into other errors on anygui.au3

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Owner.YOUR-9258729F9F\My Documents\AU3 scripts\music grabber\music.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams   
+> Starting AutoIt3Wrapper v.1.7.3
>Running AU3Check (1.54.10.0)  params:  from:C:\Program Files\AutoIt3
C:\PROGRA~1\AutoIt3\Include\ANYGUI.au3(1071,49) : ERROR: _GUICtrlListGetText(): undefined function.
                $sztext = _GUICtrlListGetText($nID, $dragIdx)
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\PROGRA~1\AutoIt3\Include\ANYGUI.au3(1072,42) : ERROR: _GUICtrlListDeleteItem(): undefined function.
                _GUICtrlListDeleteItem($nID, $dragIdx)
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\PROGRA~1\AutoIt3\Include\ANYGUI.au3(1073,52) : ERROR: _GUICtrlListInsertItem(): undefined function.
                _GUICtrlListInsertItem($nID, $sztext, $dragIdto)
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\PROGRA~1\AutoIt3\Include\ANYGUI.au3(1074,44) : ERROR: _GUICtrlListSelectIndex(): undefined function.
                _GUICtrlListSelectIndex($nID, $dragIdto)
Link to comment
Share on other sites

Looks like it uses the old UDF standards. You're gonna have to do some function renaming in AnyGUI, or use an old version of AutoIt. :\

Of course, AnyGUI is not required if you want to do the stuff manually.

#include <WindowsConstants.au3>
Run('calc.exe')

WinWait('Calculator')
$hWnd = WinGetHandle('[LAST]')
$myGUI = GUICreate('', 27, 26, 230, 62, $WS_CHILD, 0, $hWnd)
$butt = GUICtrlCreateButton('HI!', 0, 0, 27, 26)
GUISetState()

While WinExists($hWnd)
    $gm = GUIGetMsg()
    If $gm = $butt Then
        MsgBox(0, 'Button', 'You clicked the button!')
    EndIf
WEnd

Is that what you were looking for?

*Edit: Ooops, I started my reply before you made your last post Volly.

Edited by Saunders
Link to comment
Share on other sites

Looks like it uses the old UDF standards. You're gonna have to do some function renaming in AnyGUI, or use an old version of AutoIt. :\

Of course, AnyGUI is not required if you want to do the stuff manually.

#include <WindowsConstants.au3>
Run('calc.exe')

WinWait('Calculator')
$hWnd = WinGetHandle('[LAST]')
$myGUI = GUICreate('', 27, 26, 230, 62, $WS_CHILD, 0, $hWnd)
$butt = GUICtrlCreateButton('HI!', 0, 0, 27, 26)
GUISetState()

While WinExists($hWnd)
    $gm = GUIGetMsg()
    If $gm = $butt Then
        MsgBox(0, 'Button', 'You clicked the button!')
    EndIf
WEnd

Is that what you were looking for?

*Edit: Ooops, I started my reply before you made your last post Volly.

Actually, that is exactly what I wanted. Thanks! Edited by Volly
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...