topten

Can't understand the error

12 posts in this topic

I am writing a function for dynamic creating guis. Here's a piece of code from the script

 

Global $guiscounter = 0
Global $DynGui[10000]
Global $DynPic[10000]
$guiscounter=$guiscounter+1
Global $DynGui[$guiscounter] = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, $WS_POPUP)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui[$guiscounter]), "hwnd", WinGetHandle($Child1_GUI))
GUISetBkColor($iBgColor, $DynGui[$guiscounter]) ;set GUI background color
Global $DynPic[$guiscounter] = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
GUISetState(@SW_SHOW)

I get an error

==> Subscript used on non-accessible variable.:
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui[$guiscounter]), "hwnd", WinGetHandle($Child1_GUI))
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui^ ERROR

Is the error happening because I am trying to WinGetHandle the dynamic gui?

Great thanx in advance

Share this post


Link to post
Share on other sites



I do not know, try it:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
Global $guiscounter = 0
Local $iWidth=800
Local $iHeight=600
Local $iBgColor=$COLOR_RED
Global $DynGui = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, -1,-1, $WS_POPUP)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui), "hwnd", WinGetHandle($DynGui))
GUISetBkColor($iBgColor, $DynGui) ;set GUI background color
Global $DynPic = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
GUISetState(@SW_SHOW)
Sleep(3000)

 


Regards,
 

Share this post


Link to post
Share on other sites

Trong, thank you very much

I know this code. This works ok. But when I am trying to make the variable dynamic, then it breaks though!

Share this post


Link to post
Share on other sites

Aha, but

It doesnt give error for this part, which is supposed to be

Global $DynGui[$guiscounter] = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, $WS_POPUP)

But gives error for this part

 
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui[$guiscounter]), "hwnd", WinGetHandle($Child1_GUI))

Looks like

 
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui[1]), "hwnd", WinGetHandle($Child1_GUI))

wont work

Share this post


Link to post
Share on other sites

I think this line is a ReDim of your array to just one row:

Global $DynGui[$guiscounter] = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, $WS_POPUP)

You can access this row through index zero.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Remove the Global

Global $guiscounter = 0
Global $DynGui[10000]
Global $DynPic[10000]
$guiscounter=$guiscounter+1
$DynGui[$guiscounter] = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, $WS_POPUP)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($DynGui[$guiscounter]), "hwnd", WinGetHandle($Child1_GUI))
GUISetBkColor($iBgColor, $DynGui[$guiscounter]) ;set GUI background color
$DynPic[$guiscounter] = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)
GUISetState(@SW_SHOW)

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Great,  Water, it works! Thanx!

Share this post


Link to post
Share on other sites

I do not know if this is intended:
GUICtrlCreatePic overwrites the handle for GUICreate because you didn't increment $guiscounter.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@ Water,  as You say "GUICtrlCreatePic overwrites the handle for GUICreate because you didn't increment $guiscounter."

$DynGui[$guiscounter] = GUICreate("GDI+ Example23 (" & @ScriptName & ")", $iWidth, $iHeight, $WS_POPUP)
$DynPic[$guiscounter] = GUICtrlCreatePic("", 0, 0, $iWidth, $iHeight)

How? I was thinking that  $DynGui[$guiscounter] will be for GUI and  $DynPic[$guiscounter] will be for PIC .

Share this post


Link to post
Share on other sites

Ops, you are correct. My fault :>


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

:)

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