Jump to content
Sign in to follow this  
crashdemons

Dynamic GUI control

Recommended Posts

crashdemons

I had a little trouble when creating interactive PM windows for a client program.

I had to keep track of every window and be able to find the other person's username and all of the control ID's needed on the window.

Later I found a way to do this much easier than what I had done.

The attached script supplies functions to easy gaining information about dynamic windows, using the GUI value or a special identifier string.

DynGUI.au3

DynGUI.au3

Here is an example script .

In this scenario you are a client user named 'Bob' who is about to recieve PM's from two friends (Meg and Dave).

You will be able to send PM's back in either window, or close the window

#include <DynGUI.au3>
Opt('GUIOnEventMode',1)
$UserName='Bob'
Func _PM_GUI_Create($to)
    $offset=Random(0,600,1)
    
    $GUI=GUICreate("PM "&$to,400,200,$offset,$offset)
    $Text=GUICtrlCreateEdit('',0,0,400,180)
    $Txt2=GUICtrlCreateInput('',0,180,300,20)
    $Send=GUICtrlCreateButton('Send',300,180,100,20)
    $GUI=WinGetHandle($GUI) ; since the OnEvent Function cant get a GUI ID
    _DynGUI_Set($GUI,$to)
    _DynGUI_CtrlAdd($Text,$GUI)
    _DynGUI_CtrlAdd($Txt2,$GUI)
    _DynGUI_CtrlAdd($Send,$GUI)
    
    GUISetOnEvent(-3,'_PM_Close')
    GUICtrlSetOnEvent($Send,'_PM_Send')
    GUISetState()
    Return $GUI
EndFunc
Func _PM_Check($to)
    $pmv=_DynGUI_GUI($to)
    If $pmv=='' Then $pmv=_PM_GUI_Create($to)
    Return $pmv
EndFunc
Func _PM_Incoming($from,$sText)
    $GUI=_PM_Check($from)
    $Text=_DynGUI_Ctrl(1,$GUI)
    GUICtrlSetData($Text,GUICtrlRead($Text)&$from&': '&$sText&@CRLF)
EndFunc
Func _PM_Outgoing($to,$sText)
    $GUI=_PM_Check($to)
    $Text=_DynGUI_Ctrl(1,$GUI)
    GUICtrlSetData($Text,GUICtrlRead($Text)&$UserName&': '&$sText&@CRLF)
    ;;TCPSend somehow to $to here
EndFunc
Func _PM_Close()
    $GUI=@GUI_WINHANDLE
    GUIDelete($GUI)
    _DynGUI_Closed($GUI)
EndFunc
Func _PM_Send()
    $GUI=@GUI_WINHANDLE
    $Txt2=_DynGUI_Ctrl(2,$GUI)
    $Send=_DynGUI_Ctrl(3,$GUI)
    $to=_DynGUI_Identifier($GUI)
    GUICtrlSetState($Txt2,128)
    GUICtrlSetState($Send,128)
    _PM_Outgoing($to,GUICtrlRead($Txt2))
    GUICtrlSetData($Txt2,'')
    GUICtrlSetState($Send,64)
    GUICtrlSetState($Txt2,64)
EndFunc

_PM_Incoming('meg','hai')
_PM_Incoming('dave','hello')


While 1
    Sleep(300)
WEnd

Notes: Tested with Au3.2.10.0

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

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
Sign in to follow this  

×