Jump to content
topten

Can't understand the error

Recommended Posts

topten

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
VIP

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
topten

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
topten

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
LarsJ

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
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
topten

Great,  Water, it works! Thanx!

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
topten

@ 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
water

Ops, you are correct. My fault :>


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
topten

:)

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

×