Sign in to follow this  
Followers 0
vsny

Store GUI handle in Dictionary

7 posts in this topic

I am trying to add a window handle into a scripting dictionary. I have all my controls stored but I cannot store the window handle. Is there a way to store the handle in some way.

$ctrls = ObjCreate('Scripting.Dictionary')

Func _createWnd()
        Local $wnd = GUICreate("My GUI edit")
    $ctrls.add("wnd", $wnd) ; also have tried Ptr($wnd)
EndFunc

A typical error I get with or without the Ptr() is:

C:\testControls.au3 (151) : ==> The requested action with this object has failed.:

$ctrls.add("wnd", ptr($wnd))

$ctrls.add("wnd", ptr($wnd))^ ERROR

I assume there is a way to do this since it works with controls and almost everything else. Can't I store the pointer to the window? or will I lose the window once it goes out of scope.

In case anyone asks - like any good programming style I'm trying to eliminate global variables and I have to pass all the public window controls between included modules.

Share this post


Link to post
Share on other sites



Global $ctrls = ObjCreate('Scripting.Dictionary')

_createWnd()
MsgBox(0,"Handle",_GetWnd("wnd"))

Func _createWnd()
    Local $wnd = GUICreate("My GUI edit")
    _AddWnd("wnd",$wnd)

EndFunc

Func _AddWnd($sKey, $sItem)
    $ctrls.add($sKey, string($sItem))
EndFunc

Func _GetWnd($sKey)
    Return HWnd($ctrls.item($sKey))
EndFunc


GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

vsny,

Welcome to the AutoIt forum. :(

I get it to work if I convert the Hex window handle to either a decimal number or a string first:

$ctrls = ObjCreate('Scripting.Dictionary')

_createWnd()

Func _createWnd()

    Local $wnd = GUICreate("My GUI edit")
    ConsoleWrite($wnd & @CRLF)

    $ctrls.add("Wnd_1", Dec(StringTrimleft($wnd, 2)))
    ConsoleWrite("0x" & Hex($ctrls.item("Wnd_1"), 8) & @CRLF)

    $ctrls.add("Wnd_2", String($wnd))
    ConsoleWrite($ctrls.item("Wnd_2") & @CRLF)

EndFunc

Why, I have no idea - I just thought I would try it! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Same error we discovered when testing AutoItObject, it seems that no dev wants to fix it. #1410


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

ProgAndy,

Do not lose hope - the bug is still open and we know that there is a bit of a pause in development at the moment. And even if it does not get fixed, we know the work-around.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Wow, you guys are fast! I went to the backyard for a few minutes and the answer was waiting for me!

I tried Yoriz's String() solution and it seems to work. Thanks!

Are there any drawbacks or dangers to doing this? Is this an unsupported hack that will break in future versions?

Do the dev's have any feedback on this? Maybe there was a reason they didn't implement this?

Share this post


Link to post
Share on other sites

It a better idea to just use Number($wnd) instead of any string conversions. A window handle is just a 32/64-bit number anyway, it's just that AutoIt internally designates it a 'handle' and AutoIt's implementation of objects does not allow it to work with 'handle'. This is also the solution that the AutoItObject examples use.

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  
Followers 0