Jump to content

ANYGUI.au3


quaizywabbit
 Share

Recommended Posts

I am unable to add treeview items to a created treeview. Is it a bug or am I doing something wrong? It creates the treeview box, but I am unable to create treeview items.

#include <anygui.au3>
$GUI = GuiCreate("MyGUI", 464, 420,(@DesktopWidth-464)/2, (@DesktopHeight-400)/2)
GUISetState()

$target = _GuiTarget ($GUI)
$Tree = _TargetaddTreeView(250, 5, 200, 240, -1, $WS_EX_CLIENTEDGE, $target)
$1 = GUICtrlCreateTreeViewItem("Head", $Tree)

GUISetState()

While 1
WEnd

EDIT 1: hmm.. It seems to work if I use "-1" instead of targetting the variable storing the treeview. The problem is I have a complex treeview that will need to place the things under the right headers, and -1 won't do that.

EDIT 2: OK, after looking at the functions code, I realized that in order to target the created treeview, I must use $Tree[0] rather then $Tree.

FIXED!

Thanks

-JKnight

Edited by Knight
Link to comment
Share on other sites

  • 1 month later...

Hi All!

I have been playing around with AnyGui and it is awesome.

There is only one thing I find missing. That is some way to

overlay (overlapping) controls. Letting you put a control

ontop of another control. The only way to do this is to change

the z-order of the controls. Just our luck that win32 api ties

the z-order of controls (the z axis) to the tab order of the

controls. So all we need to do is change the tab order of the

controls and we change the z-order also.

Here is the code:

I modified my copy of AnyGUIv2.6's _TargetaddChild function

to change the z-order (of the child just created) after the

GUICreate function is called. Like this

Func _TargetaddChild($text, $PosX, $PosY, $SizeX, $SizeY, $LocTargethWnd = 0);
    Const $HWND_TOP = 0
    If not ($LocTargethWnd = 0) Then $TargethWnd = $LocTargethWnd
    Local $a = GUICreate($text, $SizeX, $SizeY, $PosX, $PosY, $WS_CHILD, -1, $TargethWnd)
    If $a = 0 Then
        SetError(1)
        Return $a
    Else
        DLLCall ( "user32.dll", "long", "SetWindowPOS", "hwnd", $a, "hwnd", $HWND_TOP, "int", 0, "int", 0, "int", 0, "int", 0, "long", BitOR ( $SWP_NOMOVE, $SWP_NOSIZE ))
        Return $a
EndFunc  ;==>_TargetaddChild

Now, when ever I create a control, it shows up ontop :lmao:

HOWEVER! most software will refresh the window (and z-order)after a maximize, or minimize.

So, your code will need to be called after these actions so that the z-order can be re-modified.

I am working on creating the following functions to make the coding easier.

_GUICtrlSetOnTop()

_GUICtrlSendUp()

_GUICtrlSendDown()

I will post them once I am finished. ;)

Thanks

sfranzyshen

Link to comment
Share on other sites

Hi sfranzyshen,

this sounds great!

Can you show us your new functions with an example in excel?

Here is a liite script (thanks to ptrex : link --> http://www.autoitscript.com/forum/index.ph...7&hl=_guitarget ) to get on with it.

--> German Excel <-- please replace the title !!

#include <ANYGUI.au3>
#include <guiconstants.au3>
Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

$appWindow = WinGetHandle("classname=XLMAIN")

$handle = ControlGetHandle("classname=XLMAIN", "", "EXCEL22")
;MsgBox(0,"",$handle)

$Targetwindow = _GuiTarget($appWindow,"","",$handle)

$btn = _TargetaddButton ( "Test Button", 800, 25, 80, 30,"","",$Targetwindow);
GUICtrlSetOnEvent($btn[0], "Clicked") 
GUISetState(@SW_SHOW)

_EndTarget() 

;WinActivate("Microsoft Excel - Mappe1", "")

$handle = ControlGetHandle("classname=XLMAIN", "", "XLDESK1")
$Targetwindow = _GuiTarget($appWindow,"","",$handle)
GUISetState(@SW_SHOW)
_EndTarget() 

;WinSetState("Microsoft Excel - Mappe1", "", @SW_ENABLE)
;ControlFocus("Microsoft Excel - Mappe1", "", "XLDESK1")
MsgBox(0,"Help Window","Just to get the focus back",2)
;Send ("^G")
;Send ("F5")
;Send ("{ENTER}")



While WinExists($Targetwindow)
     Sleep(100)
      If Not WinExists($Targetwindow) Then
         Exit
      EndIf
WEnd

Func Clicked()
MsgBox(0,"TEST","OK")
EndFunc

Can you replace a control???

Greets

Dizzy

Link to comment
Share on other sites

Hi sfranzyshen,

this sounds great!

Can you show us your new functions with an example in excel?

Here is a liite script (thanks to ptrex : link --> http://www.autoitscript.com/forum/index.ph...7&hl=_guitarget ) to get on with it.

"404: The page/file you requested could not be found."

That link is broken :lmao:

--> German Excel <-- please replace the title !!

#include <ANYGUI.au3>
#include <guiconstants.au3>
Opt("WinTitleMatchMode", 4)
Opt("GUIOnEventMode", 1)

 .. blah blah ..
I do not have Excel installed, so I am not sure what you are doing here ...

If you make the change to you AnyGUI, it may just simply work!

(I'm not realy sure what you want or are trying to do here?)

But, if you modify your AnyGui in the way I showed, ANY control you

create, will be placed at the top most layer of the z-order. In other words,

the newley created control (any control created with the _Targetadd* functions

from AnyGui) will be placed ontop anything else in the targeted window (assuming

the control(s) you want to overlay are set with the style WS_TABSTOP.)

Can you replace a control???

You can already replace a control. Just Hide it, then create a new control in it's

place.

I use this where I can not just hide the control. For instance, a toolbar. I do not

want to replace the entire toolbar, Just one button of it. So, I fire up this little change

and I am able to OVERLAY my control(s) ontop of an existing control(s).

Thanks

sfranzyshen

Link to comment
Share on other sites

Hi All!

I have been playing around with AnyGui and it is awesome.

There is only one thing I find missing. That is some way to

overlay (overlapping) controls. Letting you put a control

ontop of another control. The only way to do this is to change

the z-order of the controls. Just our luck that win32 api ties

the z-order of controls (the z axis) to the tab order of the

controls. So all we need to do is change the tab order of the

controls and we change the z-order also.

Here is the code:

I modified my copy of AnyGUIv2.6's _TargetaddChild function

to change the z-order (of the child just created) after the

GUICreate function is called. Like this

Func _TargetaddChild($text, $PosX, $PosY, $SizeX, $SizeY, $LocTargethWnd = 0);
    Const $HWND_TOP = 0
    If not ($LocTargethWnd = 0) Then $TargethWnd = $LocTargethWnd
    Local $a = GUICreate($text, $SizeX, $SizeY, $PosX, $PosY, $WS_CHILD, -1, $TargethWnd)
    If $a = 0 Then
        SetError(1)
        Return $a
    Else
        DLLCall ( "user32.dll", "long", "SetWindowPOS", "hwnd", $a, "hwnd", $HWND_TOP, "int", 0, "int", 0, "int", 0, "int", 0, "long", BitOR ( $SWP_NOMOVE, $SWP_NOSIZE ))
        Return $a
EndFunc ;==>_TargetaddChild

Now, when ever I create a control, it shows up ontop :lmao:

HOWEVER! most software will refresh the window (and z-order)after a maximize, or minimize.

So, your code will need to be called after these actions so that the z-order can be re-modified.

I am working on creating the following functions to make the coding easier.

_GUICtrlSetOnTop()

_GUICtrlSendUp()

_GUICtrlSendDown()

I will post them once I am finished. ;)

Thanks

sfranzyshen

I'll be more than happy to add these z-order functions to 2.7 when you get them figured out....nice work! o:)

[u]Do more with pre-existing apps![/u]ANYGUIv2.8
Link to comment
Share on other sites

Hi Me Again!

Ok, I have created two examples below. The first examples shows how to "REPLACE" a control

completly (Hide it, then create a new one). The Second example shows how to "PUT ON TOP" a

control on top of an existing control. The second example also contains the "_GUICtrlSetOnTop( )"

function that can be added to AnyGUI.

Replace an existing control example:

#include <guiconstants.au3>
#include <anyguiv2.6.au3>; z-order modified

;from Winuser.h (maybe shuold be placed into an include file some where)
Const   $HWND_TOP = 0
Const   $HWND_BOTTOM = 1
Const   $SWP_NOMOVE = 0x0002
Const   $SWP_NOSIZE = 0x0001

Run ( "calc" )

WinWait ( "Calculator" )

$Pos = WinGetPos ( "Calculator" )

WinMove ( "Calculator", "", (@DesktopWidth-$Pos[2])/2, (@DesktopHeight-$Pos[3])/2 )

ControlHide ( "Calculator", '', "Static1" ); Hide the control we want to replace

_GuiTarget ( "Calculator", 1 ); target the window

$Quit = _TargetAddButton ( "Quit", 8, 37, 36, 29 ); add a button where the previous control was
$Quit = $Quit[0]

GUISetState ( @SW_SHOW ); reset GUI

While 1
    $msg = GUIGetMsg ( )
        If $msg = $Quit Then Exit
        If Not WinExists ( "Calculator" ) Then Exit
wEnd

Func OnAutoItExit()
 ProcessClose ( "calc.exe" )
EndFunc

On-TOP an existing control example:

#include <guiconstants.au3>
#include <anyguiv2.6.au3>; z-order modified

;from Winuser.h (These should be moved to a include)
Const   $HWND_TOP = 0
Const   $HWND_BOTTOM = 1
Const   $SWP_NOMOVE = 0x0002
Const   $SWP_NOSIZE = 0x0001

;other
Const   $GW_HWNDPREV = 3
Const   $GW_HWNDNEXT = 2
Const   $GW_HWNDLAST = 1
Const   $GW_HWNDFIRST = 0

Run ( "mspaint" ); run an app

WinWait ( "untitled - Paint" ); wait for app

$Pos = WinGetPos ( "untitled - Paint" ); get default potision of app's window

WinMove ( "untitled - Paint", '', (@DesktopWidth-$Pos[2])/2, (@DesktopHeight-$Pos[3])/2, 462, 425 ); move the app to the center on the desktop

_GuiTarget ( "untitled - Paint", 1 ); target the GUI of the app

$Quit = _TargetAddButton ( "Quit", 3, 180, 50, 25, BitOr($WS_CHILD, $WS_VISIBLE, $WS_TABSTOP) ); create new control on app

$GUI = $Quit[2]; save the handle of the AutoIt GUI (child) for later updating
$Quit = $Quit[0]; save the controlid of the newley created button

GUICtrlSetTip ( -1, "Quit Paint Now!" ); set the tool tip for the newley created button

_GUICtrlSetOnTop( $GUI ); we need to call this after creating the button in applications that have controls with no
            ; current tab order set, in other applications that have tab orders, we do not need to call
            ; this function unless the screen gets redrawn and we need to update (redraw) our control

GUISetState ( @SW_SHOW ); refresh GUI

While 1; loop and wait for button press
    $msg = GUIGetMsg ( )
        If $msg = $Quit Then Exit
        If Not WinExists ( "untitled - Paint" ) Then Exit
wEnd

Func OnAutoItExit()
 ProcessClose ( "mspaint.exe" )
EndFunc


Func _GUICtrlSetOnTop( $HWND )

    DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $HWND, "hwnd", $HWND_TOP, "int", 0, "int", 0, "int", 0, "int", 0, "long", BitOR($SWP_NOMOVE, $SWP_NOSIZE ))
    GUISetState ( @SW_SHOW )

EndFunc

quaizywabbit: Feb 6 2006, 04:33 PM - I'll be more than happy to add these z-order functions to 2.7 when you get them figured out....nice work!

Thanks! I will be posting everything I figure out here ... you (or everyone) are welcome to do with it what ever you would like :lmao:

Hope this helps ya!

I am next looking at menus. Anyone got some good links to WIN32 API menu programming?

I would like to hide, add, modify application menus. Anyone else? It's got to be possible.

quaizywabbit's _WinMenuGetHandle() function looks like a good start!

I would also like to interact with parts of controls (custome or API) for instance, the ability to click

on just part of a toolbar, or change an edit control within parent control??

Thanks

sfranzyshen

Link to comment
Share on other sites

Replace an existing control example:

CLEARIFY: In these example, you do not need to change anything in you AnyGUI.au3 file.

The #include statement may have been missleading ... no change is need in either case ...

The change that was made to AnyGUI.au3 changed the way the targetaddchild was called.

Simply the same call made in the _GUICtrlSetOnTop() function. So, you can do the same

thing simply by using an unchanged AnyGUI.au3 include file, call a targetadd function, and

then call the _GUICtrlSetOnTop() function (as shown above.)

Thanks

sfranzyshen

Link to comment
Share on other sites

@sfranzyshen

Nice addition !! I vote for incorporating this in AnyGui.

The coordinates in your first example where not correct (at least when I ran it).

This is better.

$Quit = _TargetAddButton ( "Quit", 185, 62, 26, 27 );

Keep up the good work !! :lmao:

Link to comment
Share on other sites

Button Text & Background colors!

Another problem I have is when I add a control to an app's window, the control dosn't match the UI of the rest of the application. Perfect example of this is the calculator example I posted that added a button to the UI of the calc app, but the button's text color didn't match the rest of the app's UI. Color changes to buttons within AutoIt is in my opion "Broken". However, there is light at the end of the tunnel. The GUIRegisterMsg function has been quietly added to the AutoIt beta version. What this NEW function does is allow us to hook window/control messages. Allowing us to catch the WM_DRAWITEM message and proccess it ourselves. An excelent example is included in the help examples called GUIRegisterMsg.au3. I have stripped this file into two files. The first file is an #include file that contains just the functions and defines. The second file contains the MY_WM_DRAWITEM functions that I included into the calulator example here.

#include <guiconstants.au3>
#include <anyguiv2.6.au3>
#include <_GUIRegisterMsg.au3>

Const   $HWND_TOP = 0
Const   $HWND_BOTTOM = 1
Const   $SWP_NOMOVE = 0x0002
Const   $SWP_NOSIZE = 0x0001

Run ( "calc" )

WinWait ( "Calculator" )

$Pos = WinGetPos ( "Calculator" )

WinMove ( "Calculator", "", (@DesktopWidth-$Pos[2])/2, (@DesktopHeight-$Pos[3])/2 )

ControlHide ( "Calculator", '', "Static1" ); Hide the control we want to replace

_GuiTarget ( "Calculator", 1 ); target the window

$Quit = _TargetAddButton ( "Quit", 8, 37, 36, 29 ); add a button where the previous control was
$Quit = $Quit[0]
GUICtrlSetStyle($Quit, BitOr($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)); Set the ownerdrawn flag

GUIRegisterMsg($WM_DRAWITEM, "MY_WM_DRAWITEM")

GUISetState ( @SW_SHOW ); reset GUI

While 1
    $msg = GUIGetMsg ( )
        If $msg = $Quit Then Exit
        If Not WinExists ( "Calculator" ) Then Exit
wEnd

Func OnAutoItExit()
 ProcessClose ( "calc.exe" )
EndFunc

; Draw the button
Func MY_WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $stDrawItem = DllStructCreate("uint;uint;uint;uint;uint;uint;uint;int[4];dword", $lParam)
    
    $nCtlType = DllStructGetData($stDrawItem, 1)
    If $nCtlType = $ODT_BUTTON Then
        $nCtrlID    = DllStructGetData($stDrawItem, 2)
        $nItemState = DllStructGetData($stDrawItem, 5)
        $hCtrl      = DllStructGetData($stDrawItem, 6)
        $hDC        = DllStructGetData($stDrawItem, 7)
        $nLeft      = DllStructGetData($stDrawItem, 8, 1)
        $nTop       = DllStructGetData($stDrawItem, 8, 2)
        $nRight     = DllStructGetData($stDrawItem, 8, 3)
        $nBottom    = DllStructGetData($stDrawItem, 8, 4)
        $sText      = "Quit"
        $nTextColor = 0x0000ff
        $nBackColor = 0xced3d6
    ;0xD6D3CE
        DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor)
        $stDrawItem = 0
        Return 1
    EndIf

    $stDrawItem = 0
    Return $GUI_RUNDEFMSG; Proceed the default Autoit3 internal message commands
EndFunc

Place the attached file "_GUIRegisterMsg.au3" into your include folder. then run the above code :o

BTW:

I have been trying to get my _GUICtrlSetOnBottom() function working ... but it wont. So I only offer the _GUICtrlSetOnTop() function as an addition to AnyGUI. You can still accomplish all kinds of z-order changes with this one function. It will work on GUI added controls or existing controls. If you want a control to move down the z-order, just set another control ontop of it.

Thanks

sfranzyshen

_GUIRegisterMsg.au3

Link to comment
Share on other sites

  • 4 months later...

hm... i tried to use this code:

#include <ANYGUIv2.6.au3>
_GUItarget("Untitled - notepad")
_Targetaddbutton("text", 50, 50, 50, 50)

But it says "Error reading file GUIConstants.au3"

Link to comment
Share on other sites

  • 1 month later...

How can I code button click events and other messages after I have dropped a control onto an external app?

Here is my code:

#include <ANYGUI.au3>

#include <guiconstants.au3>

$Targetwindow = _GuiTarget ("Form2", 1); mode 1 set so all '_Targetadd(s) go to this window

$btn1 = _TargetaddButton ( "Button1", 30, 100, 100, 50);

GUISetState(@SW_SHOW);

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $btn1

msgBox(4096, "", "Preparing")

;Button1_Click()

EndSelect

Sleep(50)

WEnd

;Func Button1_Click()

;MsgBox(4096, "", "Button1 Clicked")

;EndFunc

I am never getting into Case $msg = $btn1

Link to comment
Share on other sites

  • 6 months later...

What am I doing wrong?

#include"./Include/OClassANYGUI.au3"
#include <guiconstants.au3>
_GuiTarget("Untitled - Notepad")
_TargetaddCheckbox("Test", 50, 50, 150, 30)oÝ÷ Ûú®¢×ºÚ"µÍÚ[ÛYH ÙÝZXÛÛÝ[Ë]LÉÝÂÚ[ÛYH  ÐSQÕR]]LÉÝÂ[   ][ÝÛÝY^I][ÝÊBÛY
L
BÚ[Ù]Ý]J ][ÝÕ[]YHÝY   ][ÝË  ][ÝÉ][ÝËÕ×ÓPVSRVJBÌÍÝÙ]HÑÝZUÙ]
    ][ÝÕ[]YHÝY   ][ÝÊBÌÍÝÙ]ÝHÑÝZUÙ]
    ÌÍÝÙ]K  ][ÝÉ][ÝËMJBÐÛÛÛ[ÝJ ÌÍÝÙ]   ][ÝÉ][ÝËMK
L
NÜÚ^HY]HÛÛÛÛÈ]][È]ÂÌÍÛ^XÚXÚØÞHHÕÙ]YÚXÚØÞ
    ][ÝÕÝ    ][ÝË
L
LMLÌLKLK   ÌÍÝÙ]Ý
NÂÉÌÍÛ^XÚXÚØÞVÌHÈÛÛÛY ÌÍÛ^XÚXÚØÞVÌWHÈÛÛÛÛ    ÌÍÛ^XÚXÚØÞVÌHÈÚ[Ú[ÝÂÕRTÙ]Ý]JÕ×ÔÒÕÊBÚ[HÚ[^ÝÊ   ÌÍÝÙ]
B   ÌÍÛÙÈHÕRQÙ]ÙÊJBÙ[XÝØÙH ÌÍÛÙÖÌHH  ÌÍÛ^XÚXÚØÞVÌBY]S
ÕRPÝXY
    ÌÍÛ^XÚXÚØÞVÌJK  ÌÍÑÕRWÐÒPÒÑQ
H[ÛÛÛÙ]^
    ÌÍÝÙ]   ][ÝÉ][ÝË    ÌÍÝÙ]Ý ][ÝÐÚXÚÙY  ][ÝÊB[YY]S
ÕRPÝXY
    ÌÍÛ^XÚXÚØÞVÌJK  ÌÍÑÕRWÕSÒPÒÑQ
H[ÛÛÛÙ]^
    ÌÍÝÙ]   ][ÝÉ][ÝË    ÌÍÝÙ]Ý ][ÝÕ[ÚXÚÙY ][ÝÊB[YØÙH  ÌÍÛÙÖÌHH  ÌÍÑÕRWÑUSÐÓÔÑB^]ØÙHÝÚ[^ÝÊ    ÌÍÝÙ]
B^][Ù[XÝÑ[

I myself haven't used this in quite awhile, so i had to re-read it again.

Hope this helps.....

Edited by quaizywabbit
[u]Do more with pre-existing apps![/u]ANYGUIv2.8
Link to comment
Share on other sites

quaizywabbit, thank you! This makes me feel like I actually own my computer! Seriously great idea! Lots of explanation points, but all of them were used purposefully. I will study what you wrote. Thanks again

Edit: Spelling

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

ANYGUIv2.7 released today.....

added _TargetAddDraglist() to the lineup and uncommented previous beta-only functions.

edited above Notepad example to demonstrate

#include <ANYGUIv2.7.au3>
Run("notepad.exe")
Sleep(1000)
WinSetState("Untitled - Notepad", "", @SW_MAXIMIZE)
$targetctl = _GuiTarget ("Untitled - Notepad", 1, "", 15)
$btnhide = _TargetAddButton("Hide", 300,400, 100, 100,-1,-1, $targetctl)
GUISetState(@SW_SHOW)
$btnshow = _TargetAddButton("Show", 400,400, 100, 100,-1,-1, $targetctl)
GUISetState(@SW_SHOW)
$mydraglist = _TargetAddDraglist ("", 50, 60, 250, 100, $WS_VSCROLL, -1, $targetctl);
GUICtrlSetData($mydraglist[0], "you|me|them|us|cool|shit|maynerd|damn|fuck|wow|bitchin|yada|nada|oh yeah")
;$mycheckbox1[0] is controlid: $mycheckbox1[1] is control hwnd: $mycheckbox1[2] is child window
GUISetState(@SW_SHOW)
While 1
 $msg = GUIGetMsg()
 Select
  Case $msg = $btnhide[0]
 GUISetState(@SW_HIDE, $mydraglist[2])
     Case $msg = $btnshow[0]
 GUISetState(@SW_SHOW, $mydraglist[2])
  Case $msg = $GUI_EVENT_CLOSE
   Exit
  Case Not WinExists($targetctl)
   Exit
 EndSelect
WEnd

see 1st post to download newest version, or click on ANYGUIv2.7 in my signature

Edited by quaizywabbit
[u]Do more with pre-existing apps![/u]ANYGUIv2.8
Link to comment
Share on other sites

Yes, I believe you can. Since control placement is based on the client area, I think you need to use Negative values in the Y(vertical) axis.

Yes but in this case the button is under the title bar.

Is there a way to put it on the top ?

Thanks

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