Jump to content

Can't understand the error


topten
 Share

Recommended Posts

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

Link to comment
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,
 

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 .

Link to comment
Share on other sites

Ops, you are correct. My fault :>

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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